c - 如何解析原始 "disk"数据?

标签 c filesystems fat32 fat

下面的输出属于 FAT32 磁盘文件。我想用 C 程序显示所有文件以及每个文件相应分配的扇区。

按照指南我什至无法找到根目录。 (示例1 - 在http://www.tavi.co.uk/phobos/fat.html中找到根目录)看起来0x16和0x17都是00。所以它们没有指向任何东西?

我一遍又一遍地阅读该文档,我已经筋疲力尽了。有人可以解释我做错了什么,或者如何通过简单的步骤做到这一点?

感谢任何帮助!谢谢。

替代资源:http://wiki.osdev.org/FAT#FAT_32_2

0000000: eb58 906d 6b66 732e 6661 7400 0201 2000  .X.mkfs.fat... .
0000010: 0200 0000 00f8 0000 2000 4000 0000 0000  ........ .@.....
0000020: 400d 0300 0306 0000 0000 0000 0200 0000  @...............
0000030: 0100 0600 0000 0000 0000 0000 0000 0000  ................
0000040: 8000 29c8 a726 5e4e 4f20 4e41 4d45 2020  ..)..&^NO NAME  
0000050: 2020 4641 5433 3220 2020 0e1f be77 7cac    FAT32   ...w|.
0000060: 22c0 740b 56b4 0ebb 0700 cd10 5eeb f032  ".t.V.......^..2
0000070: e4cd 16cd 19eb fe54 6869 7320 6973 206e  .......This is n
0000080: 6f74 2061 2062 6f6f 7461 626c 6520 6469  ot a bootable di
0000090: 736b 2e20 2050 6c65 6173 6520 696e 7365  sk.  Please inse
00000a0: 7274 2061 2062 6f6f 7461 626c 6520 666c  rt a bootable fl
00000b0: 6f70 7079 2061 6e64 0d0a 7072 6573 7320  oppy and..press 
00000c0: 616e 7920 6b65 7920 746f 2074 7279 2061  any key to try a
00000d0: 6761 696e 202e 2e2e 200d 0a00 0000 0000  gain ... .......
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000140: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000150: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000160: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000170: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000180: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000190: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.
0000200: 5252 6141 0000 0000 0000 0000 0000 0000  RRaA............
0000210: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000220: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000230: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000240: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000250: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000260: 0000 0000 0000 0000 0000 0000 0000 0000  ................
....

我用这些来创建文件:

dd if=/dev/zero of=disk.img bs=1k count=100000
losetup /dev/loop0 disk.img
mkdosfs -s 1 -F 32 /dev/loop0 100000

最佳答案

I'm unable to even find the root directory by following the guide. (Example 1 - find the root directory in http://www.tavi.co.uk/phobos/fat.html) It seems 0x16 and 0x17 are 00. So they don't point to anything?

上述文档讨论的是 FAT16,因此它不适用于您的 FAT32 文件系统;引用Alternative resource相反。
据此,FAT 的扇区大小位于偏移量 36(= 0x24,从标准引导记录的开头算起),长度为 4(以字节为单位);在 C 中,您可以使用 e 访问它(假设有一个 unsigned char *FAT32fs 指向引导记录,并且您位于小端系统上)。克。

#include <stdint.h>
    uint32_t FATsectors = *(uint32_t *)&FAT32fs[36];

在示例文件中,此大小为 0x00000603 (= 1539)。

关于c - 如何解析原始 "disk"数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30239448/

相关文章:

c - 函数定义中的指针与数组 : what is the difference between void fct1(int *p) and void fct1(int p[])?

embedded - 对于ARM7-TDMI来说,什么是好的FAT文件系统

c - 如何从引导扇区识别 FAT16 或 FAT32

python - 在python中从脂肪图像中提取文件

docker - Alpine Linux - root 安装为 ro iso9660 文件系统 如何重新安装为 rw 覆盖层?

java - 如何获取 Spring REST 文件下载以返回 404?

c - 循环中的 malloc()/free()

c - 客户端如何使用套接字同时发送和接收消息?

c - 如何读取指针式 watch 的时间?

linux - 网络 block 设备 - 某些读取请求失败 - 内核 OOPS