資源簡介
模擬文件系統的c語言實現,操作系統課程設計必備
模擬文件系統的c語言實現,操作系統課程設計必備
代碼片段和文件信息
#include?“stdio.h“?
#include??
#include??
#include?
#include?
#define?blen?10//塊大小?
#define?max?100//空間大小(物理塊數)?
#define?filemax?100//文件最大長度
???
struct?command//命令?
{
?char?com[10];
}cmd[22];
struct?blo//物理塊?
{
???????int?n;//塊號?
???????char?c[blen];//物理塊大小?
???????struct?blo?*next;//下一個物理塊?
}tblock[max];
typedef?struct?blo?*block;
struct?file//文件
{
??char?filename[20];
??int??length;
?//?char?quan;//權限控制?a組?可讀可寫,b組可讀不可寫?
??struct?blo?*first;//文件的第一個物理塊???
??struct?file?*next;//同目錄下的下一個文件?
};
struct?dir//文件夾
{
??char?dirname[20];
??struct?dir?*same;//同一級目錄?
??struct?dir?*next;//下一級目錄
??struct?file?*firstfile;//該目錄下的第一個文件?
};????
struct?user
{
int?quan;
???????char?username[20];
???struct?user?*next;
?};
?
struct?list//文件路徑儲存
{
struct?dir?*cur;
struct?list?*next;
};
struct?blo?idle;//空閑表?表頭?
struct?dir?root;//根目錄?
struct?dir?*cur_dir;?//當前目錄?
struct?list?head;
struct?user?first;
int?symbol=0;
void?format()???//格式化
{
?????int?i;
?????for(i=0;i ?????{
?????????tblock[1].n=i;
????????
????????tblock[i].next=&tblock[i+1];??????????????
??????}
?????tblock[max-1].next=NULL;
?????idle.next=&tblock[0];
?????strcpy(root.dirname“root“);
?????root.same=NULL;
?????root.next=NULL;
?????root.firstfile=NULL;
?????cur_dir=&root;
?head.cur=&root;
?head.next=NULL;
?first.quan=2;
?first.next=NULL;
?strcpy(first.username“admin“);
?symbol=0;
?????printf(“初始化完畢\n“);
?????printf(“進入文件模擬系統......\n\n“);
?????
?????
?}
?
?
void?read_system(FILE?*fp)???//讀出系統文件的信息
{
?????
?????}?
?????
?????
char*?read_file(char?filename[]int?q)//讀出文件內容
?{
struct?file?*tem=cur_dir->firstfile;
block?tem1;
char?tem2[filemax];
tem2[0]=‘\0‘;
int?i=0;
while(tem!=NULL)
{
if(strcmp(tem->filenamefilename)==0)
{
tem1=tem->first;
if(q==1)
{
printf(“%s文件內容為:“filename);
}
????? while(tem1!=NULL)
{
// strcpy(tem2tem1->c);
// printf(“%s“tem2);
strcat(tem2tem1->c);
if(q==1)
{
printf(“%s“tem1->c);
}
tem1=tem1->next;
i=i+10;
tem2[i]=‘\0‘;
}
if(q==1)
{
printf(“\n“);
}
return?tem2;
}
tem=tem->next;
}
if(q==1)
{
printf(“沒有該文件,請檢查后重新輸入。\n“);
}
return?NULL;
?}
?????
?????
void?write_system(FILE?*fp)?//讀出系統文件的信息
?{
??????
??}
??
void?callback(int?length)????//回收磁盤空間
?{
?????
?????}
?????
void?allot(int?length)?????//分配空間
{
?????
?????}?
?????
?????
?????
?????
?????
void?create_file(char?filename[]char?con[]int?q)?//創建文件
{
?????
?????int?len=strlen(con)/blen+1;
?int?n=0;
?block?tem1=&idle;
?struct?file?*newf=(file?*)malloc(sizeof(file));
?struct?file?*tem=cur_dir->firstfile;
?while(tem!=NULL)
?{
?if(strcmp(tem->filenamefilename)==0)
?{
?printf(“該文件已存在,請檢查后重新輸入。\n“);
?return;
?}
?tem=tem->next;
?}
?tem=cur_dir->firs
評論
共有 條評論