因此,我在操作系统开发方面非常新,现在我正在编写我的FAT12文件系统代码。我使用FDC代码完成了对软盘的所有写入,但我似乎无法思考在将文件写入磁盘时应该如何进行。
我知道我的根目录在哪里和它的所有相关信息,但我应该如何寻找正确的扇区写我的文件?在那之后,我该怎么把这个条目添加到脂肪中呢?
这是我用来遍历根目录并找到一个文件的代码:
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,但他从未添加过创建/编写文件位,所以我自己做。
任何帮助都是非常感谢的。
发布于 2014-07-25 08:29:35
我可以想到的一个实现是使用类似树的结构,其中根目录是父目录。
struct fat_component{
fat_component *parent;
/*other fat components here*/
};一旦有了它,我们就可以调用类似于INT13h/AH=03的内联程序集调用。我不太熟悉它,但这里有一个链接: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");https://stackoverflow.com/questions/24347497
复制相似问题