#ifndef __BOOTCACHES_H__
#define __BOOTCACHES_H__
#include <CoreFoundation/CoreFoundation.h>
#include <DiskArbitration/DiskArbitration.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <IOKit/kext/kextmanager_types.h> // uuid_string_t
#include <mach-o/arch.h>
#include "bootroot_internal.h" // includes bootroot.h
#define kTSCacheDir "/System/Library/Caches/com.apple.bootstamps"
#define kCacheDirMode 0755 // Sec reviewed
#define kCacheFileMode 0644
#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 kBCMKext2Key CFSTR("MKext2") // dict
#define kBCKernelcacheV1Key CFSTR("Kernelcache v1.1")// dict
#define kBCKernelcacheV2Key CFSTR("Kernelcache v1.2")// dict
#define kBCKernelcacheV3Key CFSTR("Kernelcache v1.3")// dict
#define kBCKernelPathKey CFSTR("KernelPath") // m_k | kernel
#define kBCPreferredCompressionKey CFSTR("Preferred Compression") // "lzvn"
#if DEV_KERNEL_SUPPORT
#define kBCKernelsDirKey CFSTR("KernelsDir") // S/L/Kernels
#endif
#define kBCArchsKey CFSTR("Archs") // ... i386
#define kBCExtensionsDirKey CFSTR("ExtensionsDir") // /S/L/E, /L/E
#define kBCPathKey CFSTR("Path") // ...kernelcache
#define kBCAdditionalPathsKey CFSTR("AdditionalPaths") // array
#define kBCBootConfigKey CFSTR("BootConfig") // bc.plist
#define kBCEncryptedRootKey CFSTR("EncryptedRoot") // dict
#define kBCCSFDEPropertyCacheKey CFSTR("EncryptedPropertyCache") // .wipekey
#define kBCCSFDERootVolPropCacheKey CFSTR("RootVolumePropertyCache")//A_B only?
#define kBCCSFDEDefResourcesDirKey CFSTR("DefaultResourcesDir") // EfiLoginUI
#define kBCCSFDELocalizationSrcKey CFSTR("LocalizationSource") // EFI.fr/Res
#define kBCCSFDELanguagesPrefKey CFSTR("LanguagesPref") // .GlobalPrefs
#define kBCCSFDEBackgroundImageKey CFSTR("BackgroundImage") // desktop..png
#define kBCCSFDELocRsrcsCacheKey CFSTR("LocalizedResourcesCache") // EFILocs
typedef enum {
kMkextCRCError = -1,
kMkextCRCFound = 0,
kMkextCRCNotFound = 1,
} MkextCRCResult;
#define NCHARSUUID (2*sizeof(uuid_t) + 5) // hex with 4 -'s and one NUL
#define BCPATH_MAX 128
#define TSPATH_MAX (BCPATH_MAX + 1 + NCHARSUUID + 1 + BCPATH_MAX)
#define DEVMAXPATHSIZE 128 // xnu/devfs/devfsdefs.h:
#define ROOTPATH_MAX (sizeof("/Volumes/") + NAME_MAX)
typedef struct {
char rpath[BCPATH_MAX]; char tspath[TSPATH_MAX]; struct timeval tstamps[2]; } cachedPath;
struct bootCaches {
int cachefd; char bsdname[DEVMAXPATHSIZE]; uuid_string_t fsys_uuid; CFStringRef csfde_uuid; char defLabel[NAME_MAX]; char root[ROOTPATH_MAX]; CFDictionaryRef cacheinfo; struct timespec bcTime;
char kernelpath[BCPATH_MAX]; int nexts; char *exts; char locSource[BCPATH_MAX]; char locPref[BCPATH_MAX]; char bgImage[BCPATH_MAX]; unsigned nrps; cachedPath *rpspaths; unsigned nmisc; cachedPath *miscpaths; cachedPath efibooter; cachedPath ofbooter;
cachedPath *kext_boot_cache_file; cachedPath *bootconfig; cachedPath *efidefrsrcs; cachedPath *efiloccache; cachedPath *label; cachedPath *erpropcache; Boolean erpropTSOnly; #if DEV_KERNEL_SUPPORT
int kernelsCount; int nekcp; cachedPath *extraKernelCachePaths; #endif
};
#undef TSPATH_MAX
#undef BCPATH_MAX
#undef ROOTPATH_MAX
Boolean hasBootRootBoots(struct bootCaches *caches, CFArrayRef *auxPartsCopy,
CFArrayRef *dataPartsCopy, Boolean *isAPM);
Boolean notBRDefault(const char *mount, const char *subdir);
int markNotBRDefault(int scopefd, const char *mount, const char* subdir,
Boolean marking);
int copyVolumeInfo(const char *vol_path, uuid_t *vol_uuid,
CFStringRef *cslvf_uuid, char vol_bsd[DEVMAXPATHSIZE],
char vol_name[NAME_MAX]);
int copyCSFDEInfo(CFStringRef uuidStr, CFDictionaryRef *encContext,
time_t *timeStamp);
struct bootCaches* readBootCaches(char *volRoot, BRUpdateOpts_t opts);
struct bootCaches* readBootCachesForDADisk(DADiskRef dadisk);
void destroyCaches(struct bootCaches *caches);
DADiskRef createDiskForMount(DASessionRef session, const char *mount);
Boolean needUpdates(struct bootCaches *caches, BRUpdateOpts_t opts,
Boolean *rps, Boolean *booters, Boolean *misc,
OSKextLogSpec oodLogSpec);
int taintDefaultStamps(CFStringRef targetBSD);
#define kBCStampsUnlinkOnly 0 // updateStamps always unlinks
#define kBCStampsApplyTimes 1 // apply stored timestamps
int updateStamps(struct bootCaches *caches, int command);
Boolean plistCachesNeedRebuild(const NXArchInfo * kernelArchInfo);
Boolean check_kext_boot_cache_file(
struct bootCaches * caches,
const char * cache_path,
const char * kernel_path);
int rebuild_kext_boot_cache_file(
struct bootCaches *caches,
Boolean wait,
const char * cache_path,
const char * kernel_file);
Boolean check_csfde(struct bootCaches *caches);
int rebuild_csfde_cache(struct bootCaches *caches);
int writeCSFDEProps(int scopefd, CFDictionaryRef ectx,
char *cspvbsd, char *dstpath);
Boolean check_loccache(struct bootCaches *caches);
int rebuild_loccache(struct bootCaches *caches);
void _daDone(DADiskRef disk, DADissenterRef dissenter, void *ctx);
int updateMount(mountpoint_t mount, uint32_t mntgoal);
pid_t launch_rebuild_all(char * rootPath, Boolean force, Boolean wait);
#endif