FAT12文件系统解析,输出其文件目录树

本文介绍了如何解析FAT12文件系统,通过读取软盘镜像文件(img),详细展示了启动扇区的结构,以及如何获取根目录条目。通过C代码实现,解释了如何遍历FAT链表和数据区,输出完整的目录树。
摘要由CSDN通过智能技术生成

近段时间刚做操作系统实验三,解析FAT12文件系统,输出其目录树。

我们可以通过读取一个软盘镜像文件,即img文件。

FAT12文件系统一般是由启动扇区,2个FAT,根目录区,数据区组成。

C代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct Boot//启动扇区 属性
{
  unsigned short int BytePerSec;
  unsigned char SecPerClus;
  unsigned short int ReservedSec;
  unsigned char FatCopy;
  unsigned short int SizeofRootDirectory;
  unsigned short int SizeofSec;
  unsigned short int SecPerFAT;
  unsigned short int SecPerTrack;
 
};

struct Entry//根目录条目 属性
{
  unsigned char FileName[8];
  unsigned char Extension[3];
  unsigned char Attribute;
  unsigned short int FirstCluster;
  unsigned int FileSize;

};

//读取boot
void getBoot(struct Boot* boot,FILE* file);
//读取file,得到根目录描述符以及实际的描述符数目
int getEntry(struct Boot boot,struct Entry* entry,FILE* file);
 //开始输出目录数,若描述符是文件,输出其文件名及后缀名,若是文件夹,则通过查找fat中数据读取DATA区的目录数,递归
void outputTree(unsigned short int* fat,unsigned short int first,FILE *file,struct Boot boot);

void getBoot(struct Boot* boot,FILE* file)
{
     fseek(file,11,0);//定位file内部指向指针,使其跳过前11个byte
     fread(&(boot->BytePerSec),2,1,file);
     fread(&(boot->SecP

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值