


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、計算機(jī)操作系統(tǒng)課程設(shè)計班級:計091-1姓名:學(xué)號:使用語言:C+指導(dǎo)老師: 學(xué)院:、系統(tǒng)要求1、實驗?zāi)康耐ㄟ^一個簡單多用戶文件系統(tǒng)的設(shè)計,加深理解文件系統(tǒng)的內(nèi)部功能及內(nèi)部實現(xiàn)。2、實驗內(nèi)容為linux系統(tǒng)設(shè)計一個簡單的二級文件系統(tǒng)。要求做到以下幾點:(1)可以實現(xiàn)下列幾條命令(至少4條);logi n用戶登陸dir列文件目錄create創(chuàng)建文件delete刪除文件ope n打開文件close關(guān)閉文件read讀文件write寫文件(2)列目錄時要列出文件名、物理地址、保護(hù)碼和文件長度;(3)源文件可以進(jìn)行讀寫保護(hù)。.二、系統(tǒng)分析1、設(shè)計思想本文件為二級文件系統(tǒng),即要實現(xiàn)對文件的增刪改查,同時又
2、具備登陸系統(tǒng)、 注冊用戶的功能,各個用戶之間的文件系統(tǒng)互不干擾。本文件系統(tǒng)采用兩級目錄,其中第一級對應(yīng)于用戶賬號,第二級對應(yīng)于用戶 帳號下的文件。另外,為了簡便文件系統(tǒng)未考慮文件共享, 文件系統(tǒng)安全以及管 道文件與設(shè)備文件等特殊內(nèi)容。系統(tǒng)采用結(jié)構(gòu)體來存儲用戶、文件目錄、文件數(shù)據(jù)內(nèi)容:048*548*5+44*5048*5+44*50+264*200用戶區(qū)文件目錄區(qū)文件數(shù)據(jù)區(qū)每個分區(qū)都是由結(jié)構(gòu)體組成,每個個去的結(jié)構(gòu)體的個數(shù)由格式化系統(tǒng)是決定。整個系統(tǒng)的編碼構(gòu)成主要分為:51 Workspace 1 project -file files-Source Files 關(guān) mymain,cpp 團(tuán) m
3、ysys,cpp =t:l myus&riiile_cpp- 3 Header Files XI allstruct.li 司 mysysh 荀 myuserfile.h _| Resource FilesAllstruct.h定義了每個分區(qū)的結(jié)構(gòu)體;Mysys.h聲明了對系統(tǒng)操作的各種方法;Myuserfile.h聲明了對文件操作的各種方法;Myma in .cpp整個系統(tǒng)的主函數(shù),操作入口;Mysys.cpp 包含了 mysys.h,實現(xiàn)了操作系統(tǒng)的各種方法;Myuserfile.cpp 包含了 myuserfile.h ,實現(xiàn)了操作文件的各種方法;2、主要數(shù)據(jù)結(jié)構(gòu)Allstruc
4、t.h struct s_userlong isuse; char n ame20; char psd20; long address;struct s_listlong isuse; char n ame20;long myaddress;文件的內(nèi)容:用戶區(qū)結(jié)構(gòu)體/是否使用用戶名/密碼/目錄地址目錄結(jié)構(gòu)體/是否使用文件名字/本條目錄地址long poi ntaddress; /指向的文件的地址 long isfile;/ 是否鎖定long poi ntsize; /目標(biāo)文件的大小long nextaddress; /下條目錄的地址 ;struct s file/文件結(jié)構(gòu)體long isuse
5、;/是否使用char conten t256; /文件內(nèi)容 long next;/下個文件塊地址;系統(tǒng)執(zhí)行創(chuàng)建分區(qū),1、如果首次進(jìn)入系統(tǒng),還沒有文件系統(tǒng),則會提示格式化文件系統(tǒng), 并初始化分區(qū):2、剛初始化后,沒有用戶,提示創(chuàng)建用戶:區(qū)図酸融嚴(yán)葩耶3屈司曙卸罟莪;濟(jì)帑慾總.、蔗辭細(xì)boh3、用戶創(chuàng)建成功后出現(xiàn)對系統(tǒng)操作的菜單4、注冊用戶功能:請輸入新用戶的用戶名!Arinin 惰輸入密碼123 情再次輸入密碼;M23展入存儲* “*制建用戶威功。5、用戶登錄,登錄成功后顯示當(dāng)前用戶下的所有文件及其詳細(xì)信息,同時顯示 對文件操作的菜單:請輸入用戶名=請輸入密碼L23登陸成功!歡迎您典目錄為空I容
6、 態(tài)程 -內(nèi) 狀出 擇4ULUL定退 選文文文文鎖. 的盲建除改否銷 您查新刪修是注 kw 12 3 4-506新注冊的用戶默認(rèn)為沒有文件,選擇創(chuàng)建文件,并且每次對文件操作后顯示 當(dāng)前用戶的所有文件和操作菜單:請輸入文件名£字母和數(shù)字"最多仞個字符九aa文件由多少個字符沖組成?(必須小于冇冏個字符128文件是否鎖定了 y鎖定/ 2或其他自由諫寫當(dāng)前目錄下的文件;劉牟名XJOEXKXJCKEJC大小是否鎖定物理地址aa129V24407、此次新建的文件為鎖定狀態(tài),不能被刪除:8、對文件查看,默認(rèn)創(chuàng)建的時候用 0填充文件內(nèi)容:縮入要查看的文件的名韋(僅限當(dāng)前目議aa000000
7、90000000000000000000000000000000000000000000000000000000000000«MHO0009U0SO0000U0SO0000000000000000000000B00006t)反件查看成功!當(dāng)前目錄下的文件;爻件名大小是否鎖定物理她址aa128V2440liiEHUitMEHiaMEiiEHUitMEHMiMEiiEHUitMEHMiiMXXiMaiiEiOiMiiMXXlrfaiiEiOiMiiMXXlrfaiiEiOiMiiMXXlrfaiiEiOiMiiMXXlrfiiiEiOiMiiMXXlrfiiiE 斗9、修改文件內(nèi)容:摩詡
8、BBE勢觀巒廚輻曾營舸整酬亙廊期U入內(nèi)容; dfsafsrsdfs<ifsafsafsdfsafsafsar 工件修改成功I課I錄下的班大小 是否鎖定128 ¥物理地址24010、對文件的鎖定進(jìn)行裝換:11、刪除文件:"的文件創(chuàng)建目錄為空!12、注銷登錄退出系統(tǒng):四、功能實現(xiàn)Mysys.h#i nclude <stdio.h>#i nclude "myuserfile.h" class MSysterm封裝了管理系統(tǒng)的方法/成員變量private:FILE *myfile;MUser myuser;/成員函數(shù)public:MSyster
9、m()void outName();/打印登陸后的用戶名int cheack();檢查虛擬文件系統(tǒng)跟是否存在int myformat();/初始化虛擬磁盤int createuser(); / 創(chuàng)建用戶int log in();/ 用戶登錄void mymai n();/主控制程序int logout();/ 用戶注銷;Myuserfile.h#in clude <stdio.h>/封裝了管理文件的方法/用戶名/密碼/目錄地址/此用戶的地址class MUser/成員變量 public:FILE *myfile; char n ame20; char psd20; long lis
10、taddress; long myaddress;private:long lastaddress;/成員函數(shù)/最后一個目錄的地址public:int createFile();增加文件int delFile(char filename20); 刪除文件int revampFile(char filename20); 修改文件in t mydir();列出當(dāng)前目錄的所有文件(夾)int viewFile(char filename20); 查看文件int myConversion(char filename20); 轉(zhuǎn)換是否鎖定狀態(tài)private:int isSame(char filenam
11、e_f20,char filename_s20);Mymain.cpp#i nclude <stdio.h> #in clude <iostream> #in clude "mysys.h" #i nclude <limits> using n amespace std;int mai n() char nod1;int n_ select = 2 , i_1 =0; MSysterm mysys;/*文件不存在的程序入口*/if(mysys.cheack()=-1) 磁盤空間不存在cout<<"虛擬磁盤文件不存在,
12、是否生成?Y/N "<<e ndl;cin»no d1;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流if(n od1='Y'| nod1='y')cout<<"正在創(chuàng)建。"<<endl;if(mysys.myformat()!=1)/ 創(chuàng)建磁盤空間cout<<"創(chuàng)建磁盤空間失??!即將退出。"<<e ndl;
13、cin»no d1;return 2;cout<<"創(chuàng)建完成!是否創(chuàng)建用戶?Y/N "<<endl;cin»no d1;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'in'); /清空輸入流if(no d1='Y'| nod1='y')if(mysys.createuser()=1)/ 倉U建用戶cout<<"創(chuàng)建用戶成功。"<<e ndl;
14、elsecout<<"創(chuàng)建用戶失??!即將退出。"<<e ndl;return 3;elsecout<<"匿名用戶無法進(jìn)入系統(tǒng),正在退出。"<<endl;return 4;elsecout<<"程序已結(jié)束!按任意鍵退出。"<<endl; return 1;/*文件存在的程序入口*/for (;)cout<<"*"<<e ndl;cout<<"請選擇:"<<e ndl;cout&l
15、t;<" 1.登錄"<<endl<<"2.注冊"<<endl<<"3.退出"<<endl;cout<<"*"<<e ndl;ci n»n_ select;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流if (n_select = 1)-for (in t i_1= 0;i_1<
16、;=3;i_1+) 登錄if (mysys.logi n()=1) cout<<"登陸成功!歡迎您 "mysys.outName();break;else cout<<"用戶名不存在或密碼錯誤!"<<e ndl;if (i_仁=4)-cout<<"非法用戶!"<<endl<<"輸入任意鍵退出。"<<endl;cin»no d1;return 5;break;if (n_select = 2)-if(mysys.create
17、user()=1) 倉U建用戶cout<<"創(chuàng)建用戶成功。"<<e ndl;elsecout<<"創(chuàng)建用戶失?。?quot;<<e ndl;if (n_select = 3)-return 6; mysys.myma in(); return 0;Mysys.cpp#in elude "mysys.h"#in elude "allstruct.h"#in elude <iostream>#i nclude <stdio.h>#include <li
18、mits>用于清除殘留的輸入流 using n amespace std;int MSysterm:cheack()檢查虛擬空間是否存在 myfile=fope n( "test1.txt","r"); if(myfile=NULL)return -1;/返回-1,代表文件不存在fclose(myfile);return 1;int MSysterm:myformat()int i =1;myfile=fope n("test1.txt","w"); if(myfile=NULL)return -1; s_u
19、ser ms_user;ms_user.isuse=0;s_list ms_list;ms_list.isuse=0;s_file ms_file;ms_file.isuse=0;for (i =1 ; i<=5 ; i+)用戶區(qū)格式化if(fwrite(&ms_user,sizeof(ms_user),1,myfile)!=1) - -cout<<"用戶格式信息寫入失?。?quot;<<endl;fclose(myfile);return -2;for (i = 1; i<=50 ;i+)if(fwrite(&ms_list,si
20、zeof(ms_list),1,myfile)!=1)目錄區(qū)格式化 - -cout<<"目錄格式信息寫入失?。?quot;<<endl;fclose(myfile);return -3;for (i=0;i<=199;i+)if(fwrite(&m s_file,sizeof(ms_file),1,myfile)!=1)/數(shù)據(jù)區(qū)格式化 - -cout<<"數(shù)據(jù)格式信息寫入失?。?quot;<<e ndl;fclose(myfile);return -4;fclose(myfile);return 1;int MS
21、ysterm:createuser() 創(chuàng)建用戶s_user ms_user,ms_user2;int nowaddress = 0 ,issame=0 ,m=0 , i =1 ;/記錄當(dāng)前的掃描指針,密碼比對標(biāo)志位,循環(huán)使用的變量cout<<"正在檢查用戶空間是否足夠。"<<endl;myfile=fope n( "test1.txt","r");for (i=1;i<=5;i+,fseek(myfile,44,1), nowaddress+)檢查用戶空間是否足夠if (fread(&m s_u
22、ser2.isuse,4,1,myfile)=0) -cout<<"讀取用戶空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_user2.isuse=0)-break;if (i=6)cout<<"用戶空間已滿!創(chuàng)建用戶失敗"<<endl;return -2;for (;)cout<<"請輸入新用戶的用戶名:"<<e ndl;cin>> ms_user. name;cin.clea
23、r(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流fseek(myfile,O,O);for (i=1;i<=5;i+) 檢查用戶名if (fread(&ms_user2.isuse,4,1,myfile)=0 )/ 找到被使用的用戶區(qū),下一步讀取名cout<<"讀取用戶空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_user2.isuse=0)-
24、fseek(myfile,44,1);elseif (fread(&ms_,20,1,myfile)=0) 讀取用戶區(qū)的名字 -"<<e ndl;cout<<"讀取用戶空間失敗,虛擬磁盤格式錯誤,可能已被損壞fclose(myfile);return -1;for (m =0 ;m<=19;m+)if (ms_user. namem != ms_user2. namem)- -issame = 0;break;elseissame = 1;if (ms_user. namem = '0')-break
25、;if (issame = 1)cout<<"用戶名重復(fù)!請重新輸入:"<<e ndl;break;fseek(myfile,24,1);if (i>=6)for (;)/輸入密碼cout<<"請輸入密碼,最多19位。"<<endl;cin»m s_user.psd;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'in'); /清空輸入流 cout<<"請再
26、次輸入密碼:"<<e ndl;cin»m s_user2.psd;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流for (m =0 ;m<=19;m+)if (ms_user.psdm != ms_user2.psdm)- - issame = 0;cout<<"兩次密碼不匹配"<<' '<<ms_user.psd<<" &qu
27、ot;<<ms_user2.psd<<" "<<m<<e ndl;break;elseissame = 1;if (ms_user.psdm = '0')-break;if (issame = 1)break;cout<<"進(jìn)入存儲。"<<endl;ms_user.isuse =1;/空間使用置為使用(1);ms_user.address = 0;/默認(rèn)不存在目錄fclose(myfile);myfile=fope n( "test1.txt",&
28、quot;r+");fseek(myfile,48* no waddress,0);if(fwrite(&m s_user,sizeof(ms_user),1,myfile) = 0) - - cout<<"寫入用戶信息失??!"<<e ndl;elsebreak;fclose(myfile);return 1;int MSysterm:login()/ 用戶登錄s_user ms_user,ms_user2;int issame = 0, m = 0 , i =0 ;/比較標(biāo)記,循環(huán)使用的變量cout<<"請輸
29、入用戶名:"<<e ndl;cin»m s_user. name;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'in'); /清空輸入流myfile=fope n( "test1.txt","r"); for (i = 1;i<=5;i+)if (fread(&ms_user2.isuse,4,1,myfile)=0) 讀取被使用的用戶區(qū) -cout<<"讀取用戶空間失敗,
30、虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_user2.isuse=0)-fseek(myfile,44,1);con ti nue;elseif (fread(&ms_,20,1,myfile)=0) 讀取名字 -cout<<"讀取用戶空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;for (m =0 ;m<=19;m+)if (ms_user. namem != m
31、s_user2. namem)- -issame = 0;break;else issame = 1;if (ms_user. namem = '0')-break;if (issame = 1)if (fread(&ms_user2.psd,20,1,myfile)=0) 讀取密碼 -cout<<"讀取密碼失?。〈疟P錯誤。 "<<e ndl; fclose(myfile);return -1;for (int k=0;k<=2;k+)cout<<"請輸入密碼:"<<e ndl
32、;cin»m s_user.psd;清空輸入流cin.clear(); /清除流的錯誤標(biāo)記cin.ign ore( nu meric_limits<streamsize>:max(),'n'); / for (m =0 ;m<=19;m+)if (ms_user.psdm != ms_user2.psdm)- -issame = 0;break;elseissame = 1;if (ms_user.psdm = '0') -break;if (issame = 0)cout<<"密碼錯誤,請重新輸入。"
33、<<e ndl;elseif (fread(&ms_user2.address,4,1,myfile)=0) 讀取目錄地址 - cout<<"讀取目錄失??!磁盤錯誤。"<<e ndl;fclose(myfile);return -1;for (m=0;m<=19;m+) 對對象 myuser 賦值 myuser. namem = ms_user2 .n amem; myuser.psdm = ms_user2.psdm; - myuser.listaddress = ms_user2.address; myuser.myad
34、dress = (i-1)*48;fclose(myfile);return 1;/返回登錄成功 fclose(myfile); return -2;/密碼錯誤 fseek(myfile,24,1);fclose(myfile);return -1;void MSysterm:mymain() 主控制程序int m_point=9,myget=0;記錄使用第幾層控制臺,接收函數(shù)返回值char m_name120,m _n ame220;for (;)if(m_poi nt= 0)-myget=logout();break;cout<<e ndlvv"*"<
35、<e ndl;coutvv"當(dāng)前目錄下的文件:"<<e ndl;myget = myuser.mydir();*"<<e ndl;cout<<"*"<<e ndl;cout<<"請輸入您的選擇:"<<e ndl;cout<<"1.查看文件內(nèi)容"<<endl;cout<<"2.新建文件"<<endl;cout<<"3.刪除文件"&l
36、t;<endl;cout<<"4.修改文件"<<endl;cout<<"5.是否鎖定狀態(tài)轉(zhuǎn)換"<<endl;cout<<"0.注銷,退出程序"<<endl;cout<<"*"<<e ndl;cin>> m_po int;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流s
37、witch (m_po int) -case 1:if (myuser.listaddress = 0)cout<<"您還沒有創(chuàng)建文件!"<<e ndl;break;cout<<"請輸入要查看的文件的名字:(僅限當(dāng)前目錄)"<<endl;cin»m_n ame1;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'in'); /清空輸入流myget = myuser.viewFile(m
38、_n amel);switch (myget)case 1: cout<<"文件查看成功!"<<e ndl;break;case -1: cout<<"磁盤打開失?。?quot;<<e ndl;break;case -2:cout<<"文件不存在! "<<e ndl; break;default: break; break;/case 1文件打開case 2:myget = myuser.createFile();switch (myget)case 1:cout<&
39、lt;"創(chuàng)建成功!"<<e ndl;break;case -1:cout<<"磁盤打開失敗!"<<e ndl;break;case -2:cout<<"目錄空間已滿!"<<endl;break;case -3:cout<<"數(shù)據(jù)空間已滿!"<<e ndl;break;case -4:cout<<"文件名已存在!"<<e ndl;break;default:cout<<"
40、;創(chuàng)建文件失敗,原因未知!"<<endl;break;break;/case 2新建文件case 3:if (myuser.listaddress = 0)cout<<"您還沒有創(chuàng)建文件!"<<e ndl;break;cout<<"請輸入要刪除的文件的名字:(僅限當(dāng)前目錄)"<<endl;cin»m_n ame1;cin.clear(); II清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n
41、9;); II清空輸入流myget = myuser.delFile(m_ namel);switch (myget)case 1:cout<<"文件刪除成功!"<<e ndl;break;case -1:cout<<"磁盤打開失??!"<<e ndl;break;case -2:cout<<"文件不存在!"<<e ndl;break;case -4: cout<<"文件鎖定!不能刪除! "<<e ndl; break;d
42、efault: cout<<"未知原因,刪除失??!"<<e ndl;break; break;/case 3刪除文件case 4:if (myuser.listaddress = 0)cout<<"您還沒有創(chuàng)建文件!"<<e ndl;break;cout<<"請輸入要修改的文件的名字:(僅限當(dāng)前目錄)"<<endl;cin»m_n ame1;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<stream
43、size>:max(),'n'); /清空輸入流myget = myuser.revampFile(m_ name1);switch (myget)case 1: cout<<"文件修改成功!"<<e ndl;break;case -1:cout<<"磁盤打開失??!"<<e ndl;break;case -2: cout<<"文件不存在!"<<e ndl;break;case -4:/cout<<"文件鎖定!無法修改!
44、"<<e ndl;break;case -5: cout<<"輸入內(nèi)容過多!無法修改! "<<e ndl; break;default:/cout<<"未知原因,修改失??!"<<e ndl;break; break;/case 4修改文件case 5:if (myuser.listaddress = 0)cout<<"您還沒有創(chuàng)建文件!"<<e ndl;break;cout<<"請輸入要轉(zhuǎn)換是否鎖定的文件的名字:(僅限當(dāng)
45、前目錄)"<<endl;cin»m_n ame1;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流myget = myuser.myC on vers ion(m_n ame1);switch (myget)case 0:cout<<"文件已轉(zhuǎn)換為鎖定! "<<e ndl; break;case 1:cout<<"文件已轉(zhuǎn)換為 自由讀寫!"<<
46、;e ndl;break;case -1:cout<<"磁盤打開失??!"<<e ndl;break;case -2:cout<<"文件不存在!"<<e ndl;break;default:cout<<"未知原因,修改失??!"<<e ndl;break;break;/case 5轉(zhuǎn)換是否鎖定狀態(tài)default:break;/switch int MSysterm:logout() 用戶注銷char word20 = '0'for (int i = 0
47、 ; i<=19 ; i+)myuser. namei = wordi; myuser.psdi = wordi; fclose(myfile);cout<<"已注銷! "<<endl;return 1;void MSysterm:outName()打印登陸后的用戶名 cout<<myuser. name<<e ndl;Myuserfile.cpp#in clude <iostream>#i nclude <stdio.h>#i nclude <ioma nip>#include &l
48、t;limits>用于清除殘留的輸入流#i nclude "myuserfile.h"#in clude "allstruct.h"using n amespace std;int MUser:createFile() 增加文件s_list ms_list;s_file ms_file;long nowaddress =0 ,f_address10, num_char = 0 ;/目錄循環(huán)記錄變量,數(shù)據(jù)塊地址變量 組,字符個數(shù)(文件大小)int f_ad_num = 0 , myerr = 0 ,i = 1; /寫入的塊數(shù),是否在最終寫入時失敗(失
49、敗置1)char f_n ame20 = ' ',m='0',e='0',f_islock;long oldastaddress = lastaddress ;上一個目錄地址(用于出錯回滾)myfile=fope n( "test1.txt","r+");if (myfile = NULL)cout<<"讀取磁盤失??!"<<e ndl;fclose(myfile);return -1;fseek(myfile,48*5,0);文件指針跳到目錄區(qū)for (i=1;i
50、<=50;i+,fseek(myfile,40,1), no waddress+) 檢查目錄空間是否足夠if (fread(&ms_list.isuse,4,1,myfile)=0) 讀取是否使用 -cout<<"讀取目錄空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_list.isuse=0)如果讀取到未使用則跳出檢測-break;if (i=51)cout<<"目錄空間已滿!創(chuàng)建文件失敗"<<endl;fclose(
51、myfile);return -2;fseek(myfile,48*5+44*50,0); 文件指針跳到數(shù)據(jù)區(qū)for (i=1;i<=200;i+,fseek(myfile,260,1)檢查數(shù)據(jù)空間是否足夠(初步檢查)if (fread(&m s_file.isuse,4,1,myfile)=0) 讀取是否使用 -cout<<"讀取數(shù)據(jù)空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_file.isuse=O)如果有空白的數(shù)據(jù)塊則跳出-break;if (i=201
52、)cout<<"數(shù)據(jù)空間已滿!創(chuàng)建文件失敗"<<e ndl;fclose(myfile);return -2;cout<<"請輸入文件名(字母和數(shù)字,最多19個字符):"<<endl;cin»f_n ame;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流fseek(myfile,48*5,0);文件指針跳到目錄區(qū)for (i=1;i<=50;i+)檢查文件
53、名是否被使用if (fread(&ms_list,sizeof(ms_list),1,myfile)=0)讀取目錄 - -cout<<"讀取目錄空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_list.isuse = 1)/如果讀取到未使用則跳出檢測-if( isSame(f_ name,msist .n ame) = 1) - -fclose(myfile);return -4;for (;)cout<<"文件由多少個字符m組成?(必須小于255
54、0個字符)"<<endl;cin»nu m_char;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'n'); /清空輸入流if (num _char <= 2550)-break; cout<<"文件長度必須小于 2550個字符。"<<endl;ms_list.poi ntsize = nu m_char;cout<<"文件是否鎖定? y鎖定/ n(或其他)自由讀寫"
55、<<endl;確定是否鎖定cin>> f_islock;cin.clear(); /清除流的錯誤標(biāo)記cin.ignore(numeric_limits<streamsize>:max(),'in'); /清空輸入流if( f_islock = 'y' | f_islock = 'Y')- -msist.isfile = 0;-elsems_list.isfile =1;-fseek(myfile,48*5+44*50,0); 文件指針跳到數(shù)據(jù)區(qū)for ( i=0 ; i<=199 && f
56、_ad_ num <=( num_char/255); i+ , fseek(myfile,260,1) )/檢查數(shù)據(jù)空間是否足夠-if (fread(&m s_file.isuse,4,1,myfile)=0) -cout<<"讀取數(shù)據(jù)空間失敗,虛擬磁盤格式錯誤,可能已被損壞"<<e ndl;fclose(myfile);return -1;if (ms_file.isuse=0)/ 如果有空白區(qū)塊-f_addressf_ad_ num = i*264+48*5+44*50;記錄下當(dāng)前空白區(qū)塊的絕對物理地址-f_ad_num+;先用后
57、加if (f_ad_num <= (num_char/255) 空白的地址不足- -cout<<"沒有足夠的磁盤空間,創(chuàng)建失??!"<<e ndl;fclose(myfile);return -3;ms_file.isuse = 1;int k = 0;/for循環(huán)變量for (i=0 ; i<f_ad_ num ; i+) -if ( i < (f_ad_num-1) )/對下個數(shù)據(jù)塊進(jìn)行鏈接ms_file .n ext = f_addressi+1;elsems_file .n ext = 0;-fseek(myfile,f_ad
58、dressi,O); 跳轉(zhuǎn)到空白數(shù)據(jù)塊if ( num_char > 255)/數(shù)據(jù)太多,一個區(qū)塊放不了if ( fwrite(&m s_file.isuse,4,1,myfile) = 0)/寫入已被使用 -cout<<"數(shù)據(jù)模塊寫入isuse失敗"<<e ndl;myerr = 1;for ( k =1 ; k <=255 ; k+)/ 寫入數(shù)據(jù)if ( fwrite(&m,1,1,myfile) =0)cout<<"數(shù)據(jù)模塊寫入內(nèi)容失敗"<<endl;myerr = 1;i
59、f ( fwrite( &e,1,1,myfile) = 0)/ 寫入結(jié)束符cout<<"數(shù)據(jù)模塊寫入結(jié)束符失敗"<<endl;myerr = 1;if ( fwrite(&m s_file. next,4,1,myfile) = 0)/寫入下個數(shù)據(jù)塊地址 -cout<<"數(shù)據(jù)模塊寫入 next失敗"<<endl;myerr = 1;nu m_char-=255; -else/數(shù)據(jù)小于一個區(qū)塊的大小if ( fwrite(&m s_file.isuse,4,1,myfile) = 0)/區(qū)塊置為已使用 -cout<<"數(shù)據(jù)模塊寫入isuse失敗"<<e ndl;myerr = 1;for ( k =1 ; k <=nu m_char ; k+) -if ( fwrite(&m,1,1,myfile) =0)cout<<"數(shù)據(jù)模塊寫入內(nèi)容失敗"<<endl;myerr = 1;for (k =1 ; k<= (256-n um_char);k+) 寫入數(shù)據(jù) -if ( fwrite( &e,1,1,myfile) = 0)cout&l
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 電蒸鍋買賣合同5篇
- 11《牛郎織女(二)》教學(xué)設(shè)計-2024-2025學(xué)年五年級上冊語文統(tǒng)編版
- 2025年OXONE過硫酸氫鉀項目投資可行性研究分析報告
- 人教版2025-2026學(xué)年一年級數(shù)學(xué)下冊教學(xué)工作計劃(含進(jìn)度表)
- 城市休閑公園建筑設(shè)計與綠化布局
- 蠶絲(教學(xué)設(shè)計)-2023-2024學(xué)年數(shù)學(xué)四年級下冊北師大版
- 2025終止合同協(xié)議書:二零二五年度終止虛擬現(xiàn)實教育平臺合作
- 二零二五年度節(jié)慶活動搭建安全規(guī)范與責(zé)任書合同
- 5景區(qū)設(shè)施居間服務(wù)合同
- 小學(xué)一年級數(shù)學(xué)兩位數(shù)加減一位數(shù)評價試題訓(xùn)練題大全附答案
- 《簡易方程》集體備課
- (完整文本版)小學(xué)英語音標(biāo)測試100題
- 醫(yī)院電梯安全操作培訓(xùn)記錄
- 《統(tǒng)計分析與SPSS的應(yīng)用(第7版)》課件全套 第1-12章 SPSS統(tǒng)計分析軟件概述
- 黑龍江省哈爾濱市2022-2023學(xué)年八年級上學(xué)期期末數(shù)學(xué)試題(含答案)
- 建筑施工安全管理及揚塵治理檢查投標(biāo)方案(技術(shù)方案)
- 《小學(xué)生數(shù)學(xué)提問能力培養(yǎng)策略研究國內(nèi)外文獻(xiàn)綜述》3600字
- 中專數(shù)學(xué)(基礎(chǔ)模塊)上冊課件
- 智慧農(nóng)業(yè)整體解決方案
- 總經(jīng)理權(quán)責(zé)授權(quán)書
- 家具廠規(guī)章制度
評論
0/150
提交評論