²Ù×÷ϵͳʵÑ鱨¸æ
cout<<\}
/**·ÃÎÊĿ¼**/ void visit(string str){ cout<<\}
/**ÏÔʾÎļþÊôÐÔ**/ void attrib(string str){ cout<<\}
/**Îļþ»òÕßÄ¿Â¼ÖØÃüÃû**/ void rename(string str){ cout<<\}
/**´Ëº¯ÊýÅж϶ÔÒª·ÃÎʵÄÎļþ¼ÐÊÇ·ñÓзÃÎÊȨÏÞ**/
bool access(struct inode *pinode)//µ÷ÓõÄʱºò Òª°Ñµ±Ç°ÎļþµÄinodeÖ¸Õë´«Ë͹ýÀ´ ÕâÀï0±íʾÆÕͨÓû§ 1±íʾ¹ÜÀíÔ± { if(pinode->di_userID==cur_user->user_id)return true;//¸ÃÎļþÊǵ±Ç°Óû§ÓµÓÐ if(cur_user->user_access==1)return true;//¸ÃÓû§Îª¹ÜÀíÔ± return false; }
/**´Ëº¯ÊýÓÃÓÚ¶ÁÈ¡ÏàÓ¦inodeºÅÏÂÃæµÄinode¿é**/ struct inode * getInode(unsigned int n){ inode *temp; temp=new inode; fseek(f_stream,DINODE_START+BLOCK_SIZE*n,SEEK_SET); fread(temp,sizeof(struct inode),1,f_stream); // cout<<\mode:\ /**´Ëº¯Êý½«Ö¸¶¨±àºÅϵÄÊý¾Ý¿éµÄĿ¼»òÕßÎļþ¶ÁÈëcur_dir**/ bool getDataBlock(unsigned int n){ //directory *temp; 26 ²Ù×÷ϵͳʵÑ鱨¸æ //temp=new directory; fseek(f_stream,DATA_START+BLOCK_SIZE*n,SEEK_SET); fread(cur_dir,sizeof(struct directory)*cur_inode->di_number,1,f_stream); // cout<<\º¯Êý:\ return true; } /**´Ëº¯ÊýÓÃÓÚÅжϵ±Ç°Îļþ¼ÐÓÐûÓвéÕÒµÄÎļþ ûÓзµ»Ø-1 Óзµ»Ø¸ÃÎļþµÄinodºÅ**/ int FindFile(string filename) { int i; if(filename.length()>FILE_NAME_LENGTH) { cout<<\ÄúÊäÈëµÄÎļþÃû³¤¶È´óÓÚ14,Îļþ²éÕÒʧ°Ü£¡\ return -1; } if( filename==\ { cout<<\×ÔÉíÎļþ¼Ð²»ÔÊÐí²Ù×÷£¡\ return -1; } if(\ { cout<<\¸¸Ä¿Â¼²»ÔÊÐí²Ù×÷£¡\ return -1; } for(i=0;i if(dir_buf[i].name==filename) { cout<<\µ±Ç°Îļþ´æÔÚ£¡\ return dir_buf[i].d_ino; } } cout<<\δÕÒµ½´ËÎļþ\ return -1; 27 ²Ù×÷ϵͳʵÑ鱨¸æ } /**´Ëº¯ÊýÓÉÓÚ¶Áȡһ¸öÎļþ,½«ÎļþÄÚÈÝÊä³ö**/ bool read(string filename) { struct inode *temp; if(FindFile(filename)==-1) { return false; } temp=getInode(FindFile(filename)); if(!access(temp)) { } cout<<\ÄúûÓдËÎļþµÄ·ÃÎÊȨÏÞ\return false; if(temp->di_mode!=1) { cout< void createFile(string str) { int i,j,m,file_access; if(str.length()>FILE_NAME_LENGTH) { 28 ²Ù×÷ϵͳʵÑ鱨¸æ cout<<\ÄúÊäÈëµÄÎļþÃû³¤¶È´óÓÚ20£¬Îļþ´´½¨Ê§°Ü£¡\ return ; } if(FindFile(str)!=-1) { cout<<\ÄúÊäÈëµÄÎļþÃûÒÑ´æÔÚ£¬ÎļþÃû²»ÄÜÖØ¸´£¬´´½¨Ê§°Ü£¡\ return; } if(superBlock.s_free_inodes_count==0||superBlock.s_free_blocks_count==0) { cout<<\µ±Ç°´æ´¢¿Õ¼äÒÑÂú£¡Çëɾ³ýһЩÎļþºóÔÙ´æ´¢¡£\ return ; } cout<<\ÇëÊäÈëÎļþµÄ·ÃÎÊȨÏÞ¡£1±íʾ¹²ÏíÎļþ£¬0±íʾ˽ÓÐÎļþ: \ cin>>file_access; fflush(stdin); for(j=0;j for(m=0;m if(bk_bitmap[m]==0) { bk_bitmap[m]=1; break; } } char *buf; int k=0,tag=0; 29 ²Ù×÷ϵͳʵÑ鱨¸æ buf = (char *)malloc(BLOCK_SIZE*sizeof(char)); cout<<\ÇëÊäÈëÎļþµÄÄÚÈÝ£¬ÒÔ¡°###¡±½áÊø£¡\ for(i=0;i buf[i] = getchar(); if(tag==0) k=0; if(buf[i] == '#') { tag=1; k++; if(k == 3) break; } else { k=0; tag=0; } } buf[i-2]='\\0'; cout<<\Îļþ³¤¶ÈΪ:\ struct inode *node_temp; node_temp=new inode; if(!node_temp) { cout<<\ÄÚ´æ·ÖÅäʧ°Ü!Îļþ´´½¨²»³É¹¦£¡\ return; } node_temp->di_tag=j; node_temp->di_number=1; /*¹ØÁªÎļþÊý£¬µ±Îª0ʱ±íʾɾ³ýÎļþ,ÈçÒ»¸öĿ¼ÖÁÉÙ°üº¬Á½¸öÎļþ:\ºÍ\ node_temp->di_mode=1; /*´æÈ¡Ä£Ê½:0ΪĿ¼,1ΪÎļþ*/ node_temp->di_userID=cur_user->user_id; /*µ±Ç°inodeËùÊôÓû§ 0Ϊ¸ùĿ¼ID,Ò»´ÎÏÂÈ¥ÊǹÜÀíԱĿ¼¡¢Óû§Ä¿Â¼*/ node_temp->di_access=file_access; /*·ÃÎÊȨÏÞ 0Ϊ²»ÔÊÐíÆÕͨÓû§·ÃÎÊ(¹«¹²Ä¿Â¼),1ΪÔÊÐíÆÕͨÓû§·ÃÎÊ*/ node_temp->di_size=strlen(buf); /*Îļþ´óС,Ŀ¼ûÓдóС,ֵΪ0*/ node_temp->di_ctime; /* ´´½¨Ê±¼ä */ node_temp->di_mtime; /* ×îºóÒ»´ÎÐÞ¸Äʱ¼ä*/ 30