Index: trunk/i386/libsaio/bootargs.h =================================================================== --- trunk/i386/libsaio/bootargs.h (revision 2559) +++ trunk/i386/libsaio/bootargs.h (revision 2560) @@ -222,6 +222,4 @@ } boot_args_pre_lion; -extern char gMacOSVersion[8]; - #endif /* _PEXPERT_I386_BOOT_H */ Index: trunk/i386/libsaio/saio_types.h =================================================================== --- trunk/i386/libsaio/saio_types.h (revision 2559) +++ trunk/i386/libsaio/saio_types.h (revision 2560) @@ -182,7 +182,8 @@ BVRef dir_bvr; /* volume reference */ }; -#define BVSTRLEN 32 +#define BVSTRLEN 36 // changed from 32 to 36 due to gpt partition name length +#define OSVERSTRLEN 9 struct BootVolume { BVRef next; /* list linkage pointer */ @@ -209,9 +210,9 @@ char altlabel[BVSTRLEN]; /* alternate partition volume label */ bool filtered; /* newFilteredBVChain() will set to TRUE */ bool visible; /* will shown in the device list */ - char OSVersion[8]; + char OSVersion[OSVERSTRLEN]; /* Null terminated string from '/System/Library/CoreServices/SystemVersion.plist/ProductVersion' e.g. "10.10.10" - hope will not reach e.g. 111.222.333 soon:) If so, OSVERSTRLEN 9 change to 12 */ bool OSisServer; /* 1 = OS X server , 0 = OS X client */ - bool OSisInstaller; /* 1 = OS X Install partition / recover partition , 0 = OS X Install */ + bool OSisInstaller; /* 1 = OS X Install partition / recovery partition , 0 = OS X Install */ }; Index: trunk/i386/libsaio/saio_internal.h =================================================================== --- trunk/i386/libsaio/saio_internal.h (revision 2559) +++ trunk/i386/libsaio/saio_internal.h (revision 2560) @@ -223,4 +223,9 @@ // Base64-decode.c char *BASE64Decode(const char* src, int in_len, int* out_len); +// options.c +extern char gMacOSVersion[OSVERSTRLEN]; +extern uint32_t MacOSVerCurrent; +extern uint32_t MacOSVer2Int(const char *osver); + #endif /* !__LIBSAIO_SAIO_INTERNAL_H */ Index: trunk/i386/boot2/drivers.c =================================================================== --- trunk/i386/boot2/drivers.c (revision 2559) +++ trunk/i386/boot2/drivers.c (revision 2560) @@ -116,8 +116,8 @@ static char *gFileSpec; static char *gTempSpec; static char *gFileName; -// Bungo -char *gDarwinBuildVerStr = "Darwin Kernel Version"; +// Bungo: +char gDarwinBuildVerStr[256] = "Darwin Kernel Version"; /*static*/ unsigned long Adler32( unsigned char *buffer, long length ) @@ -981,12 +981,21 @@ ret = ThinFatFile(&binary, &len); } - // Bungo: no range checking, sorry - size = 0; - while (memcmp((uint8_t *)binary + size, (uint8_t *)gDarwinBuildVerStr, 21)) { - size++; + // Bungo: scan binary for Darwin Kernel Version string + uint32_t offset = 0; + strncpy(gDarwinBuildVerStr, "Darwin Kernel Version", sizeof(gDarwinBuildVerStr)); + while ((offset < 0xFFFFFFFF - (uint32_t)binary - 256) && memcmp(binary + offset, gDarwinBuildVerStr, 21)) + { + offset++; } - gDarwinBuildVerStr = (char *)binary + size; + if (offset < 0xFFFFFFFF - (uint32_t)binary - 256) + { + strncpy(gDarwinBuildVerStr, (char *)(binary + offset), sizeof(gDarwinBuildVerStr)); + } + else + { + strcat(gDarwinBuildVerStr, ": Unknown"); + } // Notify modules that the kernel has been decompressed, thinned and is about to be decoded execute_hook("DecodeKernel", (void *)binary, NULL, NULL, NULL); Index: trunk/i386/boot2/boot.c =================================================================== --- trunk/i386/boot2/boot.c (revision 2559) +++ trunk/i386/boot2/boot.c (revision 2560) @@ -84,7 +84,6 @@ char gRootDevice[ROOT_DEVICE_SIZE]; char gMKextName[512]; -char gMacOSVersion[8]; int bvCount = 0; int gDeviceCount = 0; //int menucount = 0; @@ -871,6 +870,12 @@ } } +uint32_t getMacOSVerCurrent() +{ + MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion); + return MacOSVerCurrent; +} + #define BASE 65521L /* largest prime smaller than 65536 */ #define NMAX 5000 // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 Index: trunk/i386/boot2/boot.h =================================================================== --- trunk/i386/boot2/boot.h (revision 2559) +++ trunk/i386/boot2/boot.h (revision 2560) @@ -231,7 +231,9 @@ extern void initialize_runtime(); extern void common_boot(int biosdev); -bool checkOSVersion(const char * version); +extern bool checkOSVersion(const char * version); +extern uint32_t getMacOSVerCurrent(); + /* * usb.c */ @@ -277,8 +279,8 @@ extern long LoadDrivers(char * dirSpec); extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize); typedef long (*FileLoadDrivers_t)(char *dirSpec, long plugin); -// Bungo -extern char *gDarwinBuildVerStr; +// Bungo: +extern char gDarwinBuildVerStr[256]; /*! Hookable function pointer called during the driver loading phase that Index: trunk/i386/boot2/options.c =================================================================== --- trunk/i386/boot2/options.c (revision 2559) +++ trunk/i386/boot2/options.c (revision 2560) @@ -38,6 +38,8 @@ #define DBG(x...) msglog(x) #endif +char gMacOSVersion[OSVERSTRLEN]; +uint32_t MacOSVerCurrent = 0; bool showBootBanner = true; //Azi:showinfo static bool shouldboot = false; @@ -65,6 +67,53 @@ //========================================================================== +// MacOSVer2Int - converts OS ver. string to uint32 (e.g "10.9.5" -> 0x0A090500) for easy comparing +uint32_t MacOSVer2Int(const char *osver) +{ + uint32_t result = 0; + uint8_t *resptr = (uint8_t *)&result; + uint8_t len = strlen(osver); + uint8_t i, j, m; +#define CHR2UINT(c) ((uint8_t)(c - '0')) +#define ISDIGIT(c) ((c >= '0') && (c <= '9')) +#define ISDOT(c) (c == '.') + + if (!osver || (len < 4) || (len > OSVERSTRLEN - 1) || !ISDIGIT(osver[0]) || !ISDOT(osver[2]) || !ISDIGIT(osver[len - 1])) + { + verbose("ERROR: wrong Mac OS version string syntax: '%s'\n", osver); + return 0; + } + + for (i = 0, j = 3, m = 1; i < len; i++) + { + if (ISDIGIT(osver[i])) + { + resptr[j] = resptr[j] * m + CHR2UINT(osver[i]); + m = 10; + } + else if (ISDOT(osver[i])) + { + if (j > 0) + { + j--; + } + else + { + return 0; + } + m = 1; + } + else + { + return 0; + } + } + + return result; +} + +//========================================================================== + typedef struct { int x; int y; Index: trunk/CHANGES =================================================================== --- trunk/CHANGES (revision 2559) +++ trunk/CHANGES (revision 2560) @@ -1,3 +1,5 @@ +- 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). - Bungo : Added Logging start time. - Bungo : Added getRTCdatetime() Int 1Ah function 02h - RTC service.