Skip to content

Commit e80798c

Browse files
committed
error when non-exsited file closes repaired
1 parent c372139 commit e80798c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

close.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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);

filesys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ extern int login(unsigned short, char *);
182182
extern int logout(unsigned short);
183183
extern void install();
184184
extern void format();
185-
extern void close(unsigned int,unsigned short);
185+
extern void close(unsigned int,int);/*既然read, write都可以用int,没必要接着用unsigned short*/
186186
extern void halt();
187187
extern void delete(char *);
188188
extern int shell(int user_id,char *str);

shell.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ int getcid(char *command){
2525
int 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);

0 commit comments

Comments
 (0)