MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / fat32_set_part_name

Function fat32_set_part_name

src/fat.c:83–127  ·  view source on GitHub ↗

@ @ requires \valid(disk_car); @ requires valid_disk(disk_car); @ requires \valid(partition); @ requires valid_partition(partition); @ requires \valid_read(fat_header); @ requires \separated(disk_car, partition, fat_header); @ decreases 0; @*/

Source from the content-addressed store, hash-verified

81 @ decreases 0;
82 @*/
83static int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const struct fat_boot_sector*fat_header)
84{
85 partition->fsname[0]='\0';
86 if((fat_header->sectors_per_cluster>0)&&(fat_header->sectors_per_cluster<=128))
87 {
88 const unsigned int cluster_size=fat_header->sectors_per_cluster*disk_car->sector_size;
89 unsigned char *buffer=(unsigned char*)MALLOC(cluster_size);
90 if((unsigned)disk_car->pread(disk_car, buffer, cluster_size,
91 partition->part_offset + (le16(fat_header->reserved) + fat_header->fats * le32(fat_header->fat32_length) + (uint64_t)(le32(fat_header->root_cluster) - 2) * fat_header->sectors_per_cluster) * disk_car->sector_size) != cluster_size)
92 {
93#ifndef DISABLED_FOR_FRAMAC
94 log_error("fat32_set_part_name() cannot read FAT32 root cluster.\n");
95#endif
96 }
97 else
98 {
99 int i;
100 int stop=0;
101 for(i=0;(i<16*fat_header->sectors_per_cluster)&&(stop==0);i++)
102 { /* Test attribut volume name and check if the volume name is erased or not */
103 if(((buffer[i*0x20+0xB] & ATTR_EXT) !=ATTR_EXT) && ((buffer[i*0x20+0xB] & ATTR_VOLUME) !=0) && (buffer[i*0x20]!=0xE5))
104 {
105 set_part_name_chomp(partition, (const char *)&buffer[i*0x20],11);
106 if(check_VFAT_volume_name(partition->fsname, 11))
107 partition->fsname[0]='\0';
108 }
109 if(buffer[i*0x20]==0)
110 {
111 stop=1;
112 }
113 }
114 }
115 free(buffer);
116 }
117 if(partition->fsname[0]=='\0')
118 {
119#ifndef DISABLED_FOR_FRAMAC
120 log_info("set_FAT_info: name from BS used\n");
121#endif
122 set_part_name_chomp(partition, (const char*)fat_header + FAT32_PART_NAME, 11);
123 if(check_VFAT_volume_name(partition->fsname, 11))
124 partition->fsname[0]='\0';
125 }
126 return 0;
127}
128
129/*@
130 @ requires \valid(disk_car);

Callers 1

set_FAT_infoFunction · 0.85

Calls 3

MALLOCFunction · 0.85
set_part_name_chompFunction · 0.85
check_VFAT_volume_nameFunction · 0.85

Tested by

no test coverage detected