diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-02-16 20:45:56 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-02-16 20:45:56 +0000 |
commit | dbf7f51cf26b75c5aa4fc7c5aa39535bfc4fec48 (patch) | |
tree | fdd7d0372b4b69f2e8097d062371a0aa835005d1 /firmware/drivers/fat.c | |
parent | 1c6b2513ea0114150447824df45e566d87fd06d9 (diff) | |
download | rockbox-dbf7f51cf26b75c5aa4fc7c5aa39535bfc4fec48.tar.gz rockbox-dbf7f51cf26b75c5aa4fc7c5aa39535bfc4fec48.zip |
Preserve the longname extension as much as possible for shortname creation. Randomise the last 4 chars of the name part instead, but only if there is a clash.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5988 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/fat.c')
-rw-r--r-- | firmware/drivers/fat.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 743e841646..b3da25cc4d 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -234,6 +234,7 @@ static int flush_fat(IF_MV_NONVOID(struct bpb* fat_bpb)); | |||
234 | static int bpb_is_sane(IF_MV_NONVOID(struct bpb* fat_bpb)); | 234 | static int bpb_is_sane(IF_MV_NONVOID(struct bpb* fat_bpb)); |
235 | static void *cache_fat_sector(IF_MV2(struct bpb* fat_bpb,) long secnum, bool dirty); | 235 | static void *cache_fat_sector(IF_MV2(struct bpb* fat_bpb,) long secnum, bool dirty); |
236 | static int create_dos_name(const unsigned char *name, unsigned char *newname); | 236 | static int create_dos_name(const unsigned char *name, unsigned char *newname); |
237 | static void randomize_dos_name(unsigned char *name); | ||
237 | static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,) unsigned long start); | 238 | static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,) unsigned long start); |
238 | static int transfer(IF_MV2(struct bpb* fat_bpb,) unsigned long start, long count, char* buf, bool write ); | 239 | static int transfer(IF_MV2(struct bpb* fat_bpb,) unsigned long start, long count, char* buf, bool write ); |
239 | 240 | ||
@@ -1335,7 +1336,7 @@ static int add_dir_entry(struct fat_dir* dir, | |||
1335 | /* check that our intended shortname doesn't already exist */ | 1336 | /* check that our intended shortname doesn't already exist */ |
1336 | if (!strncmp(shortname, buf + i * DIR_ENTRY_SIZE, 12)) { | 1337 | if (!strncmp(shortname, buf + i * DIR_ENTRY_SIZE, 12)) { |
1337 | /* filename exists already. make a new one */ | 1338 | /* filename exists already. make a new one */ |
1338 | snprintf(shortname+8, 4, "%03X", (unsigned)rand() & 0xfff); | 1339 | randomize_dos_name(shortname); |
1339 | LDEBUGF("Duplicate shortname, changing to %s\n", | 1340 | LDEBUGF("Duplicate shortname, changing to %s\n", |
1340 | shortname); | 1341 | shortname); |
1341 | 1342 | ||
@@ -1464,24 +1465,51 @@ unsigned char char2dos(unsigned char c) | |||
1464 | 1465 | ||
1465 | static int create_dos_name(const unsigned char *name, unsigned char *newname) | 1466 | static int create_dos_name(const unsigned char *name, unsigned char *newname) |
1466 | { | 1467 | { |
1467 | int i,j; | 1468 | int i; |
1469 | unsigned char *ext; | ||
1470 | |||
1471 | /* Find extension part */ | ||
1472 | ext = strrchr(name, '.'); | ||
1473 | if (ext == name) /* handle .dotnames */ | ||
1474 | ext = NULL; | ||
1468 | 1475 | ||
1469 | /* Name part */ | 1476 | /* Name part */ |
1470 | for (i=0, j=0; name[i] && (j < 8); i++) | 1477 | for (i = 0; *name && (!ext || name < ext) && (i < 8); name++) |
1471 | { | 1478 | { |
1472 | unsigned char c = char2dos(name[i]); | 1479 | unsigned char c = char2dos(*name); |
1473 | if (c) | 1480 | if (c) |
1474 | newname[j++] = toupper(c); | 1481 | newname[i++] = toupper(c); |
1475 | } | 1482 | } |
1476 | while (j < 8) | ||
1477 | newname[j++] = ' '; | ||
1478 | 1483 | ||
1479 | /* Extension part */ | 1484 | /* Pad both name and extension */ |
1480 | snprintf(newname+8, 4, "%03X", (unsigned)rand() & 0xfff); | 1485 | while (i < 11) |
1486 | newname[i++] = ' '; | ||
1481 | 1487 | ||
1488 | if (ext) | ||
1489 | { /* Extension part */ | ||
1490 | ext++; | ||
1491 | for (i = 8; *ext && (i < 11); ext++) | ||
1492 | { | ||
1493 | unsigned char c = char2dos(*ext); | ||
1494 | if (c) | ||
1495 | newname[i++] = toupper(c); | ||
1496 | } | ||
1497 | } | ||
1482 | return 0; | 1498 | return 0; |
1483 | } | 1499 | } |
1484 | 1500 | ||
1501 | static void randomize_dos_name(unsigned char *name) | ||
1502 | { | ||
1503 | int i; | ||
1504 | unsigned char buf[5]; | ||
1505 | |||
1506 | snprintf(buf, sizeof buf, "%04x", (unsigned)rand() & 0xffff); | ||
1507 | |||
1508 | for (i = 0; (i < 4) && (name[i] != ' '); i++); | ||
1509 | /* account for possible shortname length < 4 */ | ||
1510 | memcpy(&name[i], buf, 4); | ||
1511 | } | ||
1512 | |||
1485 | static int update_short_entry( struct fat_file* file, long size, int attr ) | 1513 | static int update_short_entry( struct fat_file* file, long size, int attr ) |
1486 | { | 1514 | { |
1487 | unsigned char buf[SECTOR_SIZE]; | 1515 | unsigned char buf[SECTOR_SIZE]; |