Chameleon

Chameleon Commit Details

Date:2015-01-26 01:36:47 (9 years 2 months ago)
Author:ErmaC
Commit:2562
Parents: 2561
Message:Added ability to auto-select last booted partition as the boot volume (Credits to Bungo).
Changes:
M/trunk/i386/boot2/boot.c
M/trunk/CHANGES
M/trunk/i386/boot2/options.c
M/trunk/i386/libsaio/sys.c

File differences

trunk/i386/libsaio/sys.c
373373
374374
375375
376
376
377
378
379
380
381
382
383
377384
378
379
380
381
385
382386
383387
384388
......
952956
953957
954958
955
959
960
961
962
963
964
956965
957966
958967
......
970979
971980
972981
982
983
973984
974985
975986
......
9931004
9941005
9951006
1007
1008
9961009
9971010
9981011
9991012
10001013
10011014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
10021043
10031044
10041045
......
10681109
10691110
10701111
1071
1072
1073
1112
1113
1114
10741115
10751116
10761117
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;
}
//==========================================================================
{
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)
{
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;
}
}
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.
}
}
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;
}
trunk/i386/boot2/boot.c
390390
391391
392392
393
393
394394
395395
396396
......
782782
783783
784784
785
785
786786
787787
788788
}
// 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
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)
{
trunk/i386/boot2/options.c
12791279
12801280
12811281
1282
1283
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
12841294
12851295
12861296
......
13861396
13871397
13881398
1389
13901399
13911400
1401
13921402
13931403
13941404
......
14001410
14011411
14021412
1413
1414
1415
1416
14031417
14041418
1405
1419
14061420
14071421
14081422
14091423
14101424
14111425
1412
1426
14131427
14141428
14151429
14161430
1417
1431
14181432
1419
1433
14201434
14211435
14221436
14231437
1438
14241439
14251440
14261441
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.
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))
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));
}
trunk/CHANGES
1
12
23
34
- 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).

Archive Download the corresponding diff file

Revision: 2562