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

Function ntfs_get_volume_name

src/ntfs.c:332–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332static void ntfs_get_volume_name(disk_t *disk_car, partition_t *partition, const struct ntfs_boot_sector*ntfs_header)
333{
334 unsigned char *buffer;
335 uint64_t mft_pos;
336 unsigned int mft_record_size;
337 partition->fsname[0]='\0';
338 if(ntfs_header->clusters_per_mft_record>0)
339 mft_record_size=ntfs_header->clusters_per_mft_record * ntfs_header->sectors_per_cluster * ntfs_sector_size(ntfs_header);
340 else
341 mft_record_size=1<<(-ntfs_header->clusters_per_mft_record);
342 mft_pos=partition->part_offset+(uint64_t)(le16(ntfs_header->reserved)+le64(ntfs_header->mft_lcn)*ntfs_header->sectors_per_cluster)*ntfs_sector_size(ntfs_header);
343 /* Record 3 = $Volume */
344 mft_pos+=3*mft_record_size;
345#ifdef NTFS_DEBUG
346 log_info("NTFS MFT cluster = %lu\n",le64(ntfs_header->mft_lcn));
347 log_info("NTFS cluster size = %5u sectors\n",ntfs_header->sectors_per_cluster);
348 log_info("NTFS MFT_record_size = %5u bytes\n",mft_record_size);
349 log_info("NTFS sector size = %5u bytes\n", ntfs_sector_size(ntfs_header));
350#endif
351 if(mft_record_size < 42)
352 {
353 log_error("Invalid MFT record size or NTFS sector size\n");
354 return;
355 }
356 buffer=(unsigned char *)MALLOC(mft_record_size);
357 if((unsigned)disk_car->pread(disk_car, buffer, mft_record_size, mft_pos) != mft_record_size)
358 {
359 log_error("NTFS: Can't read MFT\n");
360 free(buffer);
361 return;
362 }
363 {
364 const ntfs_attribresident *attrib=(const ntfs_attribresident *)ntfs_findattribute((const ntfs_recordheader*)buffer, 0x60, (char*)buffer+mft_record_size);
365 if(attrib && attrib->header.bNonResident==0) /* attribute is resident */
366 {
367 char *dest;
368 const char *name_it;
369 unsigned int volume_name_length=le32(attrib->cbAttribData);
370 volume_name_length/=2; /* Unicode */
371 if(volume_name_length>sizeof(partition->fsname)-1)
372 volume_name_length=sizeof(partition->fsname)-1;
373 name_it=ntfs_getattributedata(attrib, (char*)(buffer+mft_record_size));
374 if(name_it==NULL)
375 {
376 free(buffer);
377 return;
378 }
379 for(dest=partition->fsname;
380 volume_name_length>0 && *name_it!='\0' && name_it[1]=='\0';
381 name_it+=2,volume_name_length--)
382 *dest++=*name_it;
383 *dest='\0'; /* 27 january 2003: Correct a bug found by Andreas du Plessis-Denz */
384 }
385 }
386 free(buffer);
387 return;
388}
389

Callers 1

set_NTFS_infoFunction · 0.85

Calls 4

ntfs_sector_sizeFunction · 0.85
MALLOCFunction · 0.85
ntfs_findattributeFunction · 0.85
ntfs_getattributedataFunction · 0.85

Tested by

no test coverage detected