操作系統(tǒng)實(shí)驗(yàn)文件管理規(guī)定C++代碼_第1頁(yè)
操作系統(tǒng)實(shí)驗(yàn)文件管理規(guī)定C++代碼_第2頁(yè)
操作系統(tǒng)實(shí)驗(yàn)文件管理規(guī)定C++代碼_第3頁(yè)
操作系統(tǒng)實(shí)驗(yàn)文件管理規(guī)定C++代碼_第4頁(yè)
操作系統(tǒng)實(shí)驗(yàn)文件管理規(guī)定C++代碼_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include <>#include <>#include <>#include <>#include<stack>using namespace std;#define BLKSIZE 512.n");printf("WARNING:ALL DATA ON THIS FILESYSTEM WILL BE LOST!n");printf("Proceed with Format(Y/N)");scanf("%c", &choice); getchar();

2、 if(choice = 'y') | (choice = 'Y') if(fp=fopen(image_name, "w+b") = NULL) printf("Can't create file %sn", image_name); exit(-1); for(i = 0; i < BLKSIZE; i+) fputc('0', fp); = 0; strcpy, "/"); = 'd' strcpy, "/"); = 0; = 0;

3、 0 = -1; 1 = -1; fwrite(&inode, sizeof(Inode), 1, fp); = -1; for(i = 0; i < 31; i+) fwrite(&inode, sizeof(Inode), 1, fp); for(i = 0; i < BLKNUM*BLKSIZE; i+) fputc('0', fp); fclose(fp); n", file_name); printf("This filesystem not exist, it will be create!n"); form

4、at(); login(); while(!feof(fp) fread(&user, sizeof(User), 1, fp); n"); flag = 1; fclose(fp); break; if(flag = 0) break;while(flag);n", image_name); exit(-1);num = -1;n"); exit(-1);bitmapi = '1'if(fp=fopen(image_name, "r+b") = NULL) printf("Can't open fil

5、e %sn", image_name); exit(-1);fseek(fp, i, SEEK_SET);fputc('1', fp);fclose(fp);return i;ength;add0 = inode_arraynum.address0;if(len > 512) add1 = inode_arraynum.address1;if(fp = fopen(image_name, "r+b") = NULL) printf("Can't open file %s.n", image_name); exit(

6、-1);fseek(fp, BLKSIZE+INODESIZE*INODENUM +add0*BLKSIZE, SEEK_SET);ch = fgetc(fp);for(i=0; (i < len) && (ch != '0') && (i < 512); i+) tempi = ch; ch = fgetc(fp);if(i >= 512) fseek(fp,BLKSIZE+INODESIZE*INODENUM+add1*BLKSIZE, SEEK_SET); ch = fgetc(fp); for(; (i < len

7、) && (ch != '0'); i+) tempi = ch; ch = fgetc(fp); tempi = '0'fclose(fp);ddress0;len = inode_arraynum.length;if(fp = fopen(image_name, "r+b") = NULL) printf("Can't open file %s.n", image_name); exit(-1);fseek(fp, BLKSIZE+INODESIZE*INODENUM+add0*BLKSIZE,

8、 SEEK_SET);for(i=0; (i<len)&&(tempi!='0')&&(i < 512); i+) fputc(tempi, fp);if(i = 512) add1 = inode_arraynum.address1; fseek(fp, BLKSIZE+INODESIZE*INODENUM+add1*BLKSIZE, SEEK_SET); for(; (i < len) && (tempi != '0'); i+) fputc(tempi, fp);fputc('0&#

9、39;, fp);fclose(fp);num = 0) strcpy(path,;else strcpy(path,; m=0; n=inum_cur; while(m != inum_cur) while(inode_arrayn.iparent != m) n = inode_arrayn.iparent; strcat(path,"/"); strcat(path,inode_arrayn.file_name); m = n; n = inum_cur; printf("%s$",path); 或者 cd dir1)void cd(void)in

10、t i;if(argc != 2) printf("Command cd must have two args. n"); return ;if(!strcmp(argv1, ".") inum_cur = inode_arrayinum_cur.iparent;else for(i = 0; i < INODENUM; i+) if(inode_arrayi.inum>0)&& (inode_arrayi.type='d')&& (inode_arrayi.iparent=inum_cur)&

11、amp;& !strcmp(inode_arrayi.file_name,argv1)&& !strcmp(inode_arrayi.user_name,) break; if(i = INODENUM) printf("This directory isn't exsited.n"); else inum_cur = i;n"); return ;num> 0) && (inode_arrayi.iparent = inum_cur)&& !strcmp(inode_arrayi.user_n

12、ame,) if(inode_arrayi.type = 'd') dcount+; printf("%-20s<DIR>n", inode_arrayi.file_name); else fcount+; bcount+=inode_arrayi.length; printf("%-20s%12d bytesn", inode_arrayi.file_name,inode_arrayi.length); printf("n %d file(s)%11d bytesn",fcount,bcount);pri

13、ntf(" %d dir(s) %11d bytes FreeSpacen",dcount,1024*1024-bcount);n");return ;num < 0) break; if(i = INODENUM) printf("Inode is full.n"); exit(-1);inode_arrayi.inum = i;strcpy(inode_arrayi.file_name, argv1);inode_arrayi.type = 'd'strcpy(inode_arrayi.user_name,;inode

14、_arrayi.iparent = inum_cur;inode_arrayi.length = 0;save_inode(i);n"); return ;for(i = 0; i < INODENUM; i+) if(inode_arrayi.inum > 0) && (inode_arrayi.type = 'f') && !strcmp(inode_arrayi.file_name, argv1) printf("This file is exsit.n"); return ; for(i = 0;

15、 i < INODENUM; i+) if(inode_arrayi.inum < 0) break;if(i = INODENUM) printf("Inode is full.n"); exit(-1);inode_arrayi.inum = i;strcpy(inode_arrayi.file_name, argv1);inode_arrayi.type = 'f'strcpy(inode_arrayi.user_name, ;inode_arrayi.iparent = inum_cur;inode_arrayi.length = 0;s

16、ave_inode(i);n"); return ;for(i = 0; i < INODENUM; i+) if(inode_arrayi.inum > 0) && (inode_arrayi.type = 'f') && !strcmp(inode_arrayi.file_name,argv1)&& !strcmp(inode_arrayi.user_name,) break;if(i = INODENUM) printf("The file you want to open doesn'

17、;t exsited.n"); return ;inum = i;printf("Please input open mode:(1: read, 2: write, 3: read and write):");scanf("%d", &mode);getchar();if(mode < 1) | (mode > 3) printf("Open mode is wrong.n"); return;for(i = 0; i < FILENUM; i+) if(file_arrayi.inum <

18、 0) break;if(i = FILENUM) printf("The file table is full, please close some file.n"); return ;filenum = i;file_arrayfilenum.inum = inum; strcpy(file_arrayfilenum.file_name, inode_arrayinum.file_name);file_arrayfilenum.mode = mode; printf("Open file %s by ", file_arrayfilenum.file

19、_name);if(mode = 1) printf("read only.n");else if(mode = 2) printf("write only.n");else printf("read and write.n");n"); return;for(i = 0; i < FILENUM; i+) if(file_arrayi.inum > 0) && !strcmp(file_arrayi.file_name,argv1) break;if(i = FILENUM) printf(&q

