Index: trunk/i386/libsaio/sys.c =================================================================== --- trunk/i386/libsaio/sys.c (revision 2561) +++ trunk/i386/libsaio/sys.c (revision 2562) @@ -373,12 +373,16 @@ return -1; } - // Return 0 on success, or -1 if there are no additional entries. + if (bvr->fs_getdirentry) + { + // Returns 0 on success or -1 when there are no additional entries. + return bvr->fs_getdirentry( bvr, + /* dirPath */ (char *)dirPath, + /* dirIndex */ dirIndex, + /* dirEntry */ (char **)name, flags, time, 0, 0 ); + } - return bvr->fs_getdirentry( bvr, - /* dirPath */ (char *)dirPath, - /* dirIndex */ dirIndex, - /* dirEntry */ (char **)name, flags, time, 0, 0 ); + return -1; } //========================================================================== @@ -952,7 +956,12 @@ { bool filteredChain = false; bool foundPrimary = false; - BVRef bvr, bvr1 = 0, bvr2 = 0; + BVRef bvr = NULL; + BVRef bvr1 = NULL; + BVRef bvr2 = NULL; + char dirSpec[] = "hd(%d,%d)/", fileSpec[] = "Volumes", *label; + u_int32_t time, lasttime = 0; + long flags; if (chain->filtered) { @@ -970,6 +979,8 @@ if ( (bvr->part_no == multiboot_partition) && (bvr->biosdev == gBIOSDev) ) { + label = bvr->label[0] ? bvr->label : (bvr->altlabel[0] ? bvr->altlabel : (bvr->name[0] ? bvr->name : "Untitled")); + DBG("Multiboot partition set: hd(%d,%d) '%s'\n", BIOS_DEV_UNIT(bvr), bvr->part_no, label); return bvr; } } @@ -993,12 +1004,42 @@ if (matchVolumeToString(bvr, val, false)) { free(val); + label = bvr->label[0] ? bvr->label : (bvr->altlabel[0] ? bvr->altlabel : (bvr->name[0] ? bvr->name : "Untitled")); + DBG("User default partition set: hd(%d,%d) '%s'\n", BIOS_DEV_UNIT(bvr), bvr->part_no, label); return bvr; } } free(val); } + // Bungo: select last booted partition as the boot volume + // TODO: support other OSes (foreign boot) + for (bvr = chain; bvr; bvr = bvr->next) { + if (bvr->flags & (kBVFlagSystemVolume | kBVFlagForeignBoot)) + { + time = 0; + flags = 0; + sprintf(dirSpec, "hd(%d,%d)/", BIOS_DEV_UNIT(bvr), bvr->part_no); + if ((GetFileInfo(dirSpec, fileSpec, &flags, &time) == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) + { + if (time > lasttime) + { + lasttime = time; + bvr1 = bvr; + label = bvr1->label[0] ? bvr1->label : (bvr1->altlabel[0] ? bvr1->altlabel : (bvr1->name[0] ? bvr1->name : "Untitled")); + } + } + } + } + + if (bvr1) + { + DBG("Last booted volume: hd(%d,%d) '%s' set as default partition\n\n", BIOS_DEV_UNIT(bvr1), bvr1->part_no, label); + return bvr1; + } + // Bungo: code below selects first partition in the chain (last partition on disk), + // in my case Recovery HD, as boot volume, so I would prefer last booted partition + // as default boot volume - see the code above /* * Scannig the volume chain backwards and trying to find * a HFS+ volume with valid boot record signature. @@ -1068,9 +1109,9 @@ } } - bvr = bvr2 ? bvr2 : - bvr1 ? bvr1 : chain; - + bvr = bvr2 ? bvr2 : (bvr1 ? bvr1 : chain); + label = bvr->label[0] ? bvr->label : (bvr->altlabel[0] ? bvr->altlabel : (bvr->name[0] ? bvr->name : "Untitled")); + DBG("Default partition set: hd(%d,%d) '%s'\n", BIOS_DEV_UNIT(bvr), bvr->part_no, label); return bvr; } Index: trunk/i386/boot2/boot.c =================================================================== --- trunk/i386/boot2/boot.c (revision 2561) +++ trunk/i386/boot2/boot.c (revision 2562) @@ -390,7 +390,7 @@ } // Since the kernel cache file exists and is the most recent try to load it - DBG("Loading Kernel Cache from: '%s'\n", kernelCachePath); + DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name); ret = LoadThinFatFile(kernelCachePath, binary); return ret; // ret contain the length of the binary @@ -782,7 +782,7 @@ strlcpy(bootFilePath, bootFile, sizeof(bootFilePath)); } - DBG("Loading kernel from: '%s'\n", bootFilePath); + DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name); ret = LoadThinFatFile(bootFilePath, &binary); if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { Index: trunk/i386/boot2/options.c =================================================================== --- trunk/i386/boot2/options.c (revision 2561) +++ trunk/i386/boot2/options.c (revision 2562) @@ -1279,8 +1279,18 @@ return -1; } - // Find out which version mac os we're booting. - strncpy(gMacOSVersion, gBootVolume->OSVersion, sizeof(gMacOSVersion)); + // Save a version of mac os we're booting. + MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion); + // so copy it and trim + gMacOSVersion[0] = 0; + if (MacOSVerCurrent >= MacOSVer2Int("10.10")) + { + strncat(gMacOSVersion, gBootVolume->OSVersion, 5); + } + else + { + strncat(gMacOSVersion, gBootVolume->OSVersion, 4); + } // Load config table specified by the user, or use the default. @@ -1386,9 +1396,9 @@ if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) { gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString); - DBG("boot-uuid: %s\n", gBootUUIDString); } } + DBG("Boot UUID [%s (%s), %s]: %s\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name, gBootUUIDString); if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) @@ -1400,27 +1410,32 @@ cnt++; strlcpy(valueBuffer + 1, val, cnt); val = valueBuffer; + if (cnt > 0) + { + copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); + } } else - { /* + { if (strlen(gBootUUIDString)) { val = "*uuid"; cnt = 5; } else - { */ + { // Don't set "rd=.." if there is no boot device key // and no UUID. val = ""; cnt = 0; - /* } */ + } } - +/* Bungo if (cnt > 0) { copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); } +*/ strlcpy(gRootDevice, val, (cnt + 1)); } Index: trunk/CHANGES =================================================================== --- trunk/CHANGES (revision 2561) +++ trunk/CHANGES (revision 2562) @@ -1,3 +1,4 @@ +- Bungo : Added ability to auto-select last booted partition as the boot volume. - Bungo : Added MacOSVerCurrent and MacOSVer2Int function to use instead of macros. - Bungo : Fixed bug in gDarwinBuildVerStr extracting. - Bungo : Fixed fixedUUID function (convert.c smbios.c).