现在的位置: 首页 > 综合 > 正文

Geek OS 学习之pfat 文件系统

2014年02月14日 ⁄ 综合 ⁄ 共 1268字 ⁄ 字号 评论关闭

GeekOS中的pfat文件系统。

结构如下。

假设建立了一个10M的磁盘文件disk.img

每个block为512B

0 block :引导扇区

1 block~n block: fat表,fat表中每个fat项存储的是一个块号,每个fat项4B,共可索引到0~2^32号块。fat表的大小根据磁盘文件而定,计算方式:(磁盘文件大小/512) * 4,fat表的作用是以链表的方式指示文件的数据块号。

n block~m block: 根目录区,大小根据用户写入的文件数目而定,根目录区中的每个条目指示了文件的信息如文件名,起始块号,文件大小。

m block~10M/512 block:数据区,用于存储文件数据。

主要的两个数据结构。

typedef struct {
    int magic;          /* id to tell the type of filesystem */
    int fileAllocationOffset;   /* where is the file allocation table */        /*fat表在整个磁盘中的偏移, 单位为块*/
    int fileAllocationLength;   /* length of allocation table */                /*fat表的大小,单位为块*/
    int rootDirectoryOffset;    /* offset in sectors of root directory */       /*根目录偏移, 通常在FAT表的后面*/
    int rootDirectoryCount; /* number of items in the directory */              /*根目录中的条目数*/
    short setupStart;       /* first sector of secondary loader */
    short setupSize;        /* size in sectors of secondary loader */
    short kernelStart;      /* first sector of kernel to run */
    short kernelSize;       /* size in sectors of kernel to run */
} bootSector;
                /* 根目录中的条目结构*/
typedef struct {
    char fileName[8+4];     /* 文件名 */
    /* attribute bits */
    char readOnly:1;
    char hidden:1;
    char systemFile:1;
    char volumeLabel:1;
    char directory:1;
    short time;
    short date;
    int firstBlock;     /*  文件的开始簇号 */
    int fileSize;       /* 文件的大小 */
} directoryEntry;

bootSector结构是引导扇区的格式,共28B。

directoryEntry则是根目录区每个条目的结构,每个条目28B。

pfat是一个只读的文件系统,文件在建立文件系统的时候就写进去了。

抱歉!评论已关闭.