Better handle FAT filenames

Rename filenames while copying under Dos and Windows
This commit is contained in:
Christophe Grenier 2007-12-06 00:34:10 +01:00
parent f51aa191c2
commit 56e807748e
6 changed files with 66 additions and 80 deletions

View file

@ -49,8 +49,6 @@ int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose, const u
return 1;
}
set_part_name(partition,((const struct disklabel*)buffer)->d_packname,16);
if(check_volume_name(partition->fsname,16))
partition->fsname[0]='\0';
free(buffer);
return 0;
}
@ -154,8 +152,6 @@ int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t
partition->part_size=0;
partition->part_type_i386=P_FREEBSD;
set_part_name(partition,bsd_header->d_packname,16);
if(check_volume_name(partition->fsname,16))
partition->fsname[0]='\0';
partition->info[0]='\0';
return 0;
}
@ -176,8 +172,6 @@ int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t
partition->part_size=0;
partition->part_type_i386=P_OPENBSD;
set_part_name(partition,bsd_header->d_packname,16);
if(check_volume_name(partition->fsname,16))
partition->fsname[0]='\0';
partition->info[0]='\0';
return 0;
}

View file

@ -142,37 +142,6 @@ static unsigned int up2power_aux(const unsigned int number)
return(1+up2power_aux(number/2));
}
int check_volume_name(const char *name,const unsigned int max_size)
{
unsigned int i;
for(i=0;name[i]!='\0' && i<max_size;i++)
{
if((name[i]>=0x6 && name[i]<=0x1f)||
(name[i]>=0x3A && name[i]<=0x3f))
return 1;
switch(name[i])
{
case 0x1:
case 0x2:
case 0x3:
case 0x4:
case 0x22:
case 0x2A:
case 0x2B:
case 0x2C:
/* case 0x2E: Pas sur */
case 0x2F:
case 0x5B:
case 0x5C:
case 0x5D:
case 0x7C:
/* case 'a' ... 'z': */
return 1;
}
}
return 0; /* Ok */
}
void set_part_name(partition_t *partition,const char *src,const int max_size)
{
int i;
@ -184,16 +153,27 @@ void set_part_name(partition_t *partition,const char *src,const int max_size)
static inline unsigned char convert_char(unsigned char car)
{
#ifdef DJGPP
if(car<0x20)
return '_';
switch(car)
{
case ' ':
/* Forbidden */
case '<':
case '>':
case ':':
case '"':
/* case '/': subdirectory */
case '\\':
case '|':
case '?':
case '*':
case '+':
case ',':
case '.':
case '=':
/* Not recommanded */
case '[':
case ']':
case ';':
case ',':
case '+':
case '=':
return '_';
}
/* 'a' */
@ -220,40 +200,30 @@ static inline unsigned char convert_char(unsigned char car)
/* 'y' */
if(car>=253)
return 'y';
/* Chars allowed under msdos, a-z is stored as upercase by the OS itself */
if((car>='A' && car<='Z') || (car>='a' && car<='z')|| (car>='0' && car<='9'))
return car;
#elif defined(__CYGWIN__) || defined(__MINGW32__)
if(car<0x20)
return '_';
switch(car)
{
case '$':
case '%':
case '\'':
case '`':
case '-':
case '@':
case '{':
case '}':
case '~':
case '!':
case '#':
case '(':
case ')':
case '&':
case '_':
case '^':
case ' ':
case '+':
case ',':
case '.':
case '=':
/* Forbidden */
case '<':
case '>':
case ':':
case '"':
/* case '/': subdirectory */
case '\\':
case '|':
case '?':
case '*':
/* Not recommanded */
case '[':
case ']':
case '/': /* without it, no subdirectory */
return car;
case ';':
case ',':
case '+':
case '=':
return '_';
}
if(car>=224)
return car;
return '_';
#endif
return car;
}

View file

@ -354,7 +354,6 @@ char read_key(void);
char test_key(void);
unsigned int up2power(const unsigned int number);
void my_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
int check_volume_name(const char *name,const unsigned int max_size);
void set_part_name(partition_t *partition,const char *src,const int max_size);
int rebuild_FAT_BS(disk_t *disk_car,partition_t *partition, const int verbose, const int dump_ind,const int interface, const unsigned int expert, char**current_cmd);
#ifndef BSD_MAXPARTITIONS

View file

@ -317,7 +317,7 @@ static int set_FAT_info(disk_t *disk_car, const struct fat_boot_sector *fat_head
if(buffer[38]==0x29) /* BS_BootSig */
{
fat_set_part_name(partition,((const unsigned char*)fat_header)+FAT1X_PART_NAME,11);
if(check_volume_name(partition->fsname,11))
if(check_VFAT_volume_name(partition->fsname, 11))
partition->fsname[0]='\0';
}
break;
@ -326,7 +326,7 @@ static int set_FAT_info(disk_t *disk_car, const struct fat_boot_sector *fat_head
if(buffer[38]==0x29) /* BS_BootSig */
{
fat_set_part_name(partition,((const unsigned char*)fat_header)+FAT1X_PART_NAME,11);
if(check_volume_name(partition->fsname,11))
if(check_VFAT_volume_name(partition->fsname, 11))
partition->fsname[0]='\0';
}
break;
@ -929,7 +929,7 @@ int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const struct f
{
/* dump_ncurses(&buffer[i*0x20],0x20); */
fat_set_part_name(partition,&buffer[i*0x20],11);
if(check_volume_name(partition->fsname,11))
if(check_VFAT_volume_name(partition->fsname, 11))
partition->fsname[0]='\0';
}
if(buffer[i*0x20]==0)
@ -944,7 +944,7 @@ int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const struct f
{
log_info("set_FAT_info: name from BS used\n");
fat_set_part_name(partition,((const unsigned char*)fat_header)+FAT32_PART_NAME,11);
if(check_volume_name(partition->fsname,11))
if(check_VFAT_volume_name(partition->fsname, 11))
partition->fsname[0]='\0';
}
return 0;
@ -1207,3 +1207,26 @@ int fat32_free_info(disk_t *disk_car,const partition_t *partition, const unsigne
return 0;
}
int check_VFAT_volume_name(const char *name, const unsigned int max_size)
{
unsigned int i;
for(i=0;name[i]!='\0' && i<max_size;i++)
{
if(name[i] < 0x20)
return 1;
switch(name[i])
{
case '<':
case '>':
case ':':
case '"':
case '/':
case '\\':
case '|':
case '?':
case '*':
return 1;
}
}
return 0; /* Ok */
}

View file

@ -161,4 +161,4 @@ int test_HPFS(disk_t *disk_car,const struct fat_boot_sector *fat_header, partiti
int recover_OS2MB(disk_t *disk_car, const struct fat_boot_sector*fat_header, partition_t *partition, const int verbose, const int dump_ind);
int check_OS2MB(disk_t *disk_car,partition_t *partition, const int verbose);
int test_OS2MB(disk_t *disk_car,const struct fat_boot_sector *fat_header, partition_t *partition,const int verbose, const int dump_ind);
int check_VFAT_volume_name(const char *name, const unsigned int max_size);

View file

@ -1127,7 +1127,7 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
fat_header->fat_length=le16(fat_length);
fat_header->dir_entries[1]=dir_entries>>8;
fat_header->dir_entries[0]=dir_entries;
if(check_volume_name((const char*)&newboot[FAT1X_PART_NAME],11))
if(check_VFAT_volume_name((const char*)&newboot[FAT1X_PART_NAME],11))
newboot[FAT1X_PART_NAME]='\0';
break;
case UP_FAT16:
@ -1143,7 +1143,7 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
fat_header->fat_length=le16(fat_length);
fat_header->dir_entries[1]=dir_entries>>8;
fat_header->dir_entries[0]=dir_entries;
if(check_volume_name((const char*)&newboot[FAT1X_PART_NAME],11))
if(check_VFAT_volume_name((const char*)&newboot[FAT1X_PART_NAME],11))
newboot[FAT1X_PART_NAME]='\0';
break;
case UP_FAT32:
@ -1205,7 +1205,7 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
newboot[2*disk_car->sector_size+0x1FD]=0x00;
newboot[2*disk_car->sector_size+0x1FE]=0x55;
newboot[2*disk_car->sector_size+0x1FF]=0xAA;
if(check_volume_name((const char*)&newboot[FAT32_PART_NAME],11))
if(check_VFAT_volume_name((const char*)&newboot[FAT32_PART_NAME],11))
newboot[FAT32_PART_NAME]='\0';
break;
default: