Index: trunk/i386/libsaio/ntfs.c =================================================================== --- trunk/i386/libsaio/ntfs.c (revision 415) +++ trunk/i386/libsaio/ntfs.c (revision 416) @@ -297,37 +297,37 @@ long NTFSGetUUID(CICell ih, char *uuidStr) { - bool NTFSProbe(const void*); - - struct bootfile *boot; - void *buf = malloc(MAX_BLOCK_SIZE); - if ( !buf ) - return -1; - - /* - * Read the boot sector, check signatures, and do some minimal - * sanity checking. NOTE: the size of the read below is intended - * to be a multiple of all supported block sizes, so we don't - * have to determine or change the device's block size. - */ - Seek(ih, 0); - Read(ih, (long)buf, MAX_BLOCK_SIZE); - - boot = (struct bootfile *) buf; - - // Check for NTFS signature - if ( memcmp((void*)boot->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) != 0 ) - return -1; - - // Check for non-null volume serial number - if( !boot->bf_volsn ) - 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); - - // return CreateUUIDString((uint8_t*)&(boot->bf_volsn), sizeof(boot->bf_volsn), uuidStr); + bool NTFSProbe(const void*); + + struct bootfile *boot; + void *buf = malloc(MAX_BLOCK_SIZE); + if ( !buf ) + return -1; + + /* + * Read the boot sector, check signatures, and do some minimal + * sanity checking. NOTE: the size of the read below is intended + * to be a multiple of all supported block sizes, so we don't + * have to determine or change the device's block size. + */ + Seek(ih, 0); + Read(ih, (long)buf, MAX_BLOCK_SIZE); + + boot = (struct bootfile *) buf; + + // Check for NTFS signature + if ( memcmp((void*)boot->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) != 0 ) + return -1; + + // Check for non-null volume serial number + if( !boot->bf_volsn ) + return -1; + + // Use UUID like the one you get on Windows + sprintf(uuidStr, "%04X-%04X", (unsigned short)(boot->bf_volsn >> 16) & 0xFFFF, + (unsigned short)boot->bf_volsn & 0xFFFF); + + return 0; } bool NTFSProbe(const void * buffer) Index: trunk/i386/libsaio/disk.c =================================================================== --- trunk/i386/libsaio/disk.c (revision 415) +++ trunk/i386/libsaio/disk.c (revision 416) @@ -1685,77 +1685,64 @@ //========================================================================== -char* matchVolumeToString( BVRef bvr, const char* match, bool matchParcial) +static char * matchStrings(const char * str1, const char * str2, bool matchPartial) { - char testStr[64]; - char *ret = 0; - int len = 0; - + char * ret = NULL; + + if (matchPartial) + ret = strstr(str1, str2); + else if (!strcmp(str1, str2)) + ret = (char *)str1; + + if(ret) + ret += strlen(str2); + + return ret; +} + +char * matchVolumeToString(BVRef bvr, const char * match, bool matchPartial) +{ + char testStr[128]; + char tempStr[128]; + char * ret = NULL; + int len = 0; + + *tempStr = '\0'; + if ( !bvr || !match || !*match) - return 0; - + return NULL; + if ( bvr->biosdev < 0x80 || bvr->biosdev >= 0x100 - || !(bvr->flags & (kBVFlagSystemVolume|kBVFlagForeignBoot)) ) - 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; - - - // Try to match volume UUID. - if ( bvr->fs_getuuid && bvr->fs_getuuid(bvr, testStr) == 0 ) - { - { - char* temp = malloc(64); - if(temp && bvr->description) { - bvr->description(bvr, temp, 63); - verbose("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; - } - - // 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; - } + || !(bvr->flags & (kBVFlagSystemVolume|kBVFlagForeignBoot)) ) + return NULL; + + // Try to match hd(x,y) first. + sprintf(testStr, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no); + if (ret = matchStrings(match, testStr, matchPartial)) + return ret; + + // Try to match volume UUID. + if ( bvr->fs_getuuid && !(bvr->fs_getuuid(bvr, testStr)) ) + { + if (ret = matchStrings(match, testStr, matchPartial)) + return ret; } - - return 0; + + // Try to match volume label (always quoted). + if (bvr->description) + { + // Gather volume label into tempStr. + bvr->description(bvr, tempStr, sizeof(tempStr) - 1); + len = strlen(tempStr); + if (len == 0) + return NULL; + + sprintf(testStr, "\"%s\"", tempStr); + if (ret = matchStrings(match, testStr, matchPartial)) + return ret; + } + + return NULL; } /* If Rename Partition has defined an alias, then extract it for description purpose */ Index: trunk/i386/libsa/libsa.h =================================================================== --- trunk/i386/libsa/libsa.h (revision 415) +++ trunk/i386/libsa/libsa.h (revision 416) @@ -132,7 +132,6 @@ * printf.c */ extern int sprintf(char *s, const char * format, ...); -extern int snprintf(char *s, long len, const char* fmt, ...); extern int slvprintf(char * buffer, int len, const char * fmt, va_list arg); /* Index: trunk/i386/libsa/printf.c =================================================================== --- trunk/i386/libsa/printf.c (revision 415) +++ trunk/i386/libsa/printf.c (revision 416) @@ -60,20 +60,6 @@ return (pi.str - str); } -int snprintf(char *str, long len, const char * fmt, ...) -{ - va_list ap; - struct putc_info pi; - - va_start(ap, fmt); - pi.str = str; - pi.last_str = str + len - 1; - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; - va_end(ap); - return (pi.str - str); -} - /*VARARGS1*/ int slvprintf(char * str, int len, const char * fmt, va_list ap) {