@@ -127,17 +127,17 @@ sys_link(void)
127
127
iunlock (ip );
128
128
129
129
if ((dp = nameiparent (new , name )) == 0 )
130
- goto bad ;
130
+ goto bad ;
131
131
ilock (dp );
132
- if (dp -> dev != ip -> dev || dirlink (dp , name , ip -> inum ) < 0 )
132
+ if (dp -> dev != ip -> dev || dirlink (dp , name , ip -> inum ) < 0 ){
133
+ iunlockput (dp );
133
134
goto bad ;
135
+ }
134
136
iunlockput (dp );
135
137
iput (ip );
136
138
return 0 ;
137
139
138
140
bad :
139
- if (dp )
140
- iunlockput (dp );
141
141
ilock (ip );
142
142
ip -> nlink -- ;
143
143
iupdate (ip );
@@ -212,7 +212,7 @@ sys_unlink(void)
212
212
}
213
213
214
214
static struct inode *
215
- create (char * path , int canexist , short type , short major , short minor )
215
+ create (char * path , short type , short major , short minor )
216
216
{
217
217
uint off ;
218
218
struct inode * ip , * dp ;
@@ -222,10 +222,10 @@ create(char *path, int canexist, short type, short major, short minor)
222
222
return 0 ;
223
223
ilock (dp );
224
224
225
- if (canexist && (ip = dirlookup (dp , name , & off )) != 0 ){
225
+ if ((ip = dirlookup (dp , name , & off )) != 0 ){
226
226
iunlockput (dp );
227
227
ilock (ip );
228
- if (ip -> type != type || ip -> major != major || ip -> minor != minor ){
228
+ if (ip -> type != type || type != T_FILE ){
229
229
iunlockput (ip );
230
230
return 0 ;
231
231
}
@@ -250,17 +250,8 @@ create(char *path, int canexist, short type, short major, short minor)
250
250
panic ("create dots" );
251
251
}
252
252
253
- if (dirlink (dp , name , ip -> inum ) < 0 ){
254
- if (type == T_DIR ){
255
- dp -> nlink -- ;
256
- iupdate (dp );
257
- }
258
- iunlockput (dp );
259
-
260
- ip -> nlink = 0 ;
261
- iunlockput (ip );
262
- return 0 ;
263
- }
253
+ if (dirlink (dp , name , ip -> inum ) < 0 )
254
+ panic ("create: dirlink" );
264
255
265
256
iunlockput (dp );
266
257
return ip ;
@@ -278,13 +269,13 @@ sys_open(void)
278
269
return -1 ;
279
270
280
271
if (omode & O_CREATE ){
281
- if ((ip = create (path , 1 , T_FILE , 0 , 0 )) == 0 )
272
+ if ((ip = create (path , T_FILE , 0 , 0 )) == 0 )
282
273
return -1 ;
283
274
} else {
284
275
if ((ip = namei (path )) == 0 )
285
276
return -1 ;
286
277
ilock (ip );
287
- if (ip -> type == T_DIR && ( omode & ( O_RDWR | O_WRONLY )) ){
278
+ if (ip -> type == T_DIR && omode != O_RDONLY ){
288
279
iunlockput (ip );
289
280
return -1 ;
290
281
}
@@ -318,7 +309,7 @@ sys_mknod(void)
318
309
if ((len = argstr (0 , & path )) < 0 ||
319
310
argint (1 , & major ) < 0 ||
320
311
argint (2 , & minor ) < 0 ||
321
- (ip = create (path , 0 , T_DEV , major , minor )) == 0 )
312
+ (ip = create (path , T_DEV , major , minor )) == 0 )
322
313
return -1 ;
323
314
iunlockput (ip );
324
315
return 0 ;
@@ -330,7 +321,7 @@ sys_mkdir(void)
330
321
char * path ;
331
322
struct inode * ip ;
332
323
333
- if (argstr (0 , & path ) < 0 || (ip = create (path , 0 , T_DIR , 0 , 0 )) == 0 )
324
+ if (argstr (0 , & path ) < 0 || (ip = create (path , T_DIR , 0 , 0 )) == 0 )
334
325
return -1 ;
335
326
iunlockput (ip );
336
327
return 0 ;
0 commit comments