資源簡介
模擬一個簡單二級文件管理系統
設計目的:通過具體的文件存儲空間的管理、文件的物理結構、目錄結構和文件操作的實現,加深對文件系統內部功能和實現過程的理解。
設計內容:模擬一個簡單二級文件管理系統

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#define?MaxUser?100??????????//定義最大MDF主目錄文件
#define?MaxDisk?512*1024?????//模擬最大磁盤空間
#define?commandAmount?12?????//對文件操作的指令數
//存儲空間管理有關結構體和變量
char?disk[MaxDisk];?????//模擬512K的磁盤存儲空間
typedef?struct?distTable??//磁盤塊結構體
{
int?maxlength;
int?start;
int?useFlag;
distTable?*next;
}diskNode;
diskNode?*diskHead;
struct?fileTable????//文件塊結構體
{
char?fileName[10];
int?strat;??????????//文件在磁盤存儲空間的起始地址
int?length;?????????//文件內容長度
int?maxlength;??????//文件的最大長度
char?fileKind[3];???//文件的屬性——讀寫方式
struct?tm?*timeinfo;
bool?openFlag;???????//判斷是否有進程打開了該文件
//fileTable?*next;
};
//兩級目錄結構體
typedef?struct?user_file_directory??//用戶文件目錄文件UFD
{
//char?fileName[10];
fileTable?*file;
user_file_directory?*next;
}UFD;
//UFD?*headFile;
typedef?struct?master_file_directory??//主文件目錄MFD
{
char?userName[10];
char?password[10];
UFD?*user;
}MFD;
MFD?userTable[MaxUser];
int?used=0;?????????????????????????????//定義MFD目錄中用已有的用戶數
//文件管理
void?fileCreate(char?fileName[]int?lengthchar?fileKind[]);????????//創建文件
void?fileWrite(char?fileName[]);????????????????????//寫文件
void?fileCat(char?fileName[]);????????????????????//讀文件
void?fileRen(char?fileName[]char?rename[]);????????//重命名文件
void?fileFine(char?fileName[]);???????????????????//查詢文件
void?fileDir(char?UserName[]);????????????????????//顯示某一用戶的所有文件
void?fileClose(char?fileName[]);??????????????????//關閉已打開的文件
void?fileDel(char?fileName[]);????????????????????//刪除文件
void?chmod(char?fileName[]char?kind[]);?????????//修改文件的讀寫方式
int?requestDist(int?&startPostionint?maxLength);?//磁盤分配查詢
void?initDisk();??????????????????????????????????//初始化磁盤
void?freeDisk(int?startPostion);??????????????????//磁盤空間釋放
void?diskShow();??????????????????????????????????//顯示磁盤使用情況
//用戶管理
void?userCreate();
int?login();
int?userID=-1;???//用戶登錄的ID號,值為-1時表示沒有用戶登錄
int?main()
{
char?order[commandAmount][10];
strcpy(order[0]“create“);
strcpy(order[1]“rm“);
strcpy(order[2]“cat“);
strcpy(order[3]“write“);
strcpy(order[4]“fine“);
strcpy(order[5]“chmod“);
strcpy(order[6]“ren“);
strcpy(order[7]“dir“);
strcpy(order[8]“close“);
strcpy(order[9]“return“);
strcpy(order[10]“exit“);
strcpy(order[11]“df“);
char?command[50]command_str1[10]command_str2[10]command_str3[5]command_str4[3];
int?ikj;
int?length;
initDisk();?????????????????????//初始化磁盤
for(i=0;i {
userTable[i].user=(UFD?*)malloc(sizeof(UFD));
userTable[i].user->next=NULL;
}
while(1)
{
printf(“********************************************\n“);
printf(“??????????????????1、Creat?user\n“);
printf(“??????????????????2、login\n“);
printf(“********************************************\n“);
printf(“Please?chooce?the?function?key:>“);
int?choice;
scanf(“%d“&choice);
if(choice==1)?userCreate();
else?if(choice==2)?u
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????16129??2010-04-21?16:15??二級文件管理系統\c.cpp
?????文件???????4235??2010-04-17?20:24??二級文件管理系統\cc.dsp
?????文件????????510??2010-04-17?18:46??二級文件管理系統\cc.dsw
?????文件??????58368??2010-04-21?16:15??二級文件管理系統\cc.ncb
?????文件??????48640??2010-04-21?16:15??二級文件管理系統\cc.opt
?????文件????????619??2010-04-21?16:15??二級文件管理系統\cc.plg
?????文件??????41757??2010-04-21?16:15??二級文件管理系統\Debug\c.obj
?????文件?????237620??2010-04-21?16:15??二級文件管理系統\Debug\cc.exe
?????文件?????301836??2010-04-21?16:15??二級文件管理系統\Debug\cc.ilk
?????文件?????238940??2010-04-19?21:50??二級文件管理系統\Debug\cc.pch
?????文件?????582656??2010-04-21?16:15??二級文件管理系統\Debug\cc.pdb
?????文件??????41984??2010-04-21?16:15??二級文件管理系統\Debug\vc60.idb
?????文件??????53248??2010-04-21?16:15??二級文件管理系統\Debug\vc60.pdb
?????目錄??????????0??2010-04-21?16:15??二級文件管理系統\Debug
?????目錄??????????0??2010-04-21?16:15??二級文件管理系統
-----------?---------??----------?-----??----
??????????????1626542????????????????????15
- 上一篇:《C程序設計語言》第二版 中文高清非掃描pdf
- 下一篇:航空無線電導航
評論
共有 條評論