long FileLoadDrivers( char * dirSpec, long plugin ) { long ret, length, flags, time, bundleType; long long index; long result = -1; const char * name; if ( !plugin ) { // First try 10.6's path for loading Extensions.mkext. if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0) return 0; // Next try the legacy path. else if (FileLoadMKext(dirSpec, "") == 0) return 0; strcat(dirSpec, "Extensions"); } index = 0; while (1) { ret = GetDirEntry(dirSpec, &index, &name, &flags, &time); if (ret == -1) break; // Make sure this is a directory. if ((flags & kFileTypeMask) != kFileTypeDirectory) continue; // Make sure this is a kext. length = strlen(name); if (strcmp(name + length - 5, ".kext")) continue; // Save the file name. strcpy(gFileName, name); // Determine the bundle type. sprintf(gTempSpec, "%s/%s", dirSpec, gFileName); ret = GetFileInfo(gTempSpec, "Contents", &flags, &time); if (ret == 0) bundleType = kCFBundleType2; else bundleType = kCFBundleType3; if (!plugin) sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName, (bundleType == kCFBundleType2) ? "Contents/" : ""); ret = LoadDriverPList(dirSpec, gFileName, bundleType); if (result != 0) result = ret; if (!plugin) FileLoadDrivers(gDriverSpec, 1); } return result; }
long LoadDrivers( char * dirSpec ) { if ( InitDriverSupport() != 0 ) return 0; if ( gBootFileType == kNetworkDeviceType ) { if (NetLoadDrivers(dirSpec) != 0) { error("Could not load drivers from the network\n"); return -1; } } else if ( gBootFileType == kBlockDeviceType ) { if (gMKextName[0] != '\0') { verbose("LoadDrivers: Loading from [%s]\n", gMKextName); if ( LoadDriverMKext(gMKextName) != 0 ) { error("Could not load %s\n", gMKextName); return -1; } } else { strcpy(gExtensionsSpec, dirSpec); strcat(gExtensionsSpec, "System/Library/"); FileLoadDrivers(gExtensionsSpec, 0); } } else { return 0; } MatchPersonalities(); MatchLibraries(); LoadMatchedModules(); return 0; }
static long FileLoadDrivers( char * dirSpec, long plugin ) { long ret, length, index, flags, time, bundleType; const char * name; if ( !plugin ) { long time2; ret = GetFileInfo(dirSpec, "Extensions.mkext", &flags, &time); if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)) { ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2); if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) || (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1)))) { sprintf(gDriverSpec, "%sExtensions.mkext", dirSpec); verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec); if (LoadDriverMKext(gDriverSpec) == 0) return 0; } } strcat(dirSpec, "Extensions"); } verbose("LoadDrivers: Loading from [%s]\n", dirSpec); index = 0; while (1) { ret = GetDirEntry(dirSpec, &index, &name, &flags, &time); if (ret == -1) break; // Make sure this is a directory. if ((flags & kFileTypeMask) != kFileTypeDirectory) continue; // Make sure this is a kext. length = strlen(name); if (strcmp(name + length - 5, ".kext")) continue; // Save the file name. strcpy(gFileName, name); // Determine the bundle type. sprintf(gTempSpec, "%s/%s", dirSpec, gFileName); ret = GetFileInfo(gTempSpec, "Contents", &flags, &time); if (ret == 0) bundleType = kCFBundleType2; else bundleType = kCFBundleType3; if (!plugin) sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName, (bundleType == kCFBundleType2) ? "Contents/" : ""); ret = LoadDriverPList(dirSpec, gFileName, bundleType); if (ret != 0) { //printf("LoadDrivers: failed for '%s'/'%s'\n", dirSpec, gFileName); } if (!plugin) ret = FileLoadDrivers(gDriverSpec, 1); } return 0; }
long LoadDrivers( char * dirSpec ) { char dirSpecExtra[1024]; if ( InitDriverSupport() != 0 ) { return 0; } // Load extra drivers if a hook has been installed. if (LoadExtraDrivers_p != NULL) { (*LoadExtraDrivers_p)(&FileLoadDrivers); } if ( gBootFileType == kNetworkDeviceType ) { if (NetLoadDrivers(dirSpec) != 0) { error("Could not load drivers from the network\n"); return -1; } } else if ( gBootFileType == kBlockDeviceType ) { // First try to load Extra extensions from the ramdisk if isn't aliased as bt(0,0). if (gRAMDiskVolume && !gRAMDiskBTAliased) { strcpy(dirSpecExtra, "rd(0,0)/Extra/"); FileLoadDrivers(dirSpecExtra, 0); } // Next try to load Extra extensions from the selected root partition. strcpy(dirSpecExtra, "/Extra/"); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { // If failed, then try to load Extra extensions from the boot partition // in case we have a separate booter partition or a bt(0,0) aliased ramdisk. if ( !(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no) || (gRAMDiskVolume && gRAMDiskBTAliased) ) { // Next try a specfic OS version folder ie 10.5 sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { // Next we'll try the base strcpy(dirSpecExtra, "bt(0,0)/Extra/"); FileLoadDrivers(dirSpecExtra, 0); } } } if(!gHaveKernelCache) { // Don't load main driver (from /System/Library/Extentions) if gHaveKernelCache is set. // since these drivers will already be in the kernel cache. // NOTE: when gHaveKernelCache, xnu cannot (by default) load *any* extra kexts from the bootloader. // The /Extra code is not disabled in this case due to a kernel patch that allows for this to happen. // Also try to load Extensions from boot helper partitions. if (gBootVolume->flags & kBVFlagBooter) { strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/"); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/"); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/"); FileLoadDrivers(dirSpecExtra, 0); } } } if (gMKextName[0] != '\0') { verbose("LoadDrivers: Loading from [%s]\n", gMKextName); if ( LoadDriverMKext(gMKextName) != 0 ) { error("Could not load %s\n", gMKextName); return -1; } } else { if ( MAVERICKS || YOSEMITE ) // issue 352 { strlcpy(gExtensionsSpec, dirSpec, 4087); /* 4096 - sizeof("Library/") */ strcat(gExtensionsSpec, "Library/"); FileLoadDrivers(gExtensionsSpec, 0); } strlcpy(gExtensionsSpec, dirSpec, 4080); /* 4096 - sizeof("System/Library/") */ strcat(gExtensionsSpec, "System/Library/"); FileLoadDrivers(gExtensionsSpec, 0); } } } else { return 0; } MatchPersonalities(); MatchLibraries(); LoadMatchedModules(); return 0; }
long NBI_LoadDrivers( char * dirSpec ) { char dirSpecExtra[1024]; if ( InitDriverSupport() != 0 ) return 0; int step = 0; execute_hook("ramDiskLoadDrivers", &step, NULL, NULL, NULL, NULL, NULL); #ifdef NBP_SUPPORT if ( get_env(envgBootFileType) == kNetworkDeviceType ) { if (NetLoadDrivers(dirSpec) != 0) { error("Could not load drivers from the network\n"); return -1; } } else #endif if ( get_env(envgBootFileType) == kBlockDeviceType ) { verbose("Loading Recovery Extensions\n"); strlcpy(dirSpecExtra, "/Extra/RecoveryExtensions/", sizeof(dirSpecExtra)); FileLoadDrivers(dirSpecExtra, sizeof(dirSpecExtra), 0); #ifdef BOOT_HELPER_SUPPORT // TODO: fix this, the order does matter, and it's not correct now. // Also try to load Extensions from boot helper partitions. if (((BVRef)(uint32_t)get_env(envgBootVolume))->flags & kBVFlagBooter) { strlcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/", sizeof(dirSpecExtra)); if (FileLoadDrivers(dirSpecExtra, sizeof(dirSpecExtra), 0) != 0) { strlcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/", sizeof(dirSpecExtra)); if (FileLoadDrivers(dirSpecExtra, sizeof(dirSpecExtra), 0) != 0) { strlcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/", sizeof(dirSpecExtra)); FileLoadDrivers(dirSpecExtra, sizeof(dirSpecExtra), 0); } } } #endif char * MKextName = (char*)(uint32_t)get_env(envMKextName); if (MKextName[0] != '\0') { verbose("LoadDrivers: Loading from [%s]\n", MKextName); if ( LoadDriverMKext(MKextName) != 0 ) { error("Could not load %s\n", MKextName); return -1; } } else { char * ExtensionsSpec = (char*)(uint32_t)get_env(envDriverExtSpec); strlcpy(ExtensionsSpec, dirSpec, DEFAULT_DRIVER_SPEC_SIZE); strlcat(ExtensionsSpec, "System/Library/", DEFAULT_DRIVER_SPEC_SIZE); FileLoadDrivers(ExtensionsSpec,DEFAULT_DRIVER_SPEC_SIZE, 0); } } else { return 0; } #if UNUSED MatchPersonalities(); #endif MatchLibraries(); LoadMatchedModules(); return 0; }
long LoadDrivers( char * dirSpec ) { const char * sLoadExtra = "LoadDrivers: Loading Extra drivers %s...\n"; char dirSpecExtra[1024]; if ( InitDriverSupport() != 0 ) return 0; #ifndef OPTION_ROM // Load extra drivers if a hook has been installed. if (LoadExtraDrivers_p != NULL) { (*LoadExtraDrivers_p)(&FileLoadDrivers); } if ( gBootFileType == kNetworkDeviceType ) { if (NetLoadDrivers(dirSpec) != 0) { error("Could not load drivers from the network\n"); return -1; } } else #endif if ( gBootFileType == kBlockDeviceType ) { // First try to load Extra extensions from the ramdisk if isn't aliased as bt(0,0). #ifndef OPTION_ROM // First try a specfic OS version folder ie 10.5 sprintf(dirSpecExtra, "rd(0,0)/Extra/%s/", &gMacOSVersion); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { // Next we'll try the base strcpy(dirSpecExtra, "rd(0,0)/Extra/"); FileLoadDrivers(dirSpecExtra, 0); } #endif // First try a specfic OS version folder ie 10.5 sprintf(dirSpecExtra, "/Extra/%s/", &gMacOSVersion); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { // Next try to load Extra extensions from the selected root partition. strcpy(dirSpecExtra, "/Extra/"); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { // If failed, then try to load Extra extensions from the boot partition // in case we have a separate booter partition or a bt(0,0) aliased ramdisk. if ( !(gBIOSBootVolume->biosdev == gBootVolume->biosdev && gBIOSBootVolume->part_no == gBootVolume->part_no) #ifndef OPTION_ROM || (gRAMDiskVolume && gRAMDiskBTAliased) ) #else ) #endif { // First try a specfic OS version folder ie 10.5 sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion); if (FileLoadDrivers(dirSpecExtra, 0) != 0) { // Next we'll try the base strcpy(dirSpecExtra, "bt(0,0)/Extra/"); verbose(sLoadExtra, dirSpecExtra); FileLoadDrivers(dirSpecExtra, 0); } } } }