首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取FAT16文件系统

读取FAT16文件系统
EN

Stack Overflow用户
提问于 2015-04-27 18:23:07
回答 1查看 1.8K关注 0票数 1

我试图读取一个FAT16文件系统,以获取有关它的信息,如扇区的数目,集群,字节列表等。

我正试着这样读:

代码语言:javascript
复制
FILE *floppy;
unsigned char bootDisk[512];
floppy = fopen(name, "r");
fread(bootDisk, 1, 512, floppy);

int i;
for (i = 0; i < 80; i++){
    printf("%u,",bootDisk[i]);  
}

它的产出如下:

代码语言:javascript
复制
235,60,144,109,107,100,111,115,102,115,0,0,2,1,1,0,2,224,0,64,11,240,9,0,18,0,2,0,0,0,0,0,0,0,0,0,0,0,41,140,41,7,68,32,32,32,32,32,32,32,32,32,32,32,70,65,84,49,50,32,32,32,14,31,190,91,124,172,34,192,116,11,86,180,14,187,7,0,205,16,

这些数字代表什么?它们是什么类型的?字节?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-27 18:53:53

您没有正确地读取这些值。它们中的大多数都大于1字节。

等级库中可以获得引导扇区中每个属性的长度和含义:

代码语言:javascript
复制
Offset  Size (bytes)    Description
0000h   3 Code to jump to the bootstrap code.
0003h   8 Oem ID - Name of the formatting OS
000Bh   2 Bytes per Sector
000Dh   1 Sectors per Cluster - Usual there is 512 bytes per sector.
000Eh   2 Reserved sectors from the start of the volume.
0010h   1 Number of FAT copies - Usual 2 copies are used to prevent data loss.
0011h   2 Number of possible root entries - 512 entries are recommended.
0013h   2 Small number of sectors - Used when volume size is less than 32 Mb.
0015h   1 Media Descriptor
0016h   2 Sectors per FAT
0018h   2 Sectors per Track
001Ah   2 Number of Heads
001Ch   4 Hidden Sectors
0020h   4 Large number of sectors - Used when volume size is greater than 32 Mb.
0024h   1 Drive Number - Used by some bootstrap code, fx. MS-DOS.
0025h   1 Reserved - Is used by Windows NT to decide if it shall check disk integrity.
0026h   1 Extended Boot Signature - Indicates that the next three fields are available.
0027h   4 Volume Serial Number
002Bh   11 Volume Label - Should be the same as in the root directory.
0036h   8 File System Type - The string should be 'FAT16 '
003Eh   448 Bootstrap code - May schrink in the future.
01FEh   2   Boot sector signature - This is the AA55h signature

您可能应该使用自定义结构来读取引导扇区。

比如:

代码语言:javascript
复制
typedef struct {
unsigned char jmp[3];
char oem[8];
unsigned short sector_size;
unsigned char sectors_per_cluster;
unsigned short reserved_sectors;
unsigned char number_of_fats;
unsigned short root_dir_entries;
[...]
} my_boot_sector;

在你的实现中要记住你的执着和填充规则。这个结构只是一个例子。

如果您需要更多的细节,就是一个彻底的例子。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29903222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档