Commit | Line | Data |
---|---|---|
31db12cb | 1 | /* ufs_vnops.c 4.48 83/01/11 */ |
6459ebe0 | 2 | |
d67a03eb BJ |
3 | #include "../h/param.h" |
4 | #include "../h/systm.h" | |
d67a03eb BJ |
5 | #include "../h/dir.h" |
6 | #include "../h/user.h" | |
35e7c31a | 7 | #include "../h/kernel.h" |
d67a03eb | 8 | #include "../h/file.h" |
6459ebe0 | 9 | #include "../h/stat.h" |
3e78e260 | 10 | #include "../h/inode.h" |
6459ebe0 | 11 | #include "../h/fs.h" |
3e78e260 | 12 | #include "../h/buf.h" |
3e78e260 | 13 | #include "../h/proc.h" |
0a77f278 | 14 | #include "../h/quota.h" |
4147b3f6 | 15 | #include "../h/descrip.h" |
31949305 BJ |
16 | #include "../h/uio.h" |
17 | #include "../h/socket.h" | |
b32450f4 | 18 | #include "../h/socketvar.h" |
4f083fd7 | 19 | #include "../h/nami.h" |
3e78e260 | 20 | |
4f083fd7 SL |
21 | /* |
22 | * Change current working directory (``.''). | |
23 | */ | |
3e78e260 BJ |
24 | chdir() |
25 | { | |
26 | ||
27 | chdirec(&u.u_cdir); | |
28 | } | |
29 | ||
4f083fd7 SL |
30 | /* |
31 | * Change notion of root (``/'') directory. | |
32 | */ | |
3e78e260 BJ |
33 | chroot() |
34 | { | |
35 | ||
36 | if (suser()) | |
37 | chdirec(&u.u_rdir); | |
38 | } | |
39 | ||
4f083fd7 SL |
40 | /* |
41 | * Common routine for chroot and chdir. | |
42 | */ | |
3e78e260 | 43 | chdirec(ipp) |
528f664c | 44 | register struct inode **ipp; |
3e78e260 BJ |
45 | { |
46 | register struct inode *ip; | |
47 | struct a { | |
48 | char *fname; | |
49 | }; | |
50 | ||
4f083fd7 SL |
51 | ip = namei(uchar, LOOKUP, 1); |
52 | if (ip == NULL) | |
3e78e260 | 53 | return; |
4f083fd7 | 54 | if ((ip->i_mode&IFMT) != IFDIR) { |
3e78e260 BJ |
55 | u.u_error = ENOTDIR; |
56 | goto bad; | |
57 | } | |
4f083fd7 | 58 | if (access(ip, IEXEC)) |
3e78e260 | 59 | goto bad; |
ca91bded | 60 | iunlock(ip); |
8eee8525 KM |
61 | if (*ipp) |
62 | irele(*ipp); | |
3e78e260 BJ |
63 | *ipp = ip; |
64 | return; | |
65 | ||
66 | bad: | |
67 | iput(ip); | |
68 | } | |
69 | ||
70 | /* | |
71 | * Open system call. | |
72 | */ | |
73 | open() | |
74 | { | |
75 | register struct inode *ip; | |
76 | register struct a { | |
77 | char *fname; | |
528f664c SL |
78 | int flags; |
79 | int mode; | |
3e78e260 | 80 | } *uap; |
4f083fd7 | 81 | int checkpermissions = 1, flags; |
3e78e260 BJ |
82 | |
83 | uap = (struct a *)u.u_ap; | |
4f083fd7 SL |
84 | flags = uap->flags + 1; |
85 | if ((flags&FTRUNCATE) && (flags&FWRITE) == 0) { | |
86 | u.u_error = EINVAL; | |
87 | return; | |
88 | } | |
89 | if (flags&FCREATE) { | |
90 | ip = namei(uchar, CREATE, 1); | |
528f664c SL |
91 | if (ip == NULL) { |
92 | if (u.u_error) | |
93 | return; | |
94 | ip = maknode(uap->mode&07777&(~ISVTX)); | |
95 | checkpermissions = 0; | |
4f083fd7 | 96 | flags &= ~FTRUNCATE; |
528f664c SL |
97 | } |
98 | } else | |
4f083fd7 | 99 | ip = namei(uchar, LOOKUP, 1); |
3e78e260 BJ |
100 | if (ip == NULL) |
101 | return; | |
4f083fd7 | 102 | open1(ip, flags, checkpermissions); |
3e78e260 BJ |
103 | } |
104 | ||
528f664c | 105 | #ifndef NOCOMPAT |
3e78e260 BJ |
106 | /* |
107 | * Creat system call. | |
108 | */ | |
4147b3f6 | 109 | ocreat() |
3e78e260 BJ |
110 | { |
111 | register struct inode *ip; | |
112 | register struct a { | |
113 | char *fname; | |
114 | int fmode; | |
115 | } *uap; | |
116 | ||
117 | uap = (struct a *)u.u_ap; | |
4f083fd7 | 118 | ip = namei(uchar, CREATE, 1); |
3e78e260 BJ |
119 | if (ip == NULL) { |
120 | if (u.u_error) | |
121 | return; | |
122 | ip = maknode(uap->fmode&07777&(~ISVTX)); | |
528f664c | 123 | if (ip == NULL) |
3e78e260 | 124 | return; |
528f664c | 125 | open1(ip, FWRITE, 0); |
3e78e260 | 126 | } else |
4f083fd7 | 127 | open1(ip, FWRITE|FTRUNCATE, 1); |
3e78e260 | 128 | } |
528f664c | 129 | #endif |
3e78e260 BJ |
130 | |
131 | /* | |
132 | * Common code for open and creat. | |
528f664c SL |
133 | * Check permissions (if we haven't done so already), |
134 | * allocate an open file structure, and call | |
135 | * the device open routine, if any. | |
3e78e260 | 136 | */ |
528f664c | 137 | open1(ip, mode, checkpermissions) |
3e78e260 BJ |
138 | register struct inode *ip; |
139 | register mode; | |
140 | { | |
141 | register struct file *fp; | |
528f664c | 142 | int i, flags; |
3e78e260 | 143 | |
528f664c | 144 | if (checkpermissions) { |
3e78e260 | 145 | if (mode&FREAD) |
528f664c SL |
146 | if (access(ip, IREAD)) |
147 | goto bad; | |
3e78e260 | 148 | if (mode&FWRITE) { |
528f664c SL |
149 | if (access(ip, IWRITE)) |
150 | goto bad; | |
151 | if ((ip->i_mode&IFMT) == IFDIR) { | |
3e78e260 | 152 | u.u_error = EISDIR; |
528f664c SL |
153 | goto bad; |
154 | } | |
3e78e260 BJ |
155 | } |
156 | } | |
528f664c SL |
157 | |
158 | /* | |
159 | * Check locking on inode. Release "inode lock" | |
160 | * while doing so in case we block inside flocki. | |
161 | */ | |
162 | flags = 0; | |
4f083fd7 | 163 | if (mode&(FSHLOCK|FEXLOCK)) { |
528f664c SL |
164 | iunlock(ip); |
165 | flags = flocki(ip, 0, mode); | |
166 | ilock(ip); | |
167 | if (u.u_error) | |
168 | goto bad; | |
8eee8525 | 169 | } |
528f664c | 170 | if (mode&FTRUNCATE) |
4f083fd7 | 171 | itrunc(ip, (u_long)0); |
ca91bded | 172 | iunlock(ip); |
3e78e260 BJ |
173 | if ((fp = falloc()) == NULL) |
174 | goto out; | |
528f664c | 175 | fp->f_flag = mode & FMODES; |
4147b3f6 | 176 | fp->f_type = DTYPE_FILE; |
3e78e260 BJ |
177 | i = u.u_r.r_val1; |
178 | fp->f_inode = ip; | |
f45396c3 | 179 | u.u_error = openi(ip, mode); |
528f664c SL |
180 | if (u.u_error == 0) { |
181 | u.u_pofile[i] = flags; | |
3e78e260 | 182 | return; |
528f664c | 183 | } |
3e78e260 BJ |
184 | u.u_ofile[i] = NULL; |
185 | fp->f_count--; | |
186 | out: | |
8eee8525 | 187 | irele(ip); |
528f664c SL |
188 | return; |
189 | bad: | |
190 | iput(ip); | |
3e78e260 BJ |
191 | } |
192 | ||
193 | /* | |
194 | * Mknod system call | |
195 | */ | |
196 | mknod() | |
197 | { | |
198 | register struct inode *ip; | |
199 | register struct a { | |
200 | char *fname; | |
201 | int fmode; | |
202 | int dev; | |
203 | } *uap; | |
204 | ||
205 | uap = (struct a *)u.u_ap; | |
206 | if (suser()) { | |
4f083fd7 | 207 | ip = namei(uchar, CREATE, 0); |
3e78e260 BJ |
208 | if (ip != NULL) { |
209 | u.u_error = EEXIST; | |
210 | goto out; | |
211 | } | |
212 | } | |
213 | if (u.u_error) | |
214 | return; | |
215 | ip = maknode(uap->fmode); | |
216 | if (ip == NULL) | |
217 | return; | |
218 | if (uap->dev) { | |
219 | /* | |
220 | * Want to be able to use this to make badblock | |
221 | * inodes, so don't truncate the dev number. | |
222 | */ | |
6459ebe0 | 223 | ip->i_rdev = uap->dev; |
3e78e260 BJ |
224 | ip->i_flag |= IACC|IUPD|ICHG; |
225 | } | |
226 | ||
227 | out: | |
228 | iput(ip); | |
229 | } | |
230 | ||
231 | /* | |
232 | * link system call | |
233 | */ | |
234 | link() | |
235 | { | |
236 | register struct inode *ip, *xp; | |
237 | register struct a { | |
238 | char *target; | |
239 | char *linkname; | |
240 | } *uap; | |
241 | ||
242 | uap = (struct a *)u.u_ap; | |
4f083fd7 | 243 | ip = namei(uchar, LOOKUP, 1); /* well, this routine is doomed anyhow */ |
3e78e260 BJ |
244 | if (ip == NULL) |
245 | return; | |
4f083fd7 | 246 | if ((ip->i_mode&IFMT) == IFDIR && !suser()) { |
f94ceb3b BJ |
247 | iput(ip); |
248 | return; | |
249 | } | |
3e78e260 BJ |
250 | ip->i_nlink++; |
251 | ip->i_flag |= ICHG; | |
3fd23f5c | 252 | iupdat(ip, &time, &time, 1); |
ca91bded | 253 | iunlock(ip); |
3e78e260 | 254 | u.u_dirp = (caddr_t)uap->linkname; |
4f083fd7 | 255 | xp = namei(uchar, CREATE, 0); |
3e78e260 BJ |
256 | if (xp != NULL) { |
257 | u.u_error = EEXIST; | |
258 | iput(xp); | |
259 | goto out; | |
260 | } | |
261 | if (u.u_error) | |
262 | goto out; | |
263 | if (u.u_pdir->i_dev != ip->i_dev) { | |
264 | iput(u.u_pdir); | |
265 | u.u_error = EXDEV; | |
266 | goto out; | |
267 | } | |
64d3a787 | 268 | direnter(ip); |
3e78e260 BJ |
269 | out: |
270 | if (u.u_error) { | |
271 | ip->i_nlink--; | |
272 | ip->i_flag |= ICHG; | |
273 | } | |
8eee8525 | 274 | irele(ip); |
3e78e260 BJ |
275 | } |
276 | ||
277 | /* | |
278 | * symlink -- make a symbolic link | |
279 | */ | |
280 | symlink() | |
281 | { | |
282 | register struct a { | |
283 | char *target; | |
284 | char *linkname; | |
285 | } *uap; | |
286 | register struct inode *ip; | |
287 | register char *tp; | |
288 | register c, nc; | |
289 | ||
290 | uap = (struct a *)u.u_ap; | |
291 | tp = uap->target; | |
292 | nc = 0; | |
293 | while (c = fubyte(tp)) { | |
294 | if (c < 0) { | |
295 | u.u_error = EFAULT; | |
296 | return; | |
297 | } | |
298 | tp++; | |
299 | nc++; | |
300 | } | |
301 | u.u_dirp = uap->linkname; | |
4f083fd7 | 302 | ip = namei(uchar, CREATE, 0); |
3e78e260 BJ |
303 | if (ip) { |
304 | iput(ip); | |
305 | u.u_error = EEXIST; | |
306 | return; | |
307 | } | |
308 | if (u.u_error) | |
309 | return; | |
310 | ip = maknode(IFLNK | 0777); | |
311 | if (ip == NULL) | |
312 | return; | |
31949305 | 313 | u.u_error = rdwri(UIO_WRITE, ip, uap->target, nc, 0, 0, (int *)0); |
4f083fd7 | 314 | /* handle u.u_error != 0 */ |
3e78e260 BJ |
315 | iput(ip); |
316 | } | |
317 | ||
318 | /* | |
319 | * Unlink system call. | |
320 | * Hard to avoid races here, especially | |
321 | * in unlinking directories. | |
322 | */ | |
323 | unlink() | |
324 | { | |
3e78e260 BJ |
325 | struct a { |
326 | char *fname; | |
327 | }; | |
4f083fd7 | 328 | register struct inode *ip, *dp; |
3e78e260 | 329 | |
4f083fd7 SL |
330 | ip = namei(uchar, DELETE | LOCKPARENT, 0); |
331 | if (ip == NULL) | |
3e78e260 | 332 | return; |
4f083fd7 SL |
333 | dp = u.u_pdir; |
334 | if ((ip->i_mode&IFMT) == IFDIR && !suser()) | |
3e78e260 BJ |
335 | goto out; |
336 | /* | |
337 | * Don't unlink a mounted file. | |
338 | */ | |
4f083fd7 | 339 | if (ip->i_dev != dp->i_dev) { |
3e78e260 BJ |
340 | u.u_error = EBUSY; |
341 | goto out; | |
342 | } | |
343 | if (ip->i_flag&ITEXT) | |
344 | xrele(ip); /* try once to free text */ | |
64d3a787 BJ |
345 | if (dirremove()) { |
346 | ip->i_nlink--; | |
347 | ip->i_flag |= ICHG; | |
6459ebe0 | 348 | } |
3e78e260 | 349 | out: |
4f083fd7 | 350 | if (dp == ip) |
8eee8525 KM |
351 | irele(ip); |
352 | else | |
353 | iput(ip); | |
4f083fd7 | 354 | iput(dp); |
3e78e260 BJ |
355 | } |
356 | ||
357 | /* | |
358 | * Seek system call | |
359 | */ | |
35e7c31a | 360 | lseek() |
3e78e260 BJ |
361 | { |
362 | register struct file *fp; | |
363 | register struct a { | |
528f664c | 364 | int fd; |
3e78e260 BJ |
365 | off_t off; |
366 | int sbase; | |
367 | } *uap; | |
368 | ||
369 | uap = (struct a *)u.u_ap; | |
528f664c | 370 | fp = getf(uap->fd); |
3e78e260 BJ |
371 | if (fp == NULL) |
372 | return; | |
4147b3f6 | 373 | if (fp->f_type == DTYPE_SOCKET) { |
3e78e260 BJ |
374 | u.u_error = ESPIPE; |
375 | return; | |
376 | } | |
528f664c | 377 | if (uap->sbase == FSEEK_RELATIVE) |
3e78e260 | 378 | uap->off += fp->f_offset; |
528f664c | 379 | else if (uap->sbase == FSEEK_EOF) |
3e78e260 BJ |
380 | uap->off += fp->f_inode->i_size; |
381 | fp->f_offset = uap->off; | |
382 | u.u_r.r_off = uap->off; | |
383 | } | |
384 | ||
385 | /* | |
386 | * Access system call | |
387 | */ | |
388 | saccess() | |
389 | { | |
390 | register svuid, svgid; | |
391 | register struct inode *ip; | |
392 | register struct a { | |
393 | char *fname; | |
394 | int fmode; | |
395 | } *uap; | |
396 | ||
397 | uap = (struct a *)u.u_ap; | |
398 | svuid = u.u_uid; | |
399 | svgid = u.u_gid; | |
400 | u.u_uid = u.u_ruid; | |
401 | u.u_gid = u.u_rgid; | |
4f083fd7 | 402 | ip = namei(uchar, LOOKUP, 1); |
3e78e260 | 403 | if (ip != NULL) { |
4f083fd7 | 404 | if ((uap->fmode&FACCESS_READ) && access(ip, IREAD)) |
528f664c | 405 | goto done; |
4f083fd7 | 406 | if ((uap->fmode&FACCESS_WRITE) && access(ip, IWRITE)) |
528f664c | 407 | goto done; |
4f083fd7 | 408 | if ((uap->fmode&FACCESS_EXECUTE) && access(ip, IEXEC)) |
528f664c SL |
409 | goto done; |
410 | done: | |
3e78e260 BJ |
411 | iput(ip); |
412 | } | |
413 | u.u_uid = svuid; | |
414 | u.u_gid = svgid; | |
415 | } | |
d67a03eb BJ |
416 | |
417 | /* | |
418 | * the fstat system call. | |
419 | */ | |
420 | fstat() | |
421 | { | |
422 | register struct file *fp; | |
423 | register struct a { | |
528f664c | 424 | int fd; |
d67a03eb BJ |
425 | struct stat *sb; |
426 | } *uap; | |
427 | ||
428 | uap = (struct a *)u.u_ap; | |
528f664c | 429 | fp = getf(uap->fd); |
e92a04af | 430 | if (fp == NULL) |
d67a03eb | 431 | return; |
4147b3f6 | 432 | if (fp->f_type == DTYPE_SOCKET) |
cc15ab5d | 433 | u.u_error = sostat(fp->f_socket, uap->sb); |
e92a04af BJ |
434 | else |
435 | stat1(fp->f_inode, uap->sb); | |
d67a03eb BJ |
436 | } |
437 | ||
438 | /* | |
6459ebe0 | 439 | * Stat system call. This version follows links. |
d67a03eb BJ |
440 | */ |
441 | stat() | |
442 | { | |
443 | register struct inode *ip; | |
444 | register struct a { | |
445 | char *fname; | |
446 | struct stat *sb; | |
447 | } *uap; | |
448 | ||
449 | uap = (struct a *)u.u_ap; | |
4f083fd7 | 450 | ip = namei(uchar, LOOKUP, 1); |
e92a04af | 451 | if (ip == NULL) |
d67a03eb | 452 | return; |
a3aa7f92 | 453 | stat1(ip, uap->sb); |
d67a03eb BJ |
454 | iput(ip); |
455 | } | |
456 | ||
5485e062 | 457 | /* |
6459ebe0 | 458 | * Lstat system call. This version does not follow links. |
5485e062 BJ |
459 | */ |
460 | lstat() | |
461 | { | |
462 | register struct inode *ip; | |
463 | register struct a { | |
464 | char *fname; | |
465 | struct stat *sb; | |
466 | } *uap; | |
467 | ||
468 | uap = (struct a *)u.u_ap; | |
4f083fd7 | 469 | ip = namei(uchar, LOOKUP, 0); |
5485e062 BJ |
470 | if (ip == NULL) |
471 | return; | |
019b08c9 | 472 | stat1(ip, uap->sb); |
5485e062 BJ |
473 | iput(ip); |
474 | } | |
475 | ||
d67a03eb BJ |
476 | /* |
477 | * The basic routine for fstat and stat: | |
478 | * get the inode and pass appropriate parts back. | |
479 | */ | |
a3aa7f92 | 480 | stat1(ip, ub) |
e92a04af BJ |
481 | register struct inode *ip; |
482 | struct stat *ub; | |
d67a03eb | 483 | { |
d67a03eb BJ |
484 | struct stat ds; |
485 | ||
3fd23f5c | 486 | IUPDAT(ip, &time, &time, 0); |
d67a03eb | 487 | /* |
09c42945 | 488 | * Copy from inode table |
d67a03eb BJ |
489 | */ |
490 | ds.st_dev = ip->i_dev; | |
491 | ds.st_ino = ip->i_number; | |
492 | ds.st_mode = ip->i_mode; | |
493 | ds.st_nlink = ip->i_nlink; | |
494 | ds.st_uid = ip->i_uid; | |
495 | ds.st_gid = ip->i_gid; | |
6459ebe0 | 496 | ds.st_rdev = (dev_t)ip->i_rdev; |
a3aa7f92 | 497 | ds.st_size = ip->i_size; |
6459ebe0 | 498 | ds.st_atime = ip->i_atime; |
f9559304 | 499 | ds.st_spare1 = 0; |
6459ebe0 | 500 | ds.st_mtime = ip->i_mtime; |
f9559304 | 501 | ds.st_spare2 = 0; |
6459ebe0 | 502 | ds.st_ctime = ip->i_ctime; |
f9559304 | 503 | ds.st_spare3 = 0; |
528f664c SL |
504 | /* this doesn't belong here */ |
505 | if ((ip->i_mode&IFMT) == IFBLK) | |
506 | ds.st_blksize = BLKDEV_IOSIZE; | |
507 | else if ((ip->i_mode&IFMT) == IFCHR) | |
508 | ds.st_blksize = MAXBSIZE; | |
509 | else | |
510 | ds.st_blksize = ip->i_fs->fs_bsize; | |
f9559304 | 511 | ds.st_spare4[0] = ds.st_spare4[1] = ds.st_spare4[2] = 0; |
127f7d76 | 512 | u.u_error = copyout((caddr_t)&ds, (caddr_t)ub, sizeof(ds)); |
d67a03eb BJ |
513 | } |
514 | ||
515 | /* | |
5485e062 BJ |
516 | * Return target name of a symbolic link |
517 | */ | |
518 | readlink() | |
519 | { | |
520 | register struct inode *ip; | |
521 | register struct a { | |
522 | char *name; | |
523 | char *buf; | |
524 | int count; | |
31949305 BJ |
525 | } *uap = (struct a *)u.u_ap; |
526 | int resid; | |
5485e062 | 527 | |
4f083fd7 | 528 | ip = namei(uchar, LOOKUP, 0); |
5485e062 BJ |
529 | if (ip == NULL) |
530 | return; | |
531 | if ((ip->i_mode&IFMT) != IFLNK) { | |
532 | u.u_error = ENXIO; | |
533 | goto out; | |
534 | } | |
31949305 | 535 | u.u_error = rdwri(UIO_READ, ip, uap->buf, uap->count, 0, 0, &resid); |
5485e062 BJ |
536 | out: |
537 | iput(ip); | |
31949305 | 538 | u.u_r.r_val1 = uap->count - resid; |
5485e062 BJ |
539 | } |
540 | ||
4f083fd7 SL |
541 | /* |
542 | * Change mode of a file given path name. | |
543 | */ | |
3e78e260 | 544 | chmod() |
5485e062 | 545 | { |
528f664c SL |
546 | struct inode *ip; |
547 | struct a { | |
3e78e260 BJ |
548 | char *fname; |
549 | int fmode; | |
5485e062 | 550 | } *uap; |
5485e062 BJ |
551 | |
552 | uap = (struct a *)u.u_ap; | |
3e78e260 | 553 | if ((ip = owner(1)) == NULL) |
5485e062 | 554 | return; |
528f664c | 555 | chmod1(ip, uap->fmode); |
4f083fd7 | 556 | iput(ip); |
528f664c | 557 | } |
f94ceb3b | 558 | |
4f083fd7 SL |
559 | /* |
560 | * Change mode of a file given a file descriptor. | |
561 | */ | |
528f664c SL |
562 | fchmod() |
563 | { | |
564 | struct a { | |
565 | int fd; | |
566 | int fmode; | |
567 | } *uap; | |
568 | register struct inode *ip; | |
569 | register struct file *fp; | |
570 | ||
571 | uap = (struct a *)u.u_ap; | |
572 | fp = getf(uap->fd); | |
573 | if (fp == NULL) | |
574 | return; | |
575 | if (fp->f_type == DTYPE_SOCKET) { | |
576 | u.u_error = EINVAL; | |
577 | return; | |
f94ceb3b | 578 | } |
528f664c | 579 | ip = fp->f_inode; |
4f083fd7 | 580 | if (u.u_uid != ip->i_uid && !suser()) |
528f664c | 581 | return; |
4f083fd7 | 582 | ilock(ip); |
528f664c | 583 | chmod1(ip, uap->fmode); |
4f083fd7 | 584 | iunlock(ip); |
528f664c SL |
585 | } |
586 | ||
4f083fd7 SL |
587 | /* |
588 | * Change the mode on a file. | |
589 | * Inode must be locked before calling. | |
590 | */ | |
528f664c SL |
591 | chmod1(ip, mode) |
592 | register struct inode *ip; | |
593 | register int mode; | |
594 | { | |
197da11b BJ |
595 | register int *gp; |
596 | ||
3e78e260 | 597 | ip->i_mode &= ~07777; |
f94ceb3b | 598 | if (u.u_uid) { |
528f664c | 599 | mode &= ~ISVTX; |
197da11b BJ |
600 | for (gp = u.u_groups; gp < &u.u_groups[NGROUPS]; gp++) |
601 | if (*gp == ip->i_gid) | |
602 | goto ok; | |
603 | mode &= ~ISGID; | |
604 | ok: | |
605 | ; | |
528f664c | 606 | #ifdef MUSH |
0a77f278 RE |
607 | if (u.u_quota->q_syflags & QF_UMASK && u.u_uid != 0 && |
608 | (ip->i_mode & IFMT) != IFCHR) | |
528f664c | 609 | mode &= ~u.u_cmask; |
0a77f278 | 610 | #endif |
f94ceb3b | 611 | } |
528f664c | 612 | ip->i_mode |= mode&07777; |
3e78e260 BJ |
613 | ip->i_flag |= ICHG; |
614 | if (ip->i_flag&ITEXT && (ip->i_mode&ISVTX)==0) | |
615 | xrele(ip); | |
5485e062 BJ |
616 | } |
617 | ||
4f083fd7 SL |
618 | /* |
619 | * Set ownership given a path name. | |
620 | */ | |
3e78e260 | 621 | chown() |
d67a03eb | 622 | { |
528f664c SL |
623 | struct inode *ip; |
624 | struct a { | |
3e78e260 BJ |
625 | char *fname; |
626 | int uid; | |
627 | int gid; | |
d67a03eb | 628 | } *uap; |
d67a03eb BJ |
629 | |
630 | uap = (struct a *)u.u_ap; | |
3e78e260 | 631 | if (!suser() || (ip = owner(0)) == NULL) |
d67a03eb | 632 | return; |
528f664c | 633 | chown1(ip, uap->uid, uap->gid); |
4f083fd7 | 634 | iput(ip); |
528f664c | 635 | } |
f94ceb3b | 636 | |
4f083fd7 SL |
637 | /* |
638 | * Set ownership given a file descriptor. | |
639 | */ | |
528f664c SL |
640 | fchown() |
641 | { | |
642 | struct a { | |
643 | int fd; | |
644 | int uid; | |
645 | int gid; | |
646 | } *uap; | |
647 | register struct inode *ip; | |
648 | register struct file *fp; | |
649 | ||
650 | uap = (struct a *)u.u_ap; | |
651 | fp = getf(uap->fd); | |
652 | if (fp == NULL) | |
653 | return; | |
654 | if (fp->f_type == DTYPE_SOCKET) { | |
655 | u.u_error = EINVAL; | |
656 | return; | |
f94ceb3b | 657 | } |
528f664c | 658 | ip = fp->f_inode; |
4f083fd7 | 659 | if (!suser()) |
528f664c | 660 | return; |
4f083fd7 | 661 | ilock(ip); |
528f664c | 662 | chown1(ip, uap->uid, uap->gid); |
4f083fd7 | 663 | iunlock(ip); |
528f664c SL |
664 | } |
665 | ||
666 | /* | |
667 | * Perform chown operation on inode ip; | |
668 | * inode must be locked prior to call. | |
669 | */ | |
670 | chown1(ip, uid, gid) | |
671 | register struct inode *ip; | |
672 | int uid, gid; | |
673 | { | |
674 | #ifdef QUOTA | |
675 | register long change; | |
676 | ||
0a77f278 RE |
677 | /* |
678 | * This doesn't allow for holes in files (which hopefully don't | |
679 | * happen often in files that we chown), and is not accurate anyway | |
680 | * (eg: it totally ignores 3 level indir blk files - but hopefully | |
681 | * noone who can make a file that big will have a quota) | |
682 | */ | |
528f664c | 683 | if (ip->i_uid == uid) |
0a77f278 RE |
684 | change = 0; |
685 | else { | |
686 | register struct fs *fs = ip->i_fs; | |
687 | ||
688 | if (ip->i_size > (change = NDADDR * fs->fs_bsize)) { | |
689 | register off_t size; | |
690 | ||
691 | size = blkroundup(fs, ip->i_size) - change; | |
692 | change += size; | |
693 | change += fs->fs_bsize; | |
528f664c | 694 | /* this assumes NIADDR <= 2 */ |
0a77f278 RE |
695 | if (size > NINDIR(fs) * fs->fs_bsize) |
696 | change += fs->fs_bsize; | |
697 | } else | |
698 | change = fragroundup(fs, ip->i_size); | |
699 | change /= DEV_BSIZE; | |
700 | } | |
4f083fd7 SL |
701 | (void)chkdq(ip, -change, 1); |
702 | (void)chkiq(ip->i_dev, ip, ip->i_uid, 1); | |
0a77f278 | 703 | dqrele(ip->i_dquot); |
f94ceb3b BJ |
704 | #endif |
705 | /* | |
528f664c SL |
706 | * keep uid/gid's in sane range -- no err, |
707 | * so chown(file, uid, -1) will do something useful | |
f94ceb3b | 708 | */ |
528f664c SL |
709 | if (uid >= 0 && uid <= 32767) /* should have a constant */ |
710 | ip->i_uid = uid; | |
711 | if (gid >= 0 && gid <= 32767) /* same here */ | |
712 | ip->i_gid = gid; | |
3e78e260 BJ |
713 | ip->i_flag |= ICHG; |
714 | if (u.u_ruid != 0) | |
715 | ip->i_mode &= ~(ISUID|ISGID); | |
528f664c | 716 | #ifdef QUOTA |
0a77f278 | 717 | ip->i_dquot = inoquota(ip); |
4f083fd7 SL |
718 | (void)chkdq(ip, change, 1); |
719 | (void)chkiq(ip->i_dev, (struct inode *)NULL, uid, 1); | |
0a77f278 | 720 | #endif |
d67a03eb BJ |
721 | } |
722 | ||
723 | /* | |
3e78e260 BJ |
724 | * Set IUPD and IACC times on file. |
725 | * Can't set ICHG. | |
d67a03eb | 726 | */ |
68da6a91 | 727 | outime() |
e92a04af | 728 | { |
d67a03eb | 729 | register struct a { |
3e78e260 BJ |
730 | char *fname; |
731 | time_t *tptr; | |
d67a03eb | 732 | } *uap; |
3e78e260 BJ |
733 | register struct inode *ip; |
734 | time_t tv[2]; | |
b32450f4 | 735 | struct timeval tv0, tv1; |
d67a03eb BJ |
736 | |
737 | uap = (struct a *)u.u_ap; | |
3e78e260 | 738 | if ((ip = owner(1)) == NULL) |
d67a03eb | 739 | return; |
127f7d76 SL |
740 | u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof(tv)); |
741 | if (u.u_error == 0) { | |
3e78e260 | 742 | ip->i_flag |= IACC|IUPD|ICHG; |
b32450f4 BJ |
743 | tv0.tv_sec = tv[0]; tv0.tv_usec = 0; |
744 | tv1.tv_sec = tv[1]; tv1.tv_usec = 0; | |
745 | iupdat(ip, &tv0, &tv1, 0); | |
d67a03eb | 746 | } |
d67a03eb BJ |
747 | iput(ip); |
748 | } | |
749 | ||
4f083fd7 SL |
750 | /* |
751 | * Flush any pending I/O. | |
752 | */ | |
3e78e260 | 753 | sync() |
d67a03eb | 754 | { |
d67a03eb | 755 | |
3fd23f5c | 756 | update(); |
d67a03eb | 757 | } |
64d3a787 | 758 | |
4f083fd7 SL |
759 | /* |
760 | * Apply an advisory lock on a file descriptor. | |
761 | */ | |
528f664c SL |
762 | flock() |
763 | { | |
764 | struct a { | |
765 | int fd; | |
766 | int how; | |
767 | } *uap; | |
768 | register struct file *fp; | |
769 | register int cmd, flags; | |
770 | ||
771 | uap = (struct a *)u.u_ap; | |
772 | fp = getf(uap->fd); | |
773 | if (fp == NULL) | |
774 | return; | |
775 | if (fp->f_type == DTYPE_SOCKET) { /* XXX */ | |
776 | u.u_error = EINVAL; | |
777 | return; | |
778 | } | |
779 | cmd = uap->how; | |
3650c37d | 780 | flags = u.u_pofile[uap->fd] & (UF_SHLOCK|UF_EXLOCK); |
528f664c SL |
781 | if (cmd&FUNLOCK) { |
782 | if (flags == 0) { | |
783 | u.u_error = EINVAL; | |
784 | return; | |
785 | } | |
786 | funlocki(fp->f_inode, flags); | |
3650c37d | 787 | u.u_pofile[uap->fd] &= ~(UF_SHLOCK|UF_EXLOCK); |
528f664c SL |
788 | return; |
789 | } | |
790 | /* | |
791 | * No reason to write lock a file we've already | |
792 | * write locked, similarly with a read lock. | |
793 | */ | |
3650c37d SL |
794 | if ((flags&UF_EXLOCK) && (cmd&FEXLOCK) || |
795 | (flags&UF_SHLOCK) && (cmd&FSHLOCK)) | |
528f664c SL |
796 | return; |
797 | u.u_pofile[uap->fd] = flocki(fp->f_inode, u.u_pofile[uap->fd], cmd); | |
798 | } | |
799 | ||
4f083fd7 SL |
800 | /* |
801 | * Truncate a file given its path name. | |
802 | */ | |
528f664c SL |
803 | truncate() |
804 | { | |
805 | struct a { | |
806 | char *fname; | |
4f083fd7 | 807 | u_long length; |
31949305 | 808 | } *uap = (struct a *)u.u_ap; |
528f664c SL |
809 | struct inode *ip; |
810 | ||
4f083fd7 | 811 | ip = namei(uchar, LOOKUP, 1); |
528f664c SL |
812 | if (ip == NULL) |
813 | return; | |
814 | if (access(ip, IWRITE)) | |
815 | goto bad; | |
816 | if ((ip->i_mode&IFMT) == IFDIR) { | |
817 | u.u_error = EISDIR; | |
818 | goto bad; | |
819 | } | |
820 | itrunc(ip, uap->length); | |
528f664c SL |
821 | bad: |
822 | iput(ip); | |
823 | } | |
824 | ||
4f083fd7 SL |
825 | /* |
826 | * Truncate a file given a file descriptor. | |
827 | */ | |
528f664c SL |
828 | ftruncate() |
829 | { | |
830 | struct a { | |
831 | int fd; | |
4f083fd7 | 832 | u_long length; |
31949305 | 833 | } *uap = (struct a *)u.u_ap; |
528f664c SL |
834 | struct inode *ip; |
835 | struct file *fp; | |
836 | ||
837 | fp = getf(uap->fd); | |
838 | if (fp == NULL) | |
839 | return; | |
840 | if (fp->f_type == DTYPE_SOCKET) { | |
841 | u.u_error = EINVAL; | |
842 | return; | |
843 | } | |
844 | if ((fp->f_flag&FWRITE) == 0) { | |
845 | u.u_error = EINVAL; | |
846 | return; | |
847 | } | |
848 | ip = fp->f_inode; | |
849 | ilock(ip); | |
850 | itrunc(ip, uap->length); | |
4f083fd7 SL |
851 | iunlock(ip); |
852 | } | |
853 | ||
854 | /* | |
855 | * Synch an open file. | |
856 | */ | |
857 | fsync() | |
858 | { | |
859 | struct a { | |
860 | int fd; | |
861 | } *uap = (struct a *)u.u_ap; | |
862 | struct inode *ip; | |
863 | struct file *fp; | |
864 | ||
865 | fp = getf(uap->fd); | |
866 | if (fp == NULL) | |
867 | return; | |
868 | if (fp->f_type == DTYPE_SOCKET) { | |
869 | u.u_error = EINVAL; | |
870 | return; | |
871 | } | |
872 | ip = fp->f_inode; | |
873 | ilock(ip); | |
874 | syncip(ip); | |
875 | iunlock(ip); | |
528f664c SL |
876 | } |
877 | ||
4f083fd7 SL |
878 | /* |
879 | * Rename system call. | |
880 | * rename("foo", "bar"); | |
881 | * is essentially | |
882 | * unlink("bar"); | |
883 | * link("foo", "bar"); | |
884 | * unlink("foo"); | |
885 | * but ``atomically''. Can't do full commit without saving state in the | |
886 | * inode on disk which isn't feasible at this time. Best we can do is | |
887 | * always guarantee the target exists. | |
888 | * | |
889 | * Basic algorithm is: | |
890 | * | |
891 | * 1) Bump link count on source while we're linking it to the | |
892 | * target. This also insure the inode won't be deleted out | |
893 | * from underneath us while we work. | |
894 | * 2) Link source to destination. If destination already exists, | |
895 | * delete it first. | |
896 | * 3) Unlink source reference to inode if still around. | |
897 | * 4) If a directory was moved and the parent of the destination | |
898 | * is different from the source, patch the ".." entry in the | |
899 | * directory. | |
900 | * | |
901 | * Source and destination must either both be directories, or both | |
902 | * not be directories. If target is a directory, it must be empty. | |
903 | */ | |
528f664c SL |
904 | rename() |
905 | { | |
906 | struct a { | |
907 | char *from; | |
908 | char *to; | |
909 | } *uap; | |
4f083fd7 SL |
910 | register struct inode *ip, *xp, *dp; |
911 | int oldparent, parentdifferent, doingdirectory; | |
a5390dce | 912 | int error = 0; |
4f083fd7 SL |
913 | |
914 | uap = (struct a *)u.u_ap; | |
915 | ip = namei(uchar, LOOKUP | LOCKPARENT, 0); | |
916 | if (ip == NULL) | |
917 | return; | |
918 | dp = u.u_pdir; | |
919 | oldparent = 0, doingdirectory = 0; | |
920 | if ((ip->i_mode&IFMT) == IFDIR) { | |
921 | register struct direct *d; | |
922 | ||
923 | d = &u.u_dent; | |
924 | /* | |
925 | * Avoid "." and ".." for obvious reasons. | |
926 | */ | |
927 | if (d->d_name[0] == '.') { | |
928 | if (d->d_namlen == 1 || | |
929 | (d->d_namlen == 2 && d->d_name[1] == '.')) { | |
4f083fd7 | 930 | iput(ip); |
a5390dce | 931 | u.u_error = EINVAL; |
4f083fd7 SL |
932 | return; |
933 | } | |
934 | } | |
935 | oldparent = dp->i_number; | |
936 | doingdirectory++; | |
937 | } | |
938 | irele(dp); | |
939 | ||
940 | /* | |
941 | * 1) Bump link count while we're moving stuff | |
942 | * around. If we crash somewhere before | |
943 | * completing our work, the link count | |
944 | * may be wrong, but correctable. | |
945 | */ | |
946 | ip->i_nlink++; | |
947 | ip->i_flag |= ICHG; | |
948 | iupdat(ip, &time, &time, 1); | |
949 | iunlock(ip); | |
950 | ||
951 | /* | |
952 | * When the target exists, both the directory | |
953 | * and target inodes are returned locked. | |
954 | */ | |
955 | u.u_dirp = (caddr_t)uap->to; | |
956 | xp = namei(uchar, CREATE | LOCKPARENT, 0); | |
a5390dce SL |
957 | if (u.u_error) { |
958 | error = u.u_error; | |
4f083fd7 | 959 | goto out; |
a5390dce | 960 | } |
4f083fd7 SL |
961 | dp = u.u_pdir; |
962 | /* | |
963 | * 2) If target doesn't exist, link the target | |
964 | * to the source and unlink the source. | |
965 | * Otherwise, rewrite the target directory | |
966 | * entry to reference the source inode and | |
967 | * expunge the original entry's existence. | |
968 | */ | |
969 | parentdifferent = oldparent != dp->i_number; | |
970 | if (xp == NULL) { | |
971 | if (dp->i_dev != ip->i_dev) { | |
a5390dce | 972 | error = EXDEV; |
4f083fd7 SL |
973 | goto bad; |
974 | } | |
975 | /* | |
976 | * Account for ".." in directory. | |
977 | * When source and destination have the | |
978 | * same parent we don't fool with the | |
979 | * link count -- this isn't required | |
980 | * because we do a similar check below. | |
981 | */ | |
982 | if (doingdirectory && parentdifferent) { | |
983 | dp->i_nlink++; | |
984 | dp->i_flag |= ICHG; | |
985 | iupdat(dp, &time, &time, 1); | |
986 | } | |
987 | direnter(ip); | |
a5390dce SL |
988 | if (u.u_error) { |
989 | error = u.u_error; | |
4f083fd7 | 990 | goto out; |
a5390dce | 991 | } |
4f083fd7 SL |
992 | } else { |
993 | if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev) { | |
a5390dce | 994 | error = EXDEV; |
4f083fd7 SL |
995 | goto bad; |
996 | } | |
997 | /* | |
a5390dce SL |
998 | * Target must be empty if a directory |
999 | * and have no links to it. | |
4f083fd7 SL |
1000 | * Also, insure source and target are |
1001 | * compatible (both directories, or both | |
1002 | * not directories). | |
1003 | */ | |
1004 | if ((xp->i_mode&IFMT) == IFDIR) { | |
a5390dce SL |
1005 | if (!dirempty(xp) || xp->i_nlink > 2) { |
1006 | error = ENOTEMPTY; | |
4f083fd7 SL |
1007 | goto bad; |
1008 | } | |
1009 | if (!doingdirectory) { | |
a5390dce | 1010 | error = ENOTDIR; |
4f083fd7 SL |
1011 | goto bad; |
1012 | } | |
1013 | } else if (doingdirectory) { | |
a5390dce | 1014 | error = EISDIR; |
4f083fd7 SL |
1015 | goto bad; |
1016 | } | |
1017 | dirrewrite(dp, ip); | |
a5390dce SL |
1018 | if (u.u_error) { |
1019 | error = u.u_error; | |
4f083fd7 | 1020 | goto bad1; |
a5390dce | 1021 | } |
4f083fd7 | 1022 | /* |
a5390dce SL |
1023 | * Adjust the link count of the target to |
1024 | * reflect the dirrewrite above. If this is | |
1025 | * a directory it is empty and there are | |
1026 | * no links to it, so we can squash the inode and | |
1027 | * any space associated with it. We disallowed | |
1028 | * renaming over top of a directory with links to | |
1029 | * it above, as we've no way to determine if | |
1030 | * we've got a link or the directory itself, and | |
1031 | * if we get a link, then ".." will be screwed up. | |
4f083fd7 | 1032 | */ |
a5390dce | 1033 | xp->i_nlink--; |
4f083fd7 | 1034 | if (doingdirectory) { |
a5390dce SL |
1035 | if (--xp->i_nlink != 0) |
1036 | panic("rename: linked directory"); | |
4f083fd7 | 1037 | itrunc(xp, (u_long)0); |
a5390dce | 1038 | } |
4f083fd7 SL |
1039 | xp->i_flag |= ICHG; |
1040 | iput(xp); | |
31db12cb | 1041 | xp = NULL; |
4f083fd7 SL |
1042 | } |
1043 | ||
1044 | /* | |
1045 | * 3) Unlink the source. | |
1046 | */ | |
1047 | u.u_dirp = uap->from; | |
1048 | dp = namei(uchar, DELETE, 0); | |
1049 | /* | |
1050 | * Insure directory entry still exists and | |
1051 | * has not changed since the start of all | |
1052 | * this. If either has occured, forget about | |
1053 | * about deleting the original entry and just | |
1054 | * adjust the link count in the inode. | |
1055 | */ | |
1056 | if (dp == NULL || u.u_dent.d_ino != ip->i_number) { | |
1057 | ip->i_nlink--; | |
1058 | ip->i_flag |= ICHG; | |
1059 | } else { | |
1060 | /* | |
1061 | * If source is a directory, must adjust | |
1062 | * link count of parent directory also. | |
1063 | * If target didn't exist and source and | |
1064 | * target have the same parent, then we | |
1065 | * needn't touch the link count, it all | |
1066 | * balances out in the end. Otherwise, we | |
1067 | * must do so to reflect deletion of ".." | |
1068 | * done above. | |
1069 | */ | |
1070 | if (doingdirectory && (xp != NULL || parentdifferent)) { | |
1071 | dp->i_nlink--; | |
1072 | dp->i_flag |= ICHG; | |
1073 | } | |
1074 | if (dirremove()) { | |
1075 | ip->i_nlink--; | |
1076 | ip->i_flag |= ICHG; | |
1077 | } | |
a5390dce SL |
1078 | if (error == 0) /* conservative */ |
1079 | error = u.u_error; | |
4f083fd7 SL |
1080 | } |
1081 | irele(ip); | |
1082 | if (dp) | |
1083 | iput(dp); | |
1084 | ||
1085 | /* | |
1086 | * 4) Renaming a directory with the parent | |
1087 | * different requires ".." to be rewritten. | |
1088 | * The window is still there for ".." to | |
1089 | * be inconsistent, but this is unavoidable, | |
1090 | * and a lot shorter than when it was done | |
1091 | * in a user process. | |
1092 | */ | |
a5390dce | 1093 | if (doingdirectory && parentdifferent && error == 0) { |
4f083fd7 | 1094 | struct dirtemplate dirbuf; |
528f664c | 1095 | |
4f083fd7 SL |
1096 | u.u_dirp = uap->to; |
1097 | ip = namei(uchar, LOOKUP | LOCKPARENT, 0); | |
1098 | if (ip == NULL) { | |
1099 | printf("rename: .. went away\n"); | |
1100 | return; | |
1101 | } | |
1102 | dp = u.u_pdir; | |
1103 | if ((ip->i_mode&IFMT) != IFDIR) { | |
1104 | printf("rename: .. not a directory\n"); | |
1105 | goto stuck; | |
1106 | } | |
a5390dce | 1107 | error = rdwri(UIO_READ, ip, (caddr_t)&dirbuf, |
4f083fd7 | 1108 | sizeof (struct dirtemplate), (off_t)0, 1, (int *)0); |
a5390dce | 1109 | if (error == 0) { |
4f083fd7 SL |
1110 | dirbuf.dotdot_ino = dp->i_number; |
1111 | (void) rdwri(UIO_WRITE, ip, (caddr_t)&dirbuf, | |
1112 | sizeof (struct dirtemplate), (off_t)0, 1, (int *)0); | |
1113 | } | |
1114 | stuck: | |
1115 | irele(dp); | |
1116 | iput(ip); | |
1117 | } | |
a5390dce SL |
1118 | goto done; |
1119 | ||
4f083fd7 | 1120 | bad: |
31db12cb | 1121 | iput(dp); |
4f083fd7 SL |
1122 | bad1: |
1123 | if (xp) | |
31db12cb | 1124 | iput(xp); |
4f083fd7 SL |
1125 | out: |
1126 | ip->i_nlink--; | |
1127 | ip->i_flag |= ICHG; | |
1128 | irele(ip); | |
a5390dce SL |
1129 | done: |
1130 | if (error) | |
1131 | u.u_error = error; | |
528f664c SL |
1132 | } |
1133 | ||
64d3a787 BJ |
1134 | /* |
1135 | * Make a new file. | |
1136 | */ | |
1137 | struct inode * | |
1138 | maknode(mode) | |
1139 | int mode; | |
1140 | { | |
1141 | register struct inode *ip; | |
1142 | ino_t ipref; | |
1143 | ||
1144 | if ((mode & IFMT) == IFDIR) | |
1145 | ipref = dirpref(u.u_pdir->i_fs); | |
1146 | else | |
1147 | ipref = u.u_pdir->i_number; | |
1148 | ip = ialloc(u.u_pdir, ipref, mode); | |
1149 | if (ip == NULL) { | |
1150 | iput(u.u_pdir); | |
528f664c | 1151 | return (NULL); |
64d3a787 | 1152 | } |
528f664c | 1153 | #ifdef QUOTA |
64d3a787 BJ |
1154 | if (ip->i_dquot != NODQUOT) |
1155 | panic("maknode: dquot"); | |
1156 | #endif | |
1157 | ip->i_flag |= IACC|IUPD|ICHG; | |
1158 | if ((mode & IFMT) == 0) | |
1159 | mode |= IFREG; | |
1160 | ip->i_mode = mode & ~u.u_cmask; | |
1161 | ip->i_nlink = 1; | |
1162 | ip->i_uid = u.u_uid; | |
1163 | ip->i_gid = u.u_pdir->i_gid; | |
528f664c | 1164 | #ifdef QUOTA |
64d3a787 BJ |
1165 | ip->i_dquot = inoquota(ip); |
1166 | #endif | |
1167 | ||
1168 | /* | |
1169 | * Make sure inode goes to disk before directory entry. | |
1170 | */ | |
3fd23f5c | 1171 | iupdat(ip, &time, &time, 1); |
64d3a787 BJ |
1172 | direnter(ip); |
1173 | if (u.u_error) { | |
1174 | /* | |
1175 | * write error occurred trying to update directory | |
1176 | * so must deallocate the inode | |
1177 | */ | |
1178 | ip->i_nlink = 0; | |
1179 | ip->i_flag |= ICHG; | |
1180 | iput(ip); | |
528f664c | 1181 | return (NULL); |
64d3a787 | 1182 | } |
528f664c | 1183 | return (ip); |
64d3a787 | 1184 | } |