




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、中北大學(xué)操作系統(tǒng)課程設(shè)計說 明 書學(xué) 院、系:軟件學(xué)院專 業(yè):軟件工程學(xué) 生 姓 名:xxx學(xué) 號:xxx設(shè) 計 題 目:模擬文件系統(tǒng)的設(shè)計與實現(xiàn)起 迄 日 期:2015年12月28日- 2016年1月8日指 導(dǎo) 教 師:xxx 2016 年1月8日2 / 241 需求分析 通過模擬文件系統(tǒng)的實現(xiàn),深入理解操作系統(tǒng)中文件系統(tǒng)的理論知識, 加深對教材中的重要算法的理解。同時通過編程實現(xiàn)這些算法,更好地掌握操作系統(tǒng)的原理及實現(xiàn)方法,提高綜合運(yùn)用各專業(yè)課知識的能力;掌握操作系統(tǒng)結(jié)構(gòu)、實現(xiàn)機(jī)理和各種典型算法,系統(tǒng)地了解操作系統(tǒng)的設(shè)計和實現(xiàn)思路,并了解操作系統(tǒng)的發(fā)展動向和趨勢。 模擬二級文件管理系統(tǒng)的課
2、程設(shè)計目的是通過研究Linux的文件系統(tǒng)結(jié)構(gòu),模擬設(shè)計一個簡單的二級文件系統(tǒng),第一級為主目錄文件,第二級為用戶文件。2 總體設(shè)計 結(jié)合數(shù)據(jù)結(jié)構(gòu)、程序設(shè)計、計算機(jī)原理等課程的知識,設(shè)計一個二級文件系統(tǒng),進(jìn)一步理解操作系統(tǒng)。文件的創(chuàng)建: create 文件關(guān)閉:close 文件的打開:open文件的讀:read 文件的寫:write 文件關(guān)閉:close刪除文件:delete 創(chuàng)建子目錄:mkdir 刪除子目錄:rmdir列出文件目錄:dir 退出:exit開 始系統(tǒng)執(zhí)行流程圖選擇操作創(chuàng)建文件刪除文件讀文件寫文件創(chuàng)建文件夾刪除文件夾刪除子目錄顯示當(dāng)前子目錄創(chuàng)建子目錄更改目錄 退出退出3 詳細(xì)設(shè)計主
3、要數(shù)據(jù)結(jié)構(gòu):#define MEM_D_SIZE 1024*1024 /總磁盤空間為1M#define DISKSIZE 1024/磁盤塊的大小1K#define DISK_NUM 1024/磁盤塊數(shù)目1K#define FATSIZE DISK_NUM*sizeof(struct fatitem)/FAT表大小#define ROOT_DISK_NO FATSIZE/DISKSIZE+1/根目錄起始盤塊號#define ROOT_DISK_SIZE sizeof(struct direct)/根目錄大小#define DIR_MAXSIZE 1024/路徑最大長度為1KB#define MS
4、D 5/最大子目錄數(shù)5#define MOFN 5/最大文件深度為5#define MAX_WRITE 1024*128/最大寫入文字長度128KB struct fatitem /* size 8*/ int item; /*存放文件下一個磁盤的指針*/ char em_disk; /*磁盤塊是否空閑標(biāo)志位 0 空閑*/ ; struct direct /*-文件控制快信息-*/ struct FCB char name9; /*文件/目錄名 8位*/ char property; /*屬性 1位目錄 0位普通文件*/ int size; /*文件/目錄字節(jié)數(shù)、盤塊數(shù))*/ int firs
5、tdisk; /*文件/目錄 起始盤塊號*/ int next; /*子目錄起始盤塊號*/ int sign; /*1是根目錄 0不是根目錄*/ directitemMSD+2; ; struct opentable struct openttableitem char name9; /*文件名*/ int firstdisk; /*起始盤塊號*/ int size; /*文件的大小*/ openitemMOFN; int cur_size; /*當(dāng)前打文件的數(shù)目*/ ; 管理文件的主要代碼:int create(char *name) int i,j; if(strlen(name)8) /
6、*文件名大于 8位*/ return(-1); for(j=2;,name) break; if(jMSD+2) /*文件已經(jīng)存在*/ return(-4); for(i=2;idirectitemi.firstdisk=-1) break; if(i=MSD+2) /*無空目錄項*/ return(-2); if(u_opentable.cur_size=MOFN) /*打開文件太多*/ return(-3); for(j=ROOT_DISK_NO+1;j=DISK_NUM) return(-5); fatj.em_disk = 1; /*將空閑塊置為已經(jīng)分
7、配*/ /*-填寫目錄項-*/ strcpy(cur_,name); cur_dir-directitemi.firstdisk = j; cur_dir-directitemi.size = 0; cur_dir-directitemi.next = j; cur_perty = 0; /*-*/ fd = open(name); return 0; int open(char *name) int i, j; for(i=2;,name) break; if(i=MSD+2) r
8、eturn(-1); /*-是文件還是目錄-*/ if(cur_perty=1)return(-4); /*-文件是否打開-*/ for(j=0;jMOFN;j+) if(!strcmp(u_,name) break; if(j=MOFN) /*文件打開太多*/ return(-3); /*-查找一個空閑用戶打開表項-*/ for(j=0;jdirectitemi.firstdisk; strcpy(u_,name); u_opentable.openitemj
9、.size = cur_dir-directitemi.size; u_opentable.cur_size+; /*-返回用戶打開表表項的序號-*/ return(j); int close(char *name) int i; for(i=0;i=MOFN) return(-1); /*-清空該文件的用戶打開表項的內(nèi)容-*/ strcpy(u_,); u_opentable.openitemi.firstdisk = -1; u_opentable.openitemi.size = 0; u_opentable.cur_size-; retu
10、rn 0; int write(int fd, char *buf, int len) char *first; int item, i, j, k; int ilen1, ilen2, modlen, temp; /*-用 $ 字符作為空格 # 字符作為換行符-*/ char Space = 32; char Endter= n; for(i=0;ilen;i+) if(bufi = $) bufi = Space; else if(bufi = #) bufi = Endter; /*-讀取用戶打開表對應(yīng)表項第一個盤塊號-*/ item = u_opentable.openitemfd.f
11、irstdisk; /*-找到當(dāng)前目錄所對應(yīng)表項的序號-*/ for(i=2;idirectitemi.firstdisk=item) break; temp = i; /*-存放當(dāng)前目錄項的下標(biāo)-*/ /*-找到的item 是該文件的最后一塊磁盤塊-*/ while(fatitem.item!=-1) item =fatitem.item; /*-查找該文件的下一盤塊-*/ /*-計算出該文件的最末地址-*/ first = fdisk+item*DISKSIZE+u_opentable.openitemfd.size%DISKSIZE; /*-如果最后磁盤塊剩余的大小大于要寫入的文件的大小
12、-*/ if(DISKSIZE-u_opentable.openitemfd.size%DISKSIZElen) strcpy(first,buf); u_opentable.openitemfd.size = u_opentable.openitemfd.size+len; cur_dir-directitemtemp.size = cur_dir-directitemtemp.size+len; else for(i=0;i0) ilen2 = ilen2+1; /*-還需要多少塊磁盤塊-*/ for(j=0;jilen2;j+) for(i=ROOT_DISK_NO+1;i=DISK_N
13、UM) /*-如果磁盤塊已經(jīng)分配完了-*/ return(-1); first = fdisk+i*DISKSIZE; /*-找到的那塊空閑磁盤塊的起始地址-*/ if(j=ilen2-1) /*-如果是最后要分配的一塊-*/ for(k=0;klen-(DISKSIZE-u_opentable.openitemfd.size%DISKSIZE)-j*DISKSIZE;k+) firstk = bufk; else/*-如果不是要最后分配的一塊-*/ for(k=0;kdirectitemtemp.size = cur_dir-directitemtemp.size+len; return 0
14、; int read(int fd, char *buf) int len = u_opentable.openitemfd.size; char *first; int i, j, item; int ilen1, modlen; item = u_opentable.openitemfd.firstdisk; ilen1 = len/DISKSIZE; modlen = len%DISKSIZE; if(modlen!=0) ilen1 = ilen1+1; /*-計算文件所占磁盤的塊數(shù)-*/ first = fdisk+item*DISKSIZE; /*-計算文件的起始位置-*/ for
15、(i=0;iilen1;i+) if(i=ilen1-1) /*-如果在最后一個磁盤塊-*/ for(j=0;jlen-i*DISKSIZE;j+) bufi*DISKSIZE+j = firstj; else /*-不在最后一塊磁盤塊-*/ for(j=0;jlen-i*DISKSIZE;j+) bufi*DISKSIZE+j = firstj; item = fatitem.item; /*-查找下一盤塊-*/ first = fdisk+item*DISKSIZE; return 0; int del(char *name) int i,cur_item,item,temp; for(i
16、=2;,name) break; cur_item = i; /*-用來保存目錄項的序號,供釋放目錄中-*/ if(i=MSD+2) /*-如果不在當(dāng)前目錄中-*/ return(-1); if(cur_dir-directitemcur_perty!=0) /*-如果刪除的(不)是目錄-*/ return(-3); for(i=0;idirectitemcur_item.firstdisk;/*-該文件的起始盤塊號-*/ while(item!=-1) /*-釋放空間,將FAT表對應(yīng)項進(jìn)行修改-*/ temp = fatitem.item;
17、fatitem.item = -1; fatitem.em_disk = 0; item = temp; /*-釋放目錄項-*/ cur_dir-directitemcur_item.sign = 0; cur_dir-directitemcur_item.firstdisk = -1; strcpy(u_opentable.openitemcur_,); cur_dir-directitemcur_item.next = -1; cur_dir-directitemcur_perty = 0; cur_dir-directitemcur_item.size
18、= 0; return 0; 主函數(shù):int main() FILE *fp; char ch; char a100; char code1110; char name10; int i,flag,r_size; char *contect; contect = (char *)malloc(MAX_WRITE*sizeof(char); if(fp=fopen(disk.dat,rb)=NULL) printf(You have not format,Do you want format?(y/n); scanf(%c,&ch); if(ch=y) initfile(); printf(Su
19、ccessfully format! n); else return 0; enter();print(); show(); strcpy(code0,exit); strcpy(code1,create); strcpy(code2,open); strcpy(code3,close); strcpy(code4,write); strcpy(code5,read); strcpy(code6,del); strcpy(code7,mkdir); strcpy(code8,rmdir); strcpy(code9,dir); strcpy(code10,cd); while(1) scanf
20、(%s,a); for(i=0;i11;i+) if(!strcmp(codei,a) break; switch(i) case 0: /退出文件系統(tǒng)free(contect); halt(); return 0; case 1: /創(chuàng)建文件scanf(%s,name); flag = create(name); if(flag=-1) printf(Error: n The length is too long !n); else if(flag=-2) printf(Error: n The direct item is already full !n); else if(flag=-3
21、) printf(Error: n The number of openfile is too much !n); else if(flag=-4) printf(Error: n The name is already in the direct !n); else if(flag=-5) printf(Error: n The disk space is full!n); else printf(Successfully create a file! n); show(); break; case 2:/打開文件scanf(%s,name); fd = open(name); if(fd
22、= -1) printf(Error: n The open file not exit! n); else if(fd = -2) printf(Error: n The file have already opened! n); else if(fd = -3) printf(Error: n The number of open file is too much! n); else if(fd = -4) printf(Error: n It is a direct,can not open for read or write! n); else printf(Successfully
23、opened! n); show(); break; case 3:/關(guān)閉文件 scanf(%s,name); flag = close(name); if(flag = -1) printf(Error:n The file is not opened ! n); else printf(Successfully closed! n); show(); break; case 4:/寫文件if(fd =-1) printf(Error:n The file is not opened ! n); else printf(Please input the file contect:); scanf(%s,contect); flag=write(fd,contect,strlen(contect); if(flag = 0) printf(Successfully write! n); else printf(Error:n The disk size is not enough! n); show(); break; case 5:/讀文件if(fd =-1) printf(Err
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工作場所的學(xué)習(xí)動機(jī)與工作效率關(guān)系研究
- 企業(yè)智能化管理系統(tǒng)的構(gòu)建與實踐
- 智慧城市的社會治理與創(chuàng)新
- 家庭教育中心理激勵方法探討
- 提升在線教學(xué)質(zhì)量實操與策略研究
- 19-木皮藍(lán)變?有沒有辦法提前預(yù)防富深一個解決方案
- 全球視野下的葡萄酒產(chǎn)區(qū)特色:2025年品牌國際化路徑研究報告
- 公交優(yōu)先發(fā)展戰(zhàn)略背景下2025年城市交通擁堵治理路徑探索報告
- Chitosan-Cy7-5-MW-100000-生命科學(xué)試劑-MCE
- 北京市昌平二中學(xué)南校區(qū)2024年化學(xué)九年級第一學(xué)期期末質(zhì)量跟蹤監(jiān)視試題含解析
- 投資公司項目考核與激勵制度
- 注安2024注冊安全工程師【法規(guī)】核心母題600題
- 臨近既有線施工方案
- 藥材基原鑒定技術(shù)-洞察分析
- 《文化人類學(xué)的方法》課件
- UL498標(biāo)準(zhǔn)中文版-2019插頭插座UL標(biāo)準(zhǔn)中文版
- 初中心理課職業(yè)生涯規(guī)劃:我的未來我做主
- 糖尿病合并肺結(jié)核
- 平安車輛保險合同電子版
- 天皰瘡護(hù)理個案分享
- 律師事務(wù)所日常管理制度模版(3篇)
評論
0/150
提交評論