【问题标题】:OS development: Implementing FAT12 Write FunctionOS开发:实现FAT12写入功能
【发布时间】:2014-08-12 09:44:03
【问题描述】:

所以我在操作系统开发方面很新,现在我正在编写我的 FAT12 文件系统代码。我使用 FDC 代码完成了对软盘的所有写入操作,但我似乎无法理解在将文件写入磁盘时应该如何进行。

我知道我的根目录在哪里以及所有相关信息,但是我应该如何寻找正确的扇区来写入我的文件?之后,我应该如何将该条目添加到 FAT 中?

这是我用来遍历根目录并找到文件的代码:

FILE fsysFatDirectory (const char* DirectoryName) {

        FILE file;
    unsigned char* buf;
    PDIRECTORY directory;

    //! get 8.3 directory name
    char DosFileName[11];
    ToDosFileName (DirectoryName, DosFileName, 11);
    DosFileName[11]=0;

    //! 14 sectors per directory
    int sector;
    for (sector=0; sector<14; sector++) {

        //! read in sector of root directory
        buf = (unsigned char*) flpydsk_read_sector (_MountInfo.rootOffset + sector );

        //! get directory info
        directory = (PDIRECTORY) buf;

        //! 16 entries per sector
        int i;
        for (i=0; i<16; i++) {

            //! get current filename
            char name[11];
            kmemcpy (name, directory->Filename, 11);
            name[11]=0;

            //! find a match?
            if (kstrcmp (DosFileName, name) == 0) {

                //! found it, set up file info
                kstrcpy (file.name, DirectoryName);
                file.id             = 0;
                file.currentCluster = directory->FirstCluster;
                file.fileLength     = directory->FileSize;
                file.eof            = 0;
                file.fileLength     = directory->FileSize;

                //! set file type
                if (directory->Attrib == 0x10)
                    file.flags = FS_DIRECTORY;
                else
                    file.flags = FS_FILE;

                //! return file
                return file;
            }

            //! go to next directory
            directory++;
        }
    }

    //! unable to find file
    file.flags = FS_INVALID;
    return file;
    }

我打算写一些类似的东西并遍历根目录,逐个条目,直到找到一个位置。至于添加/遍历 FAT,我知道每个条目代表一个集群(条目 1 = 集群 1)。但我不知道我是否应该遍历 FAT 而不是根目录或两者兼而有之。

我的大部分代码都基于本教程:http://www.brokenthorn.com/Resources/OSDev22.html 但他从未添加过创建/写入文件位,所以我自己做。

感谢任何帮助。

【问题讨论】:

  • 更新:我刚刚意识到我从未真正将 FAT 表写入磁盘...如何手动将表写入磁盘映像?

标签: operating-system filesystems fwrite fat


【解决方案1】:

我能想到的一种实现是使用树状结构,其中根目录是父目录。

struct fat_component{
    fat_component *parent;
    /*other fat components here*/
};

一旦我们有了它,我们就可以调用类似 inline 汇编调用 int 13h/AH=03 之类的东西。我不太熟悉,但这里有一个链接:http://stanislavs.org/helppc/int_13-3.html

inline_asm("mov ah, 03h");
inline_asm("mov ch, %s", fc->cylindernum);
inline_asm("mov cl, %s", fc->sectornum);
/*other int13h initializations here*/
inline_asm ("int 13h");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2023-01-15
    相关资源
    最近更新 更多