}
return -1;
bknum=fcbptr->first;
fcbtmp2=fcbtmp=(fcb *)(myvhard+bknum*BLOCKSIZE); for(j=0;j
while(bknum!=END) { }
strcpy(fcbptr->filename,\ strcpy(fcbptr->exname,\ fcbptr->first=END; openfilelist[curfd].count=0;
do_write(curfd,text,openfilelist[curfd].length,2); } /* 原型声明: 功能描述: 输入:
filename
指向要打开的文件的名字的指针
int my_open(char *filename) 打开文件函数
fatptr=fat1+bknum; bknum=fatptr->id; fatptr->id=FREE;
if(strcmp(fcbtmp2->filename,\{ }
fcbtmp2++;
printf(\return -1;
输出:
返回打开的文件的id
函数功能实现算法描述: */
int my_open(char *filename) {
int i,fd,rbn;
char text[MAX_TXT_SIZE],*p,*fname,*exname; fcb *fcbptr; char exnamed=0;
fname=strtok(filename,\ exname=strtok(NULL,\ if(!exname) { }
for(i=0;i openfilelist[curfd].count=0; rbn=do_read(curfd,openfilelist[curfd].length,text); fcbptr=(fcb *)text; for(i=0;i if(i>=rbn/sizeof(fcb)) { } if(exnamed) { } fd=findFreeO(); if(fd==-1) free(exname); printf(\return curfd; if(strcmp(filename,fcbptr->filename)==0 && strcmp(fcbptr->exname,exname)==0) { } fcbptr++; break; if(strcmp(openfilelist[i].filename,filename)==0 &&strcmp(openfilelist[i].exname,exname)==0&& i!=curfd) { } printf(\return -1; exname=(char *)malloc(3); strcpy(exname,\exnamed=1; { } strcpy(openfilelist[fd].filename,fcbptr->filename); strcpy(openfilelist[fd].exname,fcbptr->exname); openfilelist[fd].attribute=fcbptr->attribute; openfilelist[fd].count=0; openfilelist[fd].date=fcbptr->date; openfilelist[fd].first=fcbptr->first; openfilelist[fd].length=fcbptr->length; openfilelist[fd].time=fcbptr->time; openfilelist[fd].father=curfd; openfilelist[fd].dirno=openfilelist[curfd].first; openfilelist[fd].diroff=i; openfilelist[fd].fcbstate=0; openfilelist[fd].free=1; openfilelist[fd].topenfile=1; strcpy(openfilelist[fd].dir[fd],openfilelist[curfd].dir[curfd]); p=openfilelist[fd].dir[fd]; while(*p!='\\0') p++; return -1; strcpy(p,filename); while(*p!='\\0') p++; if(openfilelist[fd].attribute&0x20) { } else { } return fd; } /**/ /* 原型声明: 功能描述: 输入: fd 打开文件的id int my_close(int fd) 关闭文件函数 *p='.';p++; strcpy(p,openfilelist[fd].exname); *p='\\\\';p++; *p='\\0'; 输出: 返回fd的father的id 函数功能实现算法描述: */ int my_close(int fd) { fcb *fafcb; char text[MAX_TXT_SIZE]; int fa; /* 检查fd的有效性 */ if(fd > MAX_OPEN_FILE || fd<=0) { } fa=openfilelist[fd].father; if(openfilelist[fd].fcbstate) { } openfilelist[fd].attribute=0; openfilelist[fd].count=0; openfilelist[fd].date=0; strcpy(openfilelist[fd].dir[fd],\ strcpy(openfilelist[fd].filename,\ openfilelist[fa].count=0; do_write(fa,text,openfilelist[fa].length,2); fafcb=(fcb *)(text+sizeof(fcb)*openfilelist[fd].diroff); fafcb->attribute=openfilelist[fd].attribute; fafcb->date=openfilelist[fd].date; fafcb->first=openfilelist[fd].first; fafcb->length=openfilelist[fd].length; fafcb->time=openfilelist[fd].time; strcpy(fafcb->filename,openfilelist[fd].filename); strcpy(fafcb->exname,openfilelist[fd].exname); fa=openfilelist[fd].father; openfilelist[fa].count=0; do_read(fa,openfilelist[fa].length,text); printf(\return -1; strcpy(openfilelist[fd].exname,\ openfilelist[fd].length=0; openfilelist[fd].time=0; openfilelist[fd].free=0; openfilelist[fd].topenfile=0; return fa; } /**/ /* 原型声明: 功能描述: 输入: dirname 输出: 函数功能实现算法描述: */ void my_cd(char *dirname) { char *p,text[MAX_TXT_SIZE]; int fd,i; p=strtok(dirname,\ if(strcmp(p,\ return; 指向目录名的指针 无 void my_cd(char *dirname) 更改当前目录函数 if(strcmp(p,\ { } if(strcmp(p,\oot\ { for(i=1;i ptrcurdir=&openfilelist[0]; curfd=0; if(openfilelist[i].free) my_close(i); fd=openfilelist[curfd].father; my_close(curfd); curfd=fd; ptrcurdir=&openfilelist[curfd]; return;

