File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed
Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 55函数:close
66功能:关闭打开文件时,修改用户打开表和系统打开表中的纪录信息
77*******************************************************/
8- void close (unsigned int user_id, unsigned short cfd){
8+ void close (unsigned int user_id, int cfd){
99 struct inode *inode;
1010 inode = sys_ofile[user[user_id].u_ofile [cfd]].f_inode ;
1111 iput (inode);
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ extern int login(unsigned short, char *);
182182extern int logout (unsigned short );
183183extern void install ();
184184extern void format ();
185- extern void close (unsigned int ,unsigned short );
185+ extern void close (unsigned int ,int ); /*既然read, write都可以用int,没必要接着用unsigned short*/
186186extern void halt ();
187187extern void delete (char * );
188188extern int shell (int user_id ,char * str );
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ int getcid(char *command){
2525int shell (int user_id,char *str){
2626 char seps[] =" \t\n\0 " ;
2727 char * token,*tstr,*buf;
28- unsigned short mode,fd;
28+ unsigned short mode;
29+ int fd;
2930 int cid,size;
3031 token = strtok (str,seps);
3132 if (token == NULL )
@@ -69,6 +70,7 @@ int shell(int user_id,char *str){
6970 printf (" 创建文件失败!\n " );
7071 break ;
7172 }
73+ // printf("%d %d\n", user_id, fd);/*调试用句*/
7274 close (user_id,fd);
7375 break ;
7476 case 5 :
@@ -111,6 +113,11 @@ int shell(int user_id,char *str){
111113 }
112114 sscanf (token," %d" ,&size);
113115 fd = open (user_id,tstr,READ);
116+ if (fd == -1 ) {
117+ printf (" 文件不存在!\n " );
118+ break ;
119+ }
120+ // printf("%d %d\n", user_id, fd);/*调试用句*/
114121 buf = (char *)malloc (size+1 );
115122 size = read (fd,buf,size);
116123 printf (" %d bytes have been read in buf from file %s.\n " ,size,tstr);
You can’t perform that action at this time.
0 commit comments