20、uot;Open %s first.n", argv1); return ;else if(file_arrayi.mode = 2) printf("Can't read %s.n", argv1); return ;inum = file_arrayi.inum;printf("The length of %s:%d.n", argv1, inode_arrayinum.length);if(inode_arrayinum.length > 0) read_blk(inum); for(i = 0; (i < inode

21、_arrayinum.length) && (tempi != '0'); i+) printf("%c", tempi);n"); return ;for(i = 0; i < FILENUM; i+) if(file_arrayi.inum>0)&& !strcmp(file_arrayi.file_name,argv1) break; if(i = FILENUM) printf("Open %s first.n", argv1); return ;else if(file_ar

22、rayi.mode = 1) printf("Can't write %s.n", argv1); return ;inum = file_arrayi.inum;printf("The length of %s:%dn", inode_arrayinum.file_name, inode_arrayinum.length);if(inode_arrayinum.length = 0) i=0; inode_arrayinum.address0 = get_blknum(); printf("Input the data(CTRL+Z

23、to end):n"); while(i<1023&&(tempi=getchar()!=EOF) i+; tempi='0' length=strlen(temp)+1; inode_arrayinum.length=length; if(length > 512) inode_arrayinum.address1 = get_blknum(); save_inode(inum); write_blk(inum);else printf("This file can't be written.n");n&quo

24、t;); return ;for(i = 0; i < FILENUM; i+) if(file_arrayi.inum > 0) && !strcmp(file_arrayi.file_name, argv1) break;if(i = FILENUM) printf("This file doesn't be opened.n"); return ;else file_arrayi.inum = -1; printf("Close %s success!n", argv1);num = -1;if(inode_ar

25、rayi.length > 0) release_blk(inode_arrayi.address0); if(inode_arrayi.length >= 512) release_blk(inode_arrayi.address1);save_inode(i);n"); return ;int n,t,i;stack<int> istk; for(i = 0; i < INODENUM; i+)num >=0) && (inode_arrayi.iparent = inum_cur)&& (!strcmp(ino

26、de_arrayi.file_name,argv1)&& (!strcmp(inode_arrayi.user_name,) n=inode_arrayi.inum;break; if(i=INODENUM) puts("Directory ERROR"); else (n); while(!() t=(); (); del(t); for(i = 0; i < INODENUM; i+) if(inode_arrayi.inum >=0) &&(inode_arrayi.iparent = t) (i); / 功能: 退出當(dāng)前用

27、戶(logout)void logout()printf("Do you want to exit this user(y/n)");scanf("%c", &choice); getchar();if(choice = 'y') | (choice = 'Y') printf("nCurrent user has exited!n"); login();return ;/ 功能: 退出文件系統(tǒng)(quit)void quit()printf("Do you want to exist(y/n):");scanf("%c", &choice);getchar(); if(choice = 'y') | (choice = 'Y')exit(0);/ 功能: 顯示錯(cuò)誤void errcmd()printf("Command Error!n");/清空內(nèi)存中存在的用戶名v

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論