資源簡(jiǎn)介
仿照UNIX操作系統(tǒng)設(shè)計(jì)中文件系統(tǒng)的描述,將一個(gè)文件當(dāng)作一個(gè)磁盤,并在該文件上構(gòu)建一個(gè)完整文件系統(tǒng),支持多級(jí)目錄,支持命令瀏覽文件ls, 切換目錄cd,創(chuàng)建文件create,刪除文件unlink,寫入文件write,讀文件read, 留有更多接口開發(fā)其他的命令,作為學(xué)習(xí)文件系統(tǒng)是一個(gè)不錯(cuò)的例子。
代碼片段和文件信息
#include?“File_System.h“
#include?
static?FILE?*File_System_fp;
static?Surper_Block?Surper_Block_Info;
static?Mem_Inode_P?Mem_Inode_head?Mem_Inode_Tail;
static?int?Indirect_Block_Quantity?=?BLOCK_SIZE?/?sizeof(int);
static?int?Current_Dirent_Inode_Num;
//塊號(hào)轉(zhuǎn)文件偏移量
//入口參數(shù):塊號(hào)
//返回值:文件偏移量
int?Block_Num_to_Offset(int?Block_Num)
{
????unsigned?int?Offset;
????Offset?=?Surper_Block_Info.Start_Block_Offset?+?Block_Num?*?BLOCK_SIZE;
????return?Offset;
}
//結(jié)點(diǎn)號(hào)轉(zhuǎn)文件偏移量
//入口參數(shù):結(jié)點(diǎn)號(hào)
//返回值:文件偏移量
int?Inode_Num_to_Offset(int?Inode_Num)
{
????unsigned?int?Offset;
????int?Disk_Inode_Size?=?sizeof(Disk_Inode);
????Offset?=?Surper_Block_Info.Start_Inode_Offset?+?Inode_Num?*?Disk_Inode_Size;
????return?Offset;
}
//讀取文件塊里所有int數(shù)據(jù)
//入口參數(shù):Block_Num:塊號(hào);?Block_Buf:整型數(shù)組;
//返回
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????568??2018-10-23?20:29??File_System\apue.h
?????文件??????57585??2018-11-15?15:28??File_System\File_System.c
?????文件???????4894??2018-11-11?17:02??File_System\File_System.h
?????文件???????6070??2019-03-14?21:03??File_System\File_System_All.c
?????文件???????1215??2018-11-11?18:06??File_System\File_System_Test.c
?????文件????????119??2019-01-13?11:47??File_System\GccFile_System.sh
?????目錄??????????0??2019-03-14?21:06??File_System
-----------?---------??----------?-----??----
????????????????70451????????????????????7
評(píng)論
共有 條評(píng)論