#ifndef __BOOTCACHES_H__
#define __BOOTCACHES_H__
#include <CoreFoundation/CoreFoundation.h>
#include <TargetConditionals.h>
#if !TARGET_OS_EMBEDDED
#include <DiskArbitration/DiskArbitration.h>
#endif
#include <sys/stat.h>
#include <sys/time.h>
#include <IOKit/kext/kextmanager_types.h> // uuid_string_t
#define kTSCacheDir "/System/Library/Caches/com.apple.bootstamps/"
#define kTSCacheMask 0755 // Sec reviewed
#define kRPSDirMask 0755
#define kBootCachesPath "/usr/standalone/bootcaches.plist"
#define kBCPreBootKey CFSTR("PreBootPaths") // dict
#define kBCLabelKey CFSTR("DiskLabel") // ".disk_label"
#define kBCBootersKey CFSTR("BooterPaths") // dict
#define kBCEFIBooterKey CFSTR("EFIBooter") // "boot.efi"
#define kBCOFBooterKey CFSTR("OFBooter") // "BootX"
#define kBCPostBootKey CFSTR("PostBootPaths") // dict
#define kBCMKextKey CFSTR("MKext") // dict
#define kBCArchsKey CFSTR("Archs") // ar: ppc, i386
#define kBCExtensionsDirKey CFSTR("ExtensionsDir") // /S/L/E
#define kBCPathKey CFSTR("Path") // /S/L/E.mkext
#define kBCAdditionalPathsKey CFSTR("AdditionalPaths") // array
#define kBCBootConfigKey CFSTR("BootConfig") // path string
typedef enum {
kMkextCRCError = -1,
kMkextCRCFound = 0,
kMkextCRCNotFound = 1,
} MkextCRCResult;
typedef struct {
char rpath[PATH_MAX]; char tspath[PATH_MAX]; struct timeval tstamps[2]; } cachedPath;
#define NCHARSUUID (2*sizeof(uuid_t) + 5) // hex with 4 -'s and one NUL
#define DEVMAXPATHSIZE 128 // devfs/devfsdefs.h:
struct bootCaches {
int cachefd; char bsdname[DEVMAXPATHSIZE]; char uuid_str[NCHARSUUID]; char volname[NAME_MAX]; char root[PATH_MAX]; CFDictionaryRef cacheinfo;
char exts[PATH_MAX]; int nrps; cachedPath *rpspaths; int nmisc; cachedPath *miscpaths; cachedPath efibooter; cachedPath ofbooter;
cachedPath *mkext; cachedPath *bootconfig; cachedPath *label; };
Boolean hasBoots(char *bsdname, CFArrayRef *auxPartsCopy, Boolean *isGPT);
Boolean bootedFromDifferentMkext(void);
#if TARGET_OS_EMBEDDED
typedef void * DADiskRef;
typedef void * DASessionRef;
typedef void * DADissenterRef;
typedef void * DAApprovalSessionRef;
#define kDADiskDescriptionVolumeUUIDKey ""
#define kDADiskDescriptionVolumeNameKey ""
#define kDADiskDescriptionMediaBSDNameKey ""
#define kDADiskDescriptionVolumePathKey ""
#endif
struct bootCaches* readCaches(DADiskRef dadisk);
void destroyCaches(struct bootCaches *caches);
int fillCachedPath(cachedPath *cpath, char *uuidchars, char *relpath);
DADiskRef createDiskForMount(DASessionRef session, const char *mount);
int needsUpdate(char *root, cachedPath* cpath, Boolean *outofdate);
int needUpdates(struct bootCaches *caches, Boolean *any,
Boolean *rps, Boolean *booters, Boolean *misc);
int applyStamps(struct bootCaches *caches);
Boolean check_plist_cache(struct bootCaches *caches);
Boolean check_mkext(struct bootCaches *caches);
int rebuild_mkext(struct bootCaches *caches, Boolean wait);
void _daDone(DADiskRef disk, DADissenterRef dissenter, void *ctx);
#endif