gpt4 book ai didi

linux - 读取 FAT32 文件系统的引导扇区

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:13:41 25 4
gpt4 key购买 nike

我正在编写一个程序,我需要访问引导扇区中有关我挂载的 FAT32 文件系统的一些信息。

这是我所做的,完整的评论。

int main (void) {
unsigned short *i; //2 byte unsigned integer pointer
char tmp[1024]; //buffer
int fd; //file descriptor from opening device
fd = open("/dev/sdf", O_RDONLY); //open the device file
lseek(fd, 14, SEEK_SET); //set offset to 14 (0x0E), i.e. storing "no. of reserved sectors" of the FAT32 system
read(fd, tmp, 2); //read off 2 bytes, "no. of reserved sectors" is represented by 2 bytes
i = &tmp; //point j at those 2 bytes
printf("*j: %d\n", *j); //print *j out
close(fd); //close device
return 0;
}

*i的输出是38,这是废话。我用 mkfs.vfat 格式化了文件系统。我将“保留扇区数”设置为 32。

我尝试过的:

  • i = (unsigned short *) &tmp,进行强制转换,这消除了我编译时的警告,但没有帮助

  • read(fd, tmp, 512),将整个引导扇区(512 字节)加载到 tmp,然后从缓冲区读取,但没有帮助,结果仍然是 38。

    <
  • 摆弄偏移量,即将 14 更改为 13 或 15,以防我弄错索引。它分别打印出 13 的 9744 和 15 的 512,所以不起作用。

我不确定我的做法是否正确。有人可以指出我正确的方向吗?

提前致谢

费拉斯廷。

最佳答案

尝试运行:

$ dd if=/dev/sdf of=/tmp/x.bin bs=512 count=1

然后:

$ hd /tmp/x.bin

或者

$ od -tx2 /tmp/x.bin

并发布第一行。

您的 fattools 可能会添加 6 个额外的保留扇区。然后他们在显示数据之前减去它们。

关于linux - 读取 FAT32 文件系统的引导扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8588332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com