Chameleon

Chameleon Commit Details

Date:2010-08-23 06:07:30 (10 years 3 months ago)
Author:Daniel Miranda
Commit:424
Parents: 423
Message:Reworked UUID/label matching; Fixed NTFSGetUUID return value.
Changes:
M/branches/danielkza/i386/libsa/string.c
M/branches/danielkza/i386/libsaio/sys.c
M/branches/danielkza/i386/libsaio/disk.h
M/branches/danielkza/i386/libsa/libsa.h
M/branches/danielkza/i386/libsaio/disk.c
M/branches/danielkza/i386/libsaio/ntfs.c

File differences

branches/danielkza/i386/libsaio/ntfs.c
297297
298298
299299
300
301
302300
303301
304302
......
324322
325323
326324
327
328
325
326
329327
328
329
330330
331331
332332
long NTFSGetUUID(CICell ih, char *uuidStr)
{
bool NTFSProbe(const void*);
struct bootfile *boot;
void *buf = malloc(MAX_BLOCK_SIZE);
if ( !buf )
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);
}
branches/danielkza/i386/libsaio/sys.c
827827
828828
829829
830
831
832
833
834
830
831
832
833
834
835
836
837
838
839
840
841
842
843
835844
836845
846
837847
838848
839849
* 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);
}
branches/danielkza/i386/libsaio/disk.c
16001600
16011601
16021602
1603
1603
16041604
1605
1606
1605
1606
1607
1608
1609
1610
1611
1612
1613
16071614
16081615
16091616
......
16851692
16861693
16871694
1688
1695
16891696
16901697
1691
1692
16931698
16941699
16951700
16961701
1697
1698
1702
16991703
1700
1704
17011705
1702
1703
1704
1705
1706
1707
1708
1706
1707
1708
17091709
1710
17111710
1712
1711
17131712
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1713
1714
17291715
17301716
17311717
17321718
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1719
1720
1721
1722
1723
1724
1725
17591726
17601727
1761
1762
1728
1729
1730
1731
1732
1733
17631734
1764
1765
1766
1767
1735
17681736
17691737
17701738
......
17721740
17731741
17741742
1775
1776
1777
1743
1744
1745
1746
17781747
1779
1780
1748
1749
17811750
1782
1783
1784
1785
1786
1787
1788
1751
1752
1753
17891754
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1755
1756
18001757
18011758
1802
1803
1804
1805
1759
1760
18061761
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
18271773
18281774
1829
1775
18301776
18311777
18321778
......
18551801
18561802
18571803
1858
18591804
18601805
18611806
/* 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 );
}
/*
//==========================================================================
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;
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;
}
/* 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
}
branches/danielkza/i386/libsaio/disk.h
99
1010
1111
12
12
1313
1414
#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 */
branches/danielkza/i386/libsa/libsa.h
107107
108108
109109
110
111
112
110113
111114
112115
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 );
/*
branches/danielkza/i386/libsa/string.c
257257
258258
259259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
260316
261317
262318
}
#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 )
{

Archive Download the corresponding diff file

Revision: 424