Chameleon

Chameleon Commit Details

Date:2010-08-21 21:29:02 (10 years 3 months ago)
Author:Tamás Kosárszky
Commit:416
Parents: 415
Message:Refactored matchVolumeToString(), fixed NTFSGetUUID's return value. Now "Hide Partition" can accept NTFS volume serials as well.
Changes:
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsa/printf.c
M/trunk/i386/libsaio/disk.c
M/trunk/i386/libsaio/ntfs.c

File differences

trunk/i386/libsaio/ntfs.c
297297
298298
299299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331331
332332
333333
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)
trunk/i386/libsaio/disk.c
16851685
16861686
16871687
1688
1688
16891689
1690
1691
1692
1693
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
16941712
1695
1696
1713
1714
16971715
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
17561729
1757
1758
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
17591746
17601747
17611748
//==========================================================================
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 */
trunk/i386/libsa/libsa.h
132132
133133
134134
135
136135
137136
138137
* 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);
/*
trunk/i386/libsa/printf.c
6060
6161
6262
63
64
65
66
67
68
69
70
71
72
73
74
75
76
7763
7864
7965
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)
{

Archive Download the corresponding diff file

Revision: 416