ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:16.95KB ,
资源ID:17441361      下载积分:5 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-17441361.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(操作系统实验文件管理代码.docx)为本站会员(b****0)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

操作系统实验文件管理代码.docx

1、操作系统实验文件管理代码#include #include #include #include #includeusing 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(); if(choice = y) | (choice = Y) if(fp=fopen(image_name, w+b) = NULL) printf(C

2、ant create file %sn, image_name); exit(-1); for(i = 0; i BLKSIZE; i+) fputc(0, fp); = 0; strcpy, /); = d; strcpy, /); = 0; = 0; 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 512) add1 = inode_arraynum.address1; if(

3、fp = fopen(image_name, r+b) = NULL) printf(Cant open file %s.n, image_name); exit(-1); fseek(fp, BLKSIZE+INODESIZE*INODENUM +add0*BLKSIZE, SEEK_SET); ch = fgetc(fp); for(i=0; (i len) & (ch != 0) & (i = 512) fseek(fp,BLKSIZE+INODESIZE*INODENUM+add1*BLKSIZE, SEEK_SET); ch = fgetc(fp); for(; (i len) &

4、(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(Cant open file %s.n, image_name); exit(-1); fseek(fp, BLKSIZE+INODESIZE*INODENUM+add0*BLKSIZE, SEEK_SET); for(i=0; (ilen)&(tempi!=0)&(i 512); i+) fputc

5、(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, fp); fclose(fp);num = 0) strcpy(path,; else strcpy(path,; m=0; n=inum_cur; while(m != inum_cur) while(inode_arrayn.ipare

6、nt != 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) int 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;

7、 i 0)& (inode_arrayi.type=d)& (inode_arrayi.iparent=inum_cur)& !strcmp(inode_arrayi.file_name,argv1)& !strcmp(inode_arrayi.user_name,) break; if(i = INODENUM) printf(This directory isnt exsited.n); else inum_cur = i; n); return ; num 0) & (inode_arrayi.iparent = inum_cur)& !strcmp(inode_arrayi.user_

8、name,) if(inode_arrayi.type = d) dcount+; printf(%-20sn, 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); printf( %d dir(s) %11d bytes FreeSpacen,dcount,1024*1024-b

9、count); 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_arrayi.iparent = inum_cur; inode_arrayi.length = 0; save_inode(i);n); return ; for(i = 0;

10、i 0) & (inode_arrayi.type = f) & !strcmp(inode_arrayi.file_name, argv1) printf(This file is exsit.n); return ; for(i = 0; 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

11、 = f; strcpy(inode_arrayi.user_name, ; inode_arrayi.iparent = inum_cur; inode_arrayi.length = 0; save_inode(i);n); return ; for(i = 0; i 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 doe

12、snt exsited.n); return ; inum = i; printf(Please input open mode:(1: read, 2: write, 3: read and write):); scanf(%d, &mode); getchar(); if(mode 3) printf(Open mode is wrong.n); return; for(i = 0; i FILENUM; i+) if(file_arrayi.inum 0) break; if(i = FILENUM) printf(The file table is full, please close

13、 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_name); if(mode = 1) printf(read only.n); else if(mode = 2) printf(write only.n); else pri

14、ntf(read and write.n);n); return; for(i = 0; i 0) & !strcmp(file_arrayi.file_name,argv1) break; if(i = FILENUM) printf(Open %s first.n, argv1); return ; else if(file_arrayi.mode = 2) printf(Cant read %s.n, argv1); return ; inum = file_arrayi.inum; printf(The length of %s:%d.n, argv1, inode_arrayinum

15、.length); if(inode_arrayinum.length 0) read_blk(inum); for(i = 0; (i inode_arrayinum.length) & (tempi != 0); i+) printf(%c, tempi); n); return ; for(i = 0; i 0)& !strcmp(file_arrayi.file_name,argv1) break; if(i = FILENUM) printf(Open %s first.n, argv1); return ; else if(file_arrayi.mode = 1) printf(

16、Cant 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 to end):n); while(i 512) inode_arrayinum.address1 = ge

17、t_blknum(); save_inode(inum); write_blk(inum); else printf(This file cant be written.n);n); return ; for(i = 0; i 0) & !strcmp(file_arrayi.file_name, argv1) break; if(i = FILENUM) printf(This file doesnt be opened.n); return ; else file_arrayi.inum = -1; printf(Close %s success!n, argv1); num = -1;

18、if(inode_arrayi.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 istk; for(i = 0; i =0) & (inode_arrayi.iparent = inum_cur)& (!strcmp(inode_arrayi.file_name,argv1)& (!strcmp(inode_arrayi.user_n

19、ame,) n=inode_arrayi.inum; break; if(i=INODENUM) puts(Directory ERROR); else (n); while(!() t=(); (); del(t); for(i = 0; i =0) &(inode_arrayi.iparent = t) (i); / 功能: 退出当前用户(logout)void logout() printf(Do you want to exit this user(y/n); scanf(%c, &choice); getchar(); if(choice = y) | (choice = Y) pr

20、intf(nCurrent user has exited!n); login(); return ;/ 功能: 退出文件系统(quit)void quit() printf(Do you want to exist(y/n):); scanf(%c, &choice); getchar(); if(choice = y) | (choice = Y) exit(0);/ 功能: 显示错误void errcmd() printf(Command Error!n);/清空内存中存在的用户名void free_user() int i; for(i=0;i10;i+) i=0;/ 功能: 循环执行

21、用户输入的命令, 直到logout/ help, cd, dir, mkdir, creat, open,read, write, close, delete, logout, clear, format,quitvoid command(void) char cmd100; system(cls); do pathset(); gets(cmd); switch(analyse(cmd) case 0: help(); break; case 1: cd(); break; case 2: dir(); break; case 3: mkdir(); break; case 4: creat

22、e(); break; case 5: open(); break; case 6: read(); break; case 7: write(); break; case 8: close(); break; case 9: delet(); break; case 10: logout();break; case 11: system(cls);break; case 12: format(); init(); free_user(); login();break; case 13: quit(); break; case 14: errcmd(); break; default: break; while(1);/ 主函数int main(void) login(); init(); command(); return 0;

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2