Index: branches/danielkza/i386/libsaio/ntfs.c =================================================================== --- branches/danielkza/i386/libsaio/ntfs.c (revision 423) +++ branches/danielkza/i386/libsaio/ntfs.c (revision 424) @@ -297,8 +297,6 @@ long NTFSGetUUID(CICell ih, char *uuidStr) { - bool NTFSProbe(const void*); - struct bootfile *boot; void *buf = malloc(MAX_BLOCK_SIZE); if ( !buf ) @@ -324,9 +322,11 @@ return -1; // Use UUID like the one you get on Windows - return sprintf(uuidStr, "%04X-%04X", (unsigned short)(boot->bf_volsn >> 16) & 0xFFFF, - (unsigned short)boot->bf_volsn & 0xFFFF); + sprintf(uuidStr, "%04X-%04X", (unsigned short)(boot->bf_volsn >> 16) & 0xFFFF, + (unsigned short)boot->bf_volsn & 0xFFFF); + return 0; + // return CreateUUIDString((uint8_t*)&(boot->bf_volsn), sizeof(boot->bf_volsn), uuidStr); } Index: branches/danielkza/i386/libsaio/sys.c =================================================================== --- branches/danielkza/i386/libsaio/sys.c (revision 423) +++ branches/danielkza/i386/libsaio/sys.c (revision 424) @@ -827,13 +827,23 @@ * We accept only kBVFlagSystemVolume or kBVFlagForeignBoot volumes. */ char *val = XMLDecode(getStringForKey(kDefaultPartition, &bootInfo->bootConfig)); - if (val) { - for ( bvr = chain; bvr; bvr = bvr->next ) { - if (matchVolumeToString(bvr, val, false)) { - free(val); - return bvr; + if (val) + { + long len = 0; + char *vol = strbreak(val, 0, &len); + + if ( len ) + { + for ( bvr = chain; bvr; bvr = bvr->next ) + { + if ( (bvr->flags & (kBVFlagSystemVolume|kBVFlagForeignBoot)) && matchVolumeToString(bvr, vol, len) ) + { + free(val); + return bvr; + } } } + free(val); } Index: branches/danielkza/i386/libsaio/disk.c =================================================================== --- branches/danielkza/i386/libsaio/disk.c (revision 423) +++ branches/danielkza/i386/libsaio/disk.c (revision 424) @@ -1600,10 +1600,17 @@ /* Looking for "Hide Partition" entries in 'hd(x,y)|uuid|"label" hd(m,n)|uuid|"label"' format * to be able to hide foreign partitions from the boot menu. */ - if ( (newBVR->flags & kBVFlagForeignBoot) ) + if ( (newBVR->flags & kBVFlagForeignBoot) && val) { - if(val && matchVolumeToString(newBVR, val, true)) - newBVR->visible = false; + char *start, *next = val; + long len = 0; + do + { + start = strbreak(next, &next, &len); + if(len && matchVolumeToString(newBVR, start, len) ) + newBVR->visible = false; + } + while ( next && *next ); } /* @@ -1685,86 +1692,47 @@ //========================================================================== -char* matchVolumeToString( BVRef bvr, const char* match, bool matchParcial) +bool matchVolumeToString( BVRef bvr, const char* match, long matchLen) { char testStr[64]; - char *ret = 0; - int len = 0; if ( !bvr || !match || !*match) return 0; - if ( bvr->biosdev < 0x80 || bvr->biosdev >= 0x100 - || !(bvr->flags & (kBVFlagSystemVolume|kBVFlagForeignBoot)) ) + if ( bvr->biosdev < 0x80 || bvr->biosdev >= 0x100 ) return 0; - + // Try to match hd(x,y) first. - len = snprintf(testStr, sizeof(testStr)-1, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no); - if ( matchParcial ) - ret = strstr(match, testStr); - else if ( !strcmp(match, testStr) ) - ret = (char*) match; - if(ret) - return ret+len; + snprintf(testStr, sizeof(testStr)-1, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no); + if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) + return true; - // Try to match volume UUID. - if ( bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0 ) + if ( bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0) { - { - char* temp = malloc(64); - if(temp && bvr->description) { - bvr->description(bvr, temp, 63); - printf("Volume: UUID=%s, Label=%s\n", testStr, temp); - } - } - - len = strlen(testStr); - if ( matchParcial ) - ret = strstr(match, testStr); - else if ( !strcmp(match, testStr) ) - ret = (char*) match; - if(ret) - return ret+len; + if( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) + return true; } // Try to match volume label (always quoted). if ( bvr->description ) - { - char *temp = 0; - - bvr->description(bvr, testStr, sizeof(testStr)-1); - len = strlen(testStr); - if ( !len ) - return 0; - - len += 2; /* quoted */ - temp = malloc(len+1); - - if(temp) - { - len = snprintf(temp, len, "\"%s\"", testStr); - if ( matchParcial ) - ret = strstr(match, temp); - else if ( !strcmp(match, temp) ) - ret = (char*) match; - - free(temp); - if (ret) - return ret+len; - } - } - - return 0; + { + bvr->description(bvr, testStr, sizeof(testStr)-1); + if( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) + return true; + } + + return false; } -/* If Rename Partition has defined an alias, then extract it for description purpose */ -bool getVolumeLabelAlias( BVRef bvr, char* str, long strMaxLen) +/* If Rename Partition has defined an alias, then extract it for description purpose + * The format for the rename string is the following: + * hd(x,y)|uuid|"label" "alias";hd(m,n)|uuid|"label" etc; ... + */ + +bool getVolumeLabelAlias(BVRef bvr, char* str, long strMaxLen) { - /* The format for the rename string is the following: - * hd(x,y)|uuid|"label" "alias";hd(m,n)|uuid|"label" etc; ... - */ - char *aliasList, *next; + char *aliasList, *entryStart, *entryNext; if ( !str || strMaxLen <= 0) return false; @@ -1772,61 +1740,39 @@ aliasList = XMLDecode(getStringForKey(kRenamePartition, &bootInfo->bootConfig)); if ( !aliasList ) return false; - - next = aliasList; - while ( next && *next ) + + for ( entryStart = entryNext = aliasList; + entryNext && *entryNext; + entryStart = entryNext ) { - char *start, *aliasStart, *aliasEnd; - char *ret; + char *volStart, *volEnd, *aliasStart; + long volLen, aliasLen; - start = aliasStart = (char*)matchVolumeToString(bvr, next, true); - if ( !start || !*start ) - break; - - /* Find and delimit the current entry's end */ - next = strstr(start, ";"); - if ( next ) + // Delimit current entry + entryNext = strchr(entryStart, ';'); + if ( entryNext ) { - /* Not enough characters for a successful match: we'd need at least - * one space and another char. before the semicolon - */ - if ( next-start < 2 ) { - next++; - continue; - } - - *next = '\0'; - next++; + *entryNext = '\0'; + entryNext++; } - /* Check for at least one space, but ignore the rest of them */ - while ( isspace(*aliasStart) ) - aliasStart++; - if ( start == aliasStart ) + volStart = strbreak(entryStart, &volEnd, &volLen); + if(!volLen) continue; - - switch ( *aliasStart ) - { - case '\0': - break; - case '"': - /* If a starting quote is found, skip it, then find the ending one, - * and replace it for a string terminator. - */ - aliasStart++; - aliasEnd = strstr(aliasStart, "\""); - if ( !aliasEnd || aliasStart == aliasEnd ) - break; - - *aliasEnd = '\0'; - default: - ret = strncpy(str, aliasStart, strMaxLen); - free(aliasList); - - return ret != 0; + + aliasStart = strbreak(volEnd, 0, &aliasLen); + if(!aliasLen) + continue; + + if ( matchVolumeToString(bvr, volStart, volLen) ) + { + strncpy(str, aliasStart, min(strMaxLen, aliasLen)); + free(aliasList); + + return true; } } - + free(aliasList); return false; } @@ -1855,7 +1801,6 @@ /* See if a partition rename is preferred */ if(getVolumeLabelAlias(bvr, p, strMaxLen)) { - printf("Renamed: %s\n", p); strncpy(bvr->label, p, sizeof(bvr->label)-1); return; // we're done here no need to seek for real name } Index: branches/danielkza/i386/libsaio/disk.h =================================================================== --- branches/danielkza/i386/libsaio/disk.h (revision 423) +++ branches/danielkza/i386/libsaio/disk.h (revision 424) @@ -9,6 +9,6 @@ #ifndef __LIBSAIO_DISK_H #define __LIBSAIO_DISK_H -char* matchVolumeToString( BVRef bvr, const char* match, bool matchPartial); +bool matchVolumeToString( BVRef bvr, const char* match, long strMaxLen); #endif /* __LIBSAIO_DISK_H */ \ No newline at end of file Index: branches/danielkza/i386/libsa/libsa.h =================================================================== --- branches/danielkza/i386/libsa/libsa.h (revision 423) +++ branches/danielkza/i386/libsa/libsa.h (revision 424) @@ -107,6 +107,9 @@ extern int strncasecmp(const char * s1, const char * s2, size_t n); #endif +extern char * strchr(const char *str, int c); +extern char * strbreak(const char *str, char **next, long *len); + extern uint8_t checksum8( void * start, unsigned int length ); /* Index: branches/danielkza/i386/libsa/string.c =================================================================== --- branches/danielkza/i386/libsa/string.c (revision 423) +++ branches/danielkza/i386/libsa/string.c (revision 424) @@ -257,6 +257,62 @@ } #endif +char* strchr(const char *str, int c) +{ + do + { + if(*str == c) + return (char*)str; + } + while(*(str++)); + + return 0; +} + + +char* strbreak(const char *str, char **next, long *len) +{ + char *start = (char*)str, *end; + char *tmpNext; + + if ( !start || !len ) + return 0; + + while ( isspace(*start) ) + start++; + + if (*start == '"') + { + end = strchr(++start, '"'); + if(end) + { + *len = end - start; + tmpNext = end+1; + } + else + { + *len = strlen(start); + tmpNext = start + (*len) + 1; + } + } + else + { + for(end = start; *end; end++) + { + if(isspace(*end)) + break; + } + + *len = end - start; + tmpNext = end; + } + + if(tmpNext) + *next = tmpNext; + + return start; +} + /* COPYRIGHT NOTICE: checksum8 from AppleSMBIOS */ uint8_t checksum8( void * start, unsigned int length ) {