File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ extern unsigned short iname(char *);
173173extern unsigned int access (unsigned int ,struct inode * ,unsigned short );
174174extern void _dir ();
175175extern void _pwd (char * );
176+ extern void _rename (char * , char * );
176177extern void who (unsigned short );
177178extern void mkdir (char * );
178179extern void chdir (char * );
Original file line number Diff line number Diff line change @@ -40,7 +40,23 @@ unsigned short iname(char *name){
4040 return i;
4141}
4242
43-
43+ void _rename (char *oldname, char *newname)// new 是保留字
44+ {
45+ int i = namei (oldname);
46+ if (i == -1 )
47+ {
48+ printf (" 当前目录下无 %s\n " , oldname);
49+ return ;
50+ }
51+ int j = namei (newname);
52+ if (j != -1 )
53+ {
54+ printf (" 当前目录下已有与 %s 重名的\n " , newname);
55+ return ;
56+ }
57+ strcpy (dir.direct [i].d_name , newname);
58+ return ;
59+ }
4460
4561
4662
Original file line number Diff line number Diff line change 11#include " filesys.h"
22#define CLEN 10
3- #define CNUM 10
3+ #define CNUM 15
44// enum ctype
55char commands[CNUM][CLEN]={
66" exit" ,
@@ -12,7 +12,8 @@ char commands[CNUM][CLEN]={
1212" write" ,
1313" read" ,
1414" who" ,
15- " pwd"
15+ " pwd" ,
16+ " rename"
1617};
1718int getcid (char *command){
1819 int i;
@@ -139,6 +140,16 @@ int shell(int user_id,char *str){
139140 _pwd (wd);
140141 printf (" %s\n " , wd);
141142 break ;
143+ case 10 :
144+ token = strtok (NULL , seps);
145+ tstr = token;
146+ token = strtok (NULL , seps);
147+ if (token == NULL ) {
148+ printf (" rename 命令的正确格式为rename oldname newname,请检查命令!\n " );
149+ break ;
150+ }
151+ _rename (tstr, token);
152+ break ;
142153 case 0 :
143154 return 0 ;
144155 default :
You can’t perform that action at this time.
0 commit comments