1 /*- 2 * modified for EXT2FS support in Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7 /*- 8 * Copyright (c) 1982, 1986, 1989, 1993 9 * The Regents of the University of California. All rights reserved. 10 * (c) UNIX System Laboratories, Inc. 11 * All or some portions of this file are derived from material licensed 12 * to the University of California by American Telephone and Telegraph 13 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 14 * the permission of UNIX System Laboratories, Inc. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)ufs_vnops.c 8.7 (Berkeley) 2/3/94 41 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95 42 * $FreeBSD$ 43 */ 44 45 #include "opt_suiddir.h" 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 #include <sys/kernel.h> 50 #include <sys/fcntl.h> 51 #include <sys/stat.h> 52 #include <sys/bio.h> 53 #include <sys/buf.h> 54 #include <sys/endian.h> 55 #include <sys/priv.h> 56 #include <sys/mount.h> 57 #include <sys/unistd.h> 58 #include <sys/time.h> 59 #include <sys/vnode.h> 60 #include <sys/namei.h> 61 #include <sys/lockf.h> 62 #include <sys/event.h> 63 #include <sys/conf.h> 64 #include <sys/file.h> 65 66 #include <vm/vm.h> 67 #include <vm/vm_page.h> 68 #include <vm/vm_object.h> 69 #include <vm/vm_extern.h> 70 #include <vm/vnode_pager.h> 71 72 #include "opt_directio.h" 73 74 #include <ufs/ufs/dir.h> 75 76 #include <fs/ext2fs/fs.h> 77 #include <fs/ext2fs/inode.h> 78 #include <fs/ext2fs/ext2_extern.h> 79 #include <fs/ext2fs/ext2fs.h> 80 #include <fs/ext2fs/ext2_dinode.h> 81 #include <fs/ext2fs/ext2_dir.h> 82 #include <fs/ext2fs/ext2_mount.h> 83 84 static int ext2_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *); 85 static void ext2_itimes_locked(struct vnode *); 86 87 static vop_access_t ext2_access; 88 static int ext2_chmod(struct vnode *, int, struct ucred *, struct thread *); 89 static int ext2_chown(struct vnode *, uid_t, gid_t, struct ucred *, 90 struct thread *); 91 static vop_close_t ext2_close; 92 static vop_create_t ext2_create; 93 static vop_fsync_t ext2_fsync; 94 static vop_getattr_t ext2_getattr; 95 static vop_link_t ext2_link; 96 static vop_mkdir_t ext2_mkdir; 97 static vop_mknod_t ext2_mknod; 98 static vop_open_t ext2_open; 99 static vop_pathconf_t ext2_pathconf; 100 static vop_print_t ext2_print; 101 static vop_read_t ext2_read; 102 static vop_readlink_t ext2_readlink; 103 static vop_remove_t ext2_remove; 104 static vop_rename_t ext2_rename; 105 static vop_rmdir_t ext2_rmdir; 106 static vop_setattr_t ext2_setattr; 107 static vop_strategy_t ext2_strategy; 108 static vop_symlink_t ext2_symlink; 109 static vop_write_t ext2_write; 110 static vop_vptofh_t ext2_vptofh; 111 static vop_close_t ext2fifo_close; 112 static vop_kqfilter_t ext2fifo_kqfilter; 113 114 /* Global vfs data structures for ext2. */ 115 struct vop_vector ext2_vnodeops = { 116 .vop_default = &default_vnodeops, 117 .vop_access = ext2_access, 118 .vop_bmap = ext2_bmap, 119 .vop_cachedlookup = ext2_lookup, 120 .vop_close = ext2_close, 121 .vop_create = ext2_create, 122 .vop_fsync = ext2_fsync, 123 .vop_getattr = ext2_getattr, 124 .vop_inactive = ext2_inactive, 125 .vop_link = ext2_link, 126 .vop_lookup = vfs_cache_lookup, 127 .vop_mkdir = ext2_mkdir, 128 .vop_mknod = ext2_mknod, 129 .vop_open = ext2_open, 130 .vop_pathconf = ext2_pathconf, 131 .vop_poll = vop_stdpoll, 132 .vop_print = ext2_print, 133 .vop_read = ext2_read, 134 .vop_readdir = ext2_readdir, 135 .vop_readlink = ext2_readlink, 136 .vop_reallocblks = ext2_reallocblks, 137 .vop_reclaim = ext2_reclaim, 138 .vop_remove = ext2_remove, 139 .vop_rename = ext2_rename, 140 .vop_rmdir = ext2_rmdir, 141 .vop_setattr = ext2_setattr, 142 .vop_strategy = ext2_strategy, 143 .vop_symlink = ext2_symlink, 144 .vop_write = ext2_write, 145 .vop_vptofh = ext2_vptofh, 146 }; 147 148 struct vop_vector ext2_fifoops = { 149 .vop_default = &fifo_specops, 150 .vop_access = ext2_access, 151 .vop_close = ext2fifo_close, 152 .vop_fsync = ext2_fsync, 153 .vop_getattr = ext2_getattr, 154 .vop_inactive = ext2_inactive, 155 .vop_kqfilter = ext2fifo_kqfilter, 156 .vop_print = ext2_print, 157 .vop_read = VOP_PANIC, 158 .vop_reclaim = ext2_reclaim, 159 .vop_setattr = ext2_setattr, 160 .vop_write = VOP_PANIC, 161 .vop_vptofh = ext2_vptofh, 162 }; 163 164 /* 165 * A virgin directory (no blushing please). 166 * Note that the type and namlen fields are reversed relative to ext2. 167 * Also, we don't use `struct odirtemplate', since it would just cause 168 * endianness problems. 169 */ 170 static struct dirtemplate mastertemplate = { 171 0, 12, 1, EXT2_FT_DIR, ".", 172 0, DIRBLKSIZ - 12, 2, EXT2_FT_DIR, ".." 173 }; 174 static struct dirtemplate omastertemplate = { 175 0, 12, 1, EXT2_FT_UNKNOWN, ".", 176 0, DIRBLKSIZ - 12, 2, EXT2_FT_UNKNOWN, ".." 177 }; 178 179 static void 180 ext2_itimes_locked(struct vnode *vp) 181 { 182 struct inode *ip; 183 struct timespec ts; 184 185 ASSERT_VI_LOCKED(vp, __func__); 186 187 ip = VTOI(vp); 188 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0) 189 return; 190 if ((vp->v_type == VBLK || vp->v_type == VCHR)) 191 ip->i_flag |= IN_LAZYMOD; 192 else 193 ip->i_flag |= IN_MODIFIED; 194 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { 195 vfs_timestamp(&ts); 196 if (ip->i_flag & IN_ACCESS) { 197 ip->i_atime = ts.tv_sec; 198 ip->i_atimensec = ts.tv_nsec; 199 } 200 if (ip->i_flag & IN_UPDATE) { 201 ip->i_mtime = ts.tv_sec; 202 ip->i_mtimensec = ts.tv_nsec; 203 ip->i_modrev++; 204 } 205 if (ip->i_flag & IN_CHANGE) { 206 ip->i_ctime = ts.tv_sec; 207 ip->i_ctimensec = ts.tv_nsec; 208 } 209 } 210 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); 211 } 212 213 void 214 ext2_itimes(struct vnode *vp) 215 { 216 217 VI_LOCK(vp); 218 ext2_itimes_locked(vp); 219 VI_UNLOCK(vp); 220 } 221 222 /* 223 * Create a regular file 224 */ 225 static int 226 ext2_create(ap) 227 struct vop_create_args /* { 228 struct vnode *a_dvp; 229 struct vnode **a_vpp; 230 struct componentname *a_cnp; 231 struct vattr *a_vap; 232 } */ *ap; 233 { 234 int error; 235 236 error = 237 ext2_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode), 238 ap->a_dvp, ap->a_vpp, ap->a_cnp); 239 if (error) 240 return (error); 241 return (0); 242 } 243 244 static int 245 ext2_open(ap) 246 struct vop_open_args /* { 247 struct vnode *a_vp; 248 int a_mode; 249 struct ucred *a_cred; 250 struct thread *a_td; 251 } */ *ap; 252 { 253 254 if (ap->a_vp->v_type == VBLK || ap->a_vp->v_type == VCHR) 255 return (EOPNOTSUPP); 256 257 /* 258 * Files marked append-only must be opened for appending. 259 */ 260 if ((VTOI(ap->a_vp)->i_flags & APPEND) && 261 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE) 262 return (EPERM); 263 264 vnode_create_vobject(ap->a_vp, VTOI(ap->a_vp)->i_size, ap->a_td); 265 266 return (0); 267 } 268 269 /* 270 * Close called. 271 * 272 * Update the times on the inode. 273 */ 274 static int 275 ext2_close(ap) 276 struct vop_close_args /* { 277 struct vnode *a_vp; 278 int a_fflag; 279 struct ucred *a_cred; 280 struct thread *a_td; 281 } */ *ap; 282 { 283 struct vnode *vp = ap->a_vp; 284 285 VI_LOCK(vp); 286 if (vp->v_usecount > 1) 287 ext2_itimes_locked(vp); 288 VI_UNLOCK(vp); 289 return (0); 290 } 291 292 static int 293 ext2_access(ap) 294 struct vop_access_args /* { 295 struct vnode *a_vp; 296 accmode_t a_accmode; 297 struct ucred *a_cred; 298 struct thread *a_td; 299 } */ *ap; 300 { 301 struct vnode *vp = ap->a_vp; 302 struct inode *ip = VTOI(vp); 303 accmode_t accmode = ap->a_accmode; 304 int error; 305 306 if (vp->v_type == VBLK || vp->v_type == VCHR) 307 return (EOPNOTSUPP); 308 309 /* 310 * Disallow write attempts on read-only file systems; 311 * unless the file is a socket, fifo, or a block or 312 * character device resident on the file system. 313 */ 314 if (accmode & VWRITE) { 315 switch (vp->v_type) { 316 case VDIR: 317 case VLNK: 318 case VREG: 319 if (vp->v_mount->mnt_flag & MNT_RDONLY) 320 return (EROFS); 321 break; 322 default: 323 break; 324 } 325 } 326 327 /* If immutable bit set, nobody gets to write it. */ 328 if ((accmode & VWRITE) && (ip->i_flags & (SF_IMMUTABLE | SF_SNAPSHOT))) 329 return (EPERM); 330 331 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid, 332 ap->a_accmode, ap->a_cred, NULL); 333 return (error); 334 } 335 336 static int 337 ext2_getattr(ap) 338 struct vop_getattr_args /* { 339 struct vnode *a_vp; 340 struct vattr *a_vap; 341 struct ucred *a_cred; 342 } */ *ap; 343 { 344 struct vnode *vp = ap->a_vp; 345 struct inode *ip = VTOI(vp); 346 struct vattr *vap = ap->a_vap; 347 348 ext2_itimes(vp); 349 /* 350 * Copy from inode table 351 */ 352 vap->va_fsid = dev2udev(ip->i_devvp->v_rdev); 353 vap->va_fileid = ip->i_number; 354 vap->va_mode = ip->i_mode & ~IFMT; 355 vap->va_nlink = ip->i_nlink; 356 vap->va_uid = ip->i_uid; 357 vap->va_gid = ip->i_gid; 358 vap->va_rdev = ip->i_rdev; 359 vap->va_size = ip->i_size; 360 vap->va_atime.tv_sec = ip->i_atime; 361 vap->va_atime.tv_nsec = E2DI_HAS_XTIME(ip) ? ip->i_atimensec : 0; 362 vap->va_mtime.tv_sec = ip->i_mtime; 363 vap->va_mtime.tv_nsec = E2DI_HAS_XTIME(ip) ? ip->i_mtimensec : 0; 364 vap->va_ctime.tv_sec = ip->i_ctime; 365 vap->va_ctime.tv_nsec = E2DI_HAS_XTIME(ip) ? ip->i_ctimensec : 0; 366 if E2DI_HAS_XTIME(ip) { 367 vap->va_birthtime.tv_sec = ip->i_birthtime; 368 vap->va_birthtime.tv_nsec = ip->i_birthnsec; 369 } 370 vap->va_flags = ip->i_flags; 371 vap->va_gen = ip->i_gen; 372 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize; 373 vap->va_bytes = dbtob((u_quad_t)ip->i_blocks); 374 vap->va_type = IFTOVT(ip->i_mode); 375 vap->va_filerev = ip->i_modrev; 376 return (0); 377 } 378 379 /* 380 * Set attribute vnode op. called from several syscalls 381 */ 382 static int 383 ext2_setattr(ap) 384 struct vop_setattr_args /* { 385 struct vnode *a_vp; 386 struct vattr *a_vap; 387 struct ucred *a_cred; 388 } */ *ap; 389 { 390 struct vattr *vap = ap->a_vap; 391 struct vnode *vp = ap->a_vp; 392 struct inode *ip = VTOI(vp); 393 struct ucred *cred = ap->a_cred; 394 struct thread *td = curthread; 395 int error; 396 397 /* 398 * Check for unsettable attributes. 399 */ 400 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) || 401 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) || 402 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) || 403 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) { 404 return (EINVAL); 405 } 406 if (vap->va_flags != VNOVAL) { 407 /* Disallow flags not supported by ext2fs. */ 408 if(vap->va_flags & ~(SF_APPEND | SF_IMMUTABLE | UF_NODUMP)) 409 return (EOPNOTSUPP); 410 411 if (vp->v_mount->mnt_flag & MNT_RDONLY) 412 return (EROFS); 413 /* 414 * Callers may only modify the file flags on objects they 415 * have VADMIN rights for. 416 */ 417 if ((error = VOP_ACCESS(vp, VADMIN, cred, td))) 418 return (error); 419 /* 420 * Unprivileged processes and privileged processes in 421 * jail() are not permitted to unset system flags, or 422 * modify flags if any system flags are set. 423 * Privileged non-jail processes may not modify system flags 424 * if securelevel > 0 and any existing system flags are set. 425 */ 426 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) { 427 if (ip->i_flags 428 & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) { 429 error = securelevel_gt(cred, 0); 430 if (error) 431 return (error); 432 } 433 ip->i_flags = vap->va_flags; 434 } else { 435 if (ip->i_flags 436 & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) || 437 (vap->va_flags & UF_SETTABLE) != vap->va_flags) 438 return (EPERM); 439 ip->i_flags &= SF_SETTABLE; 440 ip->i_flags |= (vap->va_flags & UF_SETTABLE); 441 } 442 ip->i_flag |= IN_CHANGE; 443 if (vap->va_flags & (IMMUTABLE | APPEND)) 444 return (0); 445 } 446 if (ip->i_flags & (IMMUTABLE | APPEND)) 447 return (EPERM); 448 /* 449 * Go through the fields and update iff not VNOVAL. 450 */ 451 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) { 452 if (vp->v_mount->mnt_flag & MNT_RDONLY) 453 return (EROFS); 454 if ((error = ext2_chown(vp, vap->va_uid, vap->va_gid, cred, 455 td)) != 0) 456 return (error); 457 } 458 if (vap->va_size != VNOVAL) { 459 /* 460 * Disallow write attempts on read-only file systems; 461 * unless the file is a socket, fifo, or a block or 462 * character device resident on the file system. 463 */ 464 switch (vp->v_type) { 465 case VDIR: 466 return (EISDIR); 467 case VLNK: 468 case VREG: 469 if (vp->v_mount->mnt_flag & MNT_RDONLY) 470 return (EROFS); 471 break; 472 default: 473 break; 474 } 475 if ((error = ext2_truncate(vp, vap->va_size, 0, cred, td)) != 0) 476 return (error); 477 } 478 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) { 479 if (vp->v_mount->mnt_flag & MNT_RDONLY) 480 return (EROFS); 481 /* 482 * From utimes(2): 483 * If times is NULL, ... The caller must be the owner of 484 * the file, have permission to write the file, or be the 485 * super-user. 486 * If times is non-NULL, ... The caller must be the owner of 487 * the file or be the super-user. 488 */ 489 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)) && 490 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 || 491 (error = VOP_ACCESS(vp, VWRITE, cred, td)))) 492 return (error); 493 if (vap->va_atime.tv_sec != VNOVAL) 494 ip->i_flag |= IN_ACCESS; 495 if (vap->va_mtime.tv_sec != VNOVAL) 496 ip->i_flag |= IN_CHANGE | IN_UPDATE; 497 ext2_itimes(vp); 498 if (vap->va_atime.tv_sec != VNOVAL) { 499 ip->i_atime = vap->va_atime.tv_sec; 500 ip->i_atimensec = vap->va_atime.tv_nsec; 501 } 502 if (vap->va_mtime.tv_sec != VNOVAL) { 503 ip->i_mtime = vap->va_mtime.tv_sec; 504 ip->i_mtimensec = vap->va_mtime.tv_nsec; 505 } 506 ip->i_birthtime = vap->va_birthtime.tv_sec; 507 ip->i_birthnsec = vap->va_birthtime.tv_nsec; 508 error = ext2_update(vp, 0); 509 if (error) 510 return (error); 511 } 512 error = 0; 513 if (vap->va_mode != (mode_t)VNOVAL) { 514 if (vp->v_mount->mnt_flag & MNT_RDONLY) 515 return (EROFS); 516 error = ext2_chmod(vp, (int)vap->va_mode, cred, td); 517 } 518 return (error); 519 } 520 521 /* 522 * Change the mode on a file. 523 * Inode must be locked before calling. 524 */ 525 static int 526 ext2_chmod(vp, mode, cred, td) 527 struct vnode *vp; 528 int mode; 529 struct ucred *cred; 530 struct thread *td; 531 { 532 struct inode *ip = VTOI(vp); 533 int error; 534 535 /* 536 * To modify the permissions on a file, must possess VADMIN 537 * for that file. 538 */ 539 if ((error = VOP_ACCESS(vp, VADMIN, cred, td))) 540 return (error); 541 /* 542 * Privileged processes may set the sticky bit on non-directories, 543 * as well as set the setgid bit on a file with a group that the 544 * process is not a member of. 545 */ 546 if (vp->v_type != VDIR && (mode & S_ISTXT)) { 547 error = priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0); 548 if (error) 549 return (EFTYPE); 550 } 551 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) { 552 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0); 553 if (error) 554 return (error); 555 } 556 ip->i_mode &= ~ALLPERMS; 557 ip->i_mode |= (mode & ALLPERMS); 558 ip->i_flag |= IN_CHANGE; 559 return (0); 560 } 561 562 /* 563 * Perform chown operation on inode ip; 564 * inode must be locked prior to call. 565 */ 566 static int 567 ext2_chown(vp, uid, gid, cred, td) 568 struct vnode *vp; 569 uid_t uid; 570 gid_t gid; 571 struct ucred *cred; 572 struct thread *td; 573 { 574 struct inode *ip = VTOI(vp); 575 uid_t ouid; 576 gid_t ogid; 577 int error = 0; 578 579 if (uid == (uid_t)VNOVAL) 580 uid = ip->i_uid; 581 if (gid == (gid_t)VNOVAL) 582 gid = ip->i_gid; 583 /* 584 * To modify the ownership of a file, must possess VADMIN 585 * for that file. 586 */ 587 if ((error = VOP_ACCESS(vp, VADMIN, cred, td))) 588 return (error); 589 /* 590 * To change the owner of a file, or change the group of a file 591 * to a group of which we are not a member, the caller must 592 * have privilege. 593 */ 594 if (uid != ip->i_uid || (gid != ip->i_gid && 595 !groupmember(gid, cred))) { 596 error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0); 597 if (error) 598 return (error); 599 } 600 ogid = ip->i_gid; 601 ouid = ip->i_uid; 602 ip->i_gid = gid; 603 ip->i_uid = uid; 604 ip->i_flag |= IN_CHANGE; 605 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) { 606 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0) != 0) 607 ip->i_mode &= ~(ISUID | ISGID); 608 } 609 return (0); 610 } 611 612 /* 613 * Synch an open file. 614 */ 615 /* ARGSUSED */ 616 static int 617 ext2_fsync(ap) 618 struct vop_fsync_args /* { 619 struct vnode *a_vp; 620 struct ucred *a_cred; 621 int a_waitfor; 622 struct thread *a_td; 623 } */ *ap; 624 { 625 /* 626 * Flush all dirty buffers associated with a vnode. 627 */ 628 629 vop_stdfsync(ap); 630 631 return (ext2_update(ap->a_vp, ap->a_waitfor == MNT_WAIT)); 632 } 633 634 /* 635 * Mknod vnode call 636 */ 637 /* ARGSUSED */ 638 static int 639 ext2_mknod(ap) 640 struct vop_mknod_args /* { 641 struct vnode *a_dvp; 642 struct vnode **a_vpp; 643 struct componentname *a_cnp; 644 struct vattr *a_vap; 645 } */ *ap; 646 { 647 struct vattr *vap = ap->a_vap; 648 struct vnode **vpp = ap->a_vpp; 649 struct inode *ip; 650 ino_t ino; 651 int error; 652 653 error = ext2_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), 654 ap->a_dvp, vpp, ap->a_cnp); 655 if (error) 656 return (error); 657 ip = VTOI(*vpp); 658 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE; 659 if (vap->va_rdev != VNOVAL) { 660 /* 661 * Want to be able to use this to make badblock 662 * inodes, so don't truncate the dev number. 663 */ 664 ip->i_rdev = vap->va_rdev; 665 } 666 /* 667 * Remove inode, then reload it through VFS_VGET so it is 668 * checked to see if it is an alias of an existing entry in 669 * the inode cache. XXX I don't believe this is necessary now. 670 */ 671 (*vpp)->v_type = VNON; 672 ino = ip->i_number; /* Save this before vgone() invalidates ip. */ 673 vgone(*vpp); 674 vput(*vpp); 675 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp); 676 if (error) { 677 *vpp = NULL; 678 return (error); 679 } 680 return (0); 681 } 682 683 static int 684 ext2_remove(ap) 685 struct vop_remove_args /* { 686 struct vnode *a_dvp; 687 struct vnode *a_vp; 688 struct componentname *a_cnp; 689 } */ *ap; 690 { 691 struct inode *ip; 692 struct vnode *vp = ap->a_vp; 693 struct vnode *dvp = ap->a_dvp; 694 int error; 695 696 ip = VTOI(vp); 697 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) || 698 (VTOI(dvp)->i_flags & APPEND)) { 699 error = EPERM; 700 goto out; 701 } 702 error = ext2_dirremove(dvp, ap->a_cnp); 703 if (error == 0) { 704 ip->i_nlink--; 705 ip->i_flag |= IN_CHANGE; 706 } 707 out: 708 return (error); 709 } 710 711 /* 712 * link vnode call 713 */ 714 static int 715 ext2_link(ap) 716 struct vop_link_args /* { 717 struct vnode *a_tdvp; 718 struct vnode *a_vp; 719 struct componentname *a_cnp; 720 } */ *ap; 721 { 722 struct vnode *vp = ap->a_vp; 723 struct vnode *tdvp = ap->a_tdvp; 724 struct componentname *cnp = ap->a_cnp; 725 struct inode *ip; 726 int error; 727 728 #ifdef DIAGNOSTIC 729 if ((cnp->cn_flags & HASBUF) == 0) 730 panic("ext2_link: no name"); 731 #endif 732 if (tdvp->v_mount != vp->v_mount) { 733 error = EXDEV; 734 goto out; 735 } 736 ip = VTOI(vp); 737 if ((nlink_t)ip->i_nlink >= LINK_MAX) { 738 error = EMLINK; 739 goto out; 740 } 741 if (ip->i_flags & (IMMUTABLE | APPEND)) { 742 error = EPERM; 743 goto out; 744 } 745 ip->i_nlink++; 746 ip->i_flag |= IN_CHANGE; 747 error = ext2_update(vp, !DOINGASYNC(vp)); 748 if (!error) 749 error = ext2_direnter(ip, tdvp, cnp); 750 if (error) { 751 ip->i_nlink--; 752 ip->i_flag |= IN_CHANGE; 753 } 754 out: 755 return (error); 756 } 757 758 /* 759 * Rename system call. 760 * rename("foo", "bar"); 761 * is essentially 762 * unlink("bar"); 763 * link("foo", "bar"); 764 * unlink("foo"); 765 * but ``atomically''. Can't do full commit without saving state in the 766 * inode on disk which isn't feasible at this time. Best we can do is 767 * always guarantee the target exists. 768 * 769 * Basic algorithm is: 770 * 771 * 1) Bump link count on source while we're linking it to the 772 * target. This also ensure the inode won't be deleted out 773 * from underneath us while we work (it may be truncated by 774 * a concurrent `trunc' or `open' for creation). 775 * 2) Link source to destination. If destination already exists, 776 * delete it first. 777 * 3) Unlink source reference to inode if still around. If a 778 * directory was moved and the parent of the destination 779 * is different from the source, patch the ".." entry in the 780 * directory. 781 */ 782 static int 783 ext2_rename(ap) 784 struct vop_rename_args /* { 785 struct vnode *a_fdvp; 786 struct vnode *a_fvp; 787 struct componentname *a_fcnp; 788 struct vnode *a_tdvp; 789 struct vnode *a_tvp; 790 struct componentname *a_tcnp; 791 } */ *ap; 792 { 793 struct vnode *tvp = ap->a_tvp; 794 struct vnode *tdvp = ap->a_tdvp; 795 struct vnode *fvp = ap->a_fvp; 796 struct vnode *fdvp = ap->a_fdvp; 797 struct componentname *tcnp = ap->a_tcnp; 798 struct componentname *fcnp = ap->a_fcnp; 799 struct inode *ip, *xp, *dp; 800 struct dirtemplate dirbuf; 801 int doingdirectory = 0, oldparent = 0, newparent = 0; 802 int error = 0; 803 u_char namlen; 804 805 #ifdef DIAGNOSTIC 806 if ((tcnp->cn_flags & HASBUF) == 0 || 807 (fcnp->cn_flags & HASBUF) == 0) 808 panic("ext2_rename: no name"); 809 #endif 810 /* 811 * Check for cross-device rename. 812 */ 813 if ((fvp->v_mount != tdvp->v_mount) || 814 (tvp && (fvp->v_mount != tvp->v_mount))) { 815 error = EXDEV; 816 abortit: 817 if (tdvp == tvp) 818 vrele(tdvp); 819 else 820 vput(tdvp); 821 if (tvp) 822 vput(tvp); 823 vrele(fdvp); 824 vrele(fvp); 825 return (error); 826 } 827 828 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) || 829 (VTOI(tdvp)->i_flags & APPEND))) { 830 error = EPERM; 831 goto abortit; 832 } 833 834 /* 835 * Renaming a file to itself has no effect. The upper layers should 836 * not call us in that case. Temporarily just warn if they do. 837 */ 838 if (fvp == tvp) { 839 printf("ext2_rename: fvp == tvp (can't happen)\n"); 840 error = 0; 841 goto abortit; 842 } 843 844 if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0) 845 goto abortit; 846 dp = VTOI(fdvp); 847 ip = VTOI(fvp); 848 if (ip->i_nlink >= LINK_MAX) { 849 VOP_UNLOCK(fvp, 0); 850 error = EMLINK; 851 goto abortit; 852 } 853 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) 854 || (dp->i_flags & APPEND)) { 855 VOP_UNLOCK(fvp, 0); 856 error = EPERM; 857 goto abortit; 858 } 859 if ((ip->i_mode & IFMT) == IFDIR) { 860 /* 861 * Avoid ".", "..", and aliases of "." for obvious reasons. 862 */ 863 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') || 864 dp == ip || (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT || 865 (ip->i_flag & IN_RENAME)) { 866 VOP_UNLOCK(fvp, 0); 867 error = EINVAL; 868 goto abortit; 869 } 870 ip->i_flag |= IN_RENAME; 871 oldparent = dp->i_number; 872 doingdirectory++; 873 } 874 vrele(fdvp); 875 876 /* 877 * When the target exists, both the directory 878 * and target vnodes are returned locked. 879 */ 880 dp = VTOI(tdvp); 881 xp = NULL; 882 if (tvp) 883 xp = VTOI(tvp); 884 885 /* 886 * 1) Bump link count while we're moving stuff 887 * around. If we crash somewhere before 888 * completing our work, the link count 889 * may be wrong, but correctable. 890 */ 891 ip->i_nlink++; 892 ip->i_flag |= IN_CHANGE; 893 if ((error = ext2_update(fvp, !DOINGASYNC(fvp))) != 0) { 894 VOP_UNLOCK(fvp, 0); 895 goto bad; 896 } 897 898 /* 899 * If ".." must be changed (ie the directory gets a new 900 * parent) then the source directory must not be in the 901 * directory hierarchy above the target, as this would 902 * orphan everything below the source directory. Also 903 * the user must have write permission in the source so 904 * as to be able to change "..". We must repeat the call 905 * to namei, as the parent directory is unlocked by the 906 * call to checkpath(). 907 */ 908 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread); 909 VOP_UNLOCK(fvp, 0); 910 if (oldparent != dp->i_number) 911 newparent = dp->i_number; 912 if (doingdirectory && newparent) { 913 if (error) /* write access check above */ 914 goto bad; 915 if (xp != NULL) 916 vput(tvp); 917 error = ext2_checkpath(ip, dp, tcnp->cn_cred); 918 if (error) 919 goto out; 920 VREF(tdvp); 921 error = relookup(tdvp, &tvp, tcnp); 922 if (error) 923 goto out; 924 vrele(tdvp); 925 dp = VTOI(tdvp); 926 xp = NULL; 927 if (tvp) 928 xp = VTOI(tvp); 929 } 930 /* 931 * 2) If target doesn't exist, link the target 932 * to the source and unlink the source. 933 * Otherwise, rewrite the target directory 934 * entry to reference the source inode and 935 * expunge the original entry's existence. 936 */ 937 if (xp == NULL) { 938 if (dp->i_devvp != ip->i_devvp) 939 panic("ext2_rename: EXDEV"); 940 /* 941 * Account for ".." in new directory. 942 * When source and destination have the same 943 * parent we don't fool with the link count. 944 */ 945 if (doingdirectory && newparent) { 946 if ((nlink_t)dp->i_nlink >= LINK_MAX) { 947 error = EMLINK; 948 goto bad; 949 } 950 dp->i_nlink++; 951 dp->i_flag |= IN_CHANGE; 952 error = ext2_update(tdvp, !DOINGASYNC(tdvp)); 953 if (error) 954 goto bad; 955 } 956 error = ext2_direnter(ip, tdvp, tcnp); 957 if (error) { 958 if (doingdirectory && newparent) { 959 dp->i_nlink--; 960 dp->i_flag |= IN_CHANGE; 961 (void)ext2_update(tdvp, 1); 962 } 963 goto bad; 964 } 965 vput(tdvp); 966 } else { 967 if (xp->i_devvp != dp->i_devvp || xp->i_devvp != ip->i_devvp) 968 panic("ext2_rename: EXDEV"); 969 /* 970 * Short circuit rename(foo, foo). 971 */ 972 if (xp->i_number == ip->i_number) 973 panic("ext2_rename: same file"); 974 /* 975 * If the parent directory is "sticky", then the user must 976 * own the parent directory, or the destination of the rename, 977 * otherwise the destination may not be changed (except by 978 * root). This implements append-only directories. 979 */ 980 if ((dp->i_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 && 981 tcnp->cn_cred->cr_uid != dp->i_uid && 982 xp->i_uid != tcnp->cn_cred->cr_uid) { 983 error = EPERM; 984 goto bad; 985 } 986 /* 987 * Target must be empty if a directory and have no links 988 * to it. Also, ensure source and target are compatible 989 * (both directories, or both not directories). 990 */ 991 if ((xp->i_mode&IFMT) == IFDIR) { 992 if (! ext2_dirempty(xp, dp->i_number, tcnp->cn_cred) || 993 xp->i_nlink > 2) { 994 error = ENOTEMPTY; 995 goto bad; 996 } 997 if (!doingdirectory) { 998 error = ENOTDIR; 999 goto bad; 1000 } 1001 cache_purge(tdvp); 1002 } else if (doingdirectory) { 1003 error = EISDIR; 1004 goto bad; 1005 } 1006 error = ext2_dirrewrite(dp, ip, tcnp); 1007 if (error) 1008 goto bad; 1009 /* 1010 * If the target directory is in the same 1011 * directory as the source directory, 1012 * decrement the link count on the parent 1013 * of the target directory. 1014 */ 1015 if (doingdirectory && !newparent) { 1016 dp->i_nlink--; 1017 dp->i_flag |= IN_CHANGE; 1018 } 1019 vput(tdvp); 1020 /* 1021 * Adjust the link count of the target to 1022 * reflect the dirrewrite above. If this is 1023 * a directory it is empty and there are 1024 * no links to it, so we can squash the inode and 1025 * any space associated with it. We disallowed 1026 * renaming over top of a directory with links to 1027 * it above, as the remaining link would point to 1028 * a directory without "." or ".." entries. 1029 */ 1030 xp->i_nlink--; 1031 if (doingdirectory) { 1032 if (--xp->i_nlink != 0) 1033 panic("ext2_rename: linked directory"); 1034 error = ext2_truncate(tvp, (off_t)0, IO_SYNC, 1035 tcnp->cn_cred, tcnp->cn_thread); 1036 } 1037 xp->i_flag |= IN_CHANGE; 1038 vput(tvp); 1039 xp = NULL; 1040 } 1041 1042 /* 1043 * 3) Unlink the source. 1044 */ 1045 fcnp->cn_flags &= ~MODMASK; 1046 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF; 1047 VREF(fdvp); 1048 error = relookup(fdvp, &fvp, fcnp); 1049 if (error == 0) 1050 vrele(fdvp); 1051 if (fvp != NULL) { 1052 xp = VTOI(fvp); 1053 dp = VTOI(fdvp); 1054 } else { 1055 /* 1056 * From name has disappeared. 1057 */ 1058 if (doingdirectory) 1059 panic("ext2_rename: lost dir entry"); 1060 vrele(ap->a_fvp); 1061 return (0); 1062 } 1063 /* 1064 * Ensure that the directory entry still exists and has not 1065 * changed while the new name has been entered. If the source is 1066 * a file then the entry may have been unlinked or renamed. In 1067 * either case there is no further work to be done. If the source 1068 * is a directory then it cannot have been rmdir'ed; its link 1069 * count of three would cause a rmdir to fail with ENOTEMPTY. 1070 * The IN_RENAME flag ensures that it cannot be moved by another 1071 * rename. 1072 */ 1073 if (xp != ip) { 1074 if (doingdirectory) 1075 panic("ext2_rename: lost dir entry"); 1076 } else { 1077 /* 1078 * If the source is a directory with a 1079 * new parent, the link count of the old 1080 * parent directory must be decremented 1081 * and ".." set to point to the new parent. 1082 */ 1083 if (doingdirectory && newparent) { 1084 dp->i_nlink--; 1085 dp->i_flag |= IN_CHANGE; 1086 error = vn_rdwr(UIO_READ, fvp, (caddr_t)&dirbuf, 1087 sizeof(struct dirtemplate), (off_t)0, 1088 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK, 1089 tcnp->cn_cred, NOCRED, NULL, NULL); 1090 if (error == 0) { 1091 /* Like ufs little-endian: */ 1092 namlen = dirbuf.dotdot_type; 1093 if (namlen != 2 || 1094 dirbuf.dotdot_name[0] != '.' || 1095 dirbuf.dotdot_name[1] != '.') { 1096 ext2_dirbad(xp, (doff_t)12, 1097 "rename: mangled dir"); 1098 } else { 1099 dirbuf.dotdot_ino = newparent; 1100 (void) vn_rdwr(UIO_WRITE, fvp, 1101 (caddr_t)&dirbuf, 1102 sizeof(struct dirtemplate), 1103 (off_t)0, UIO_SYSSPACE, 1104 IO_NODELOCKED | IO_SYNC | 1105 IO_NOMACCHECK, tcnp->cn_cred, 1106 NOCRED, NULL, NULL); 1107 cache_purge(fdvp); 1108 } 1109 } 1110 } 1111 error = ext2_dirremove(fdvp, fcnp); 1112 if (!error) { 1113 xp->i_nlink--; 1114 xp->i_flag |= IN_CHANGE; 1115 } 1116 xp->i_flag &= ~IN_RENAME; 1117 } 1118 if (dp) 1119 vput(fdvp); 1120 if (xp) 1121 vput(fvp); 1122 vrele(ap->a_fvp); 1123 return (error); 1124 1125 bad: 1126 if (xp) 1127 vput(ITOV(xp)); 1128 vput(ITOV(dp)); 1129 out: 1130 if (doingdirectory) 1131 ip->i_flag &= ~IN_RENAME; 1132 if (vn_lock(fvp, LK_EXCLUSIVE) == 0) { 1133 ip->i_nlink--; 1134 ip->i_flag |= IN_CHANGE; 1135 ip->i_flag &= ~IN_RENAME; 1136 vput(fvp); 1137 } else 1138 vrele(fvp); 1139 return (error); 1140 } 1141 1142 /* 1143 * Mkdir system call 1144 */ 1145 static int 1146 ext2_mkdir(ap) 1147 struct vop_mkdir_args /* { 1148 struct vnode *a_dvp; 1149 struct vnode **a_vpp; 1150 struct componentname *a_cnp; 1151 struct vattr *a_vap; 1152 } */ *ap; 1153 { 1154 struct vnode *dvp = ap->a_dvp; 1155 struct vattr *vap = ap->a_vap; 1156 struct componentname *cnp = ap->a_cnp; 1157 struct inode *ip, *dp; 1158 struct vnode *tvp; 1159 struct dirtemplate dirtemplate, *dtp; 1160 int error, dmode; 1161 1162 #ifdef DIAGNOSTIC 1163 if ((cnp->cn_flags & HASBUF) == 0) 1164 panic("ext2_mkdir: no name"); 1165 #endif 1166 dp = VTOI(dvp); 1167 if ((nlink_t)dp->i_nlink >= LINK_MAX) { 1168 error = EMLINK; 1169 goto out; 1170 } 1171 dmode = vap->va_mode & 0777; 1172 dmode |= IFDIR; 1173 /* 1174 * Must simulate part of ext2_makeinode here to acquire the inode, 1175 * but not have it entered in the parent directory. The entry is 1176 * made later after writing "." and ".." entries. 1177 */ 1178 error = ext2_valloc(dvp, dmode, cnp->cn_cred, &tvp); 1179 if (error) 1180 goto out; 1181 ip = VTOI(tvp); 1182 ip->i_gid = dp->i_gid; 1183 #ifdef SUIDDIR 1184 { 1185 /* 1186 * if we are hacking owners here, (only do this where told to) 1187 * and we are not giving it TOO root, (would subvert quotas) 1188 * then go ahead and give it to the other user. 1189 * The new directory also inherits the SUID bit. 1190 * If user's UID and dir UID are the same, 1191 * 'give it away' so that the SUID is still forced on. 1192 */ 1193 if ( (dvp->v_mount->mnt_flag & MNT_SUIDDIR) && 1194 (dp->i_mode & ISUID) && dp->i_uid) { 1195 dmode |= ISUID; 1196 ip->i_uid = dp->i_uid; 1197 } else { 1198 ip->i_uid = cnp->cn_cred->cr_uid; 1199 } 1200 } 1201 #else 1202 ip->i_uid = cnp->cn_cred->cr_uid; 1203 #endif 1204 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE; 1205 ip->i_mode = dmode; 1206 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */ 1207 ip->i_nlink = 2; 1208 if (cnp->cn_flags & ISWHITEOUT) 1209 ip->i_flags |= UF_OPAQUE; 1210 error = ext2_update(tvp, 1); 1211 1212 /* 1213 * Bump link count in parent directory 1214 * to reflect work done below. Should 1215 * be done before reference is created 1216 * so reparation is possible if we crash. 1217 */ 1218 dp->i_nlink++; 1219 dp->i_flag |= IN_CHANGE; 1220 error = ext2_update(dvp, !DOINGASYNC(dvp)); 1221 if (error) 1222 goto bad; 1223 1224 /* Initialize directory with "." and ".." from static template. */ 1225 if (EXT2_HAS_INCOMPAT_FEATURE(ip->i_e2fs, 1226 EXT2F_INCOMPAT_FTYPE)) 1227 dtp = &mastertemplate; 1228 else 1229 dtp = &omastertemplate; 1230 dirtemplate = *dtp; 1231 dirtemplate.dot_ino = ip->i_number; 1232 dirtemplate.dotdot_ino = dp->i_number; 1233 /* note that in ext2 DIRBLKSIZ == blocksize, not DEV_BSIZE 1234 * so let's just redefine it - for this function only 1235 */ 1236 #undef DIRBLKSIZ 1237 #define DIRBLKSIZ VTOI(dvp)->i_e2fs->e2fs_bsize 1238 dirtemplate.dotdot_reclen = DIRBLKSIZ - 12; 1239 error = vn_rdwr(UIO_WRITE, tvp, (caddr_t)&dirtemplate, 1240 sizeof(dirtemplate), (off_t)0, UIO_SYSSPACE, 1241 IO_NODELOCKED | IO_SYNC | IO_NOMACCHECK, cnp->cn_cred, NOCRED, 1242 NULL, NULL); 1243 if (error) { 1244 dp->i_nlink--; 1245 dp->i_flag |= IN_CHANGE; 1246 goto bad; 1247 } 1248 if (DIRBLKSIZ > VFSTOEXT2(dvp->v_mount)->um_mountp->mnt_stat.f_bsize) 1249 /* XXX should grow with balloc() */ 1250 panic("ext2_mkdir: blksize"); 1251 else { 1252 ip->i_size = DIRBLKSIZ; 1253 ip->i_flag |= IN_CHANGE; 1254 } 1255 1256 /* Directory set up, now install its entry in the parent directory. */ 1257 error = ext2_direnter(ip, dvp, cnp); 1258 if (error) { 1259 dp->i_nlink--; 1260 dp->i_flag |= IN_CHANGE; 1261 } 1262 bad: 1263 /* 1264 * No need to do an explicit VOP_TRUNCATE here, vrele will do this 1265 * for us because we set the link count to 0. 1266 */ 1267 if (error) { 1268 ip->i_nlink = 0; 1269 ip->i_flag |= IN_CHANGE; 1270 vput(tvp); 1271 } else 1272 *ap->a_vpp = tvp; 1273 out: 1274 return (error); 1275 #undef DIRBLKSIZ 1276 #define DIRBLKSIZ DEV_BSIZE 1277 } 1278 1279 /* 1280 * Rmdir system call. 1281 */ 1282 static int 1283 ext2_rmdir(ap) 1284 struct vop_rmdir_args /* { 1285 struct vnode *a_dvp; 1286 struct vnode *a_vp; 1287 struct componentname *a_cnp; 1288 } */ *ap; 1289 { 1290 struct vnode *vp = ap->a_vp; 1291 struct vnode *dvp = ap->a_dvp; 1292 struct componentname *cnp = ap->a_cnp; 1293 struct inode *ip, *dp; 1294 int error; 1295 1296 ip = VTOI(vp); 1297 dp = VTOI(dvp); 1298 1299 /* 1300 * Verify the directory is empty (and valid). 1301 * (Rmdir ".." won't be valid since 1302 * ".." will contain a reference to 1303 * the current directory and thus be 1304 * non-empty.) 1305 */ 1306 error = 0; 1307 if (ip->i_nlink != 2 || !ext2_dirempty(ip, dp->i_number, cnp->cn_cred)) { 1308 error = ENOTEMPTY; 1309 goto out; 1310 } 1311 if ((dp->i_flags & APPEND) 1312 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) { 1313 error = EPERM; 1314 goto out; 1315 } 1316 /* 1317 * Delete reference to directory before purging 1318 * inode. If we crash in between, the directory 1319 * will be reattached to lost+found, 1320 */ 1321 error = ext2_dirremove(dvp, cnp); 1322 if (error) 1323 goto out; 1324 dp->i_nlink--; 1325 dp->i_flag |= IN_CHANGE; 1326 cache_purge(dvp); 1327 VOP_UNLOCK(dvp, 0); 1328 /* 1329 * Truncate inode. The only stuff left 1330 * in the directory is "." and "..". The 1331 * "." reference is inconsequential since 1332 * we're quashing it. The ".." reference 1333 * has already been adjusted above. We've 1334 * removed the "." reference and the reference 1335 * in the parent directory, but there may be 1336 * other hard links so decrement by 2 and 1337 * worry about them later. 1338 */ 1339 ip->i_nlink -= 2; 1340 error = ext2_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred, 1341 cnp->cn_thread); 1342 cache_purge(ITOV(ip)); 1343 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); 1344 out: 1345 return (error); 1346 } 1347 1348 /* 1349 * symlink -- make a symbolic link 1350 */ 1351 static int 1352 ext2_symlink(ap) 1353 struct vop_symlink_args /* { 1354 struct vnode *a_dvp; 1355 struct vnode **a_vpp; 1356 struct componentname *a_cnp; 1357 struct vattr *a_vap; 1358 char *a_target; 1359 } */ *ap; 1360 { 1361 struct vnode *vp, **vpp = ap->a_vpp; 1362 struct inode *ip; 1363 int len, error; 1364 1365 error = ext2_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp, 1366 vpp, ap->a_cnp); 1367 if (error) 1368 return (error); 1369 vp = *vpp; 1370 len = strlen(ap->a_target); 1371 if (len < vp->v_mount->mnt_maxsymlinklen) { 1372 ip = VTOI(vp); 1373 bcopy(ap->a_target, (char *)ip->i_shortlink, len); 1374 ip->i_size = len; 1375 ip->i_flag |= IN_CHANGE | IN_UPDATE; 1376 } else 1377 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0, 1378 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK, 1379 ap->a_cnp->cn_cred, NOCRED, NULL, NULL); 1380 if (error) 1381 vput(vp); 1382 return (error); 1383 } 1384 1385 /* 1386 * Return target name of a symbolic link 1387 */ 1388 static int 1389 ext2_readlink(ap) 1390 struct vop_readlink_args /* { 1391 struct vnode *a_vp; 1392 struct uio *a_uio; 1393 struct ucred *a_cred; 1394 } */ *ap; 1395 { 1396 struct vnode *vp = ap->a_vp; 1397 struct inode *ip = VTOI(vp); 1398 int isize; 1399 1400 isize = ip->i_size; 1401 if (isize < vp->v_mount->mnt_maxsymlinklen) { 1402 uiomove((char *)ip->i_shortlink, isize, ap->a_uio); 1403 return (0); 1404 } 1405 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred)); 1406 } 1407 1408 /* 1409 * Calculate the logical to physical mapping if not done already, 1410 * then call the device strategy routine. 1411 * 1412 * In order to be able to swap to a file, the ext2_bmaparray() operation may not 1413 * deadlock on memory. See ext2_bmap() for details. 1414 */ 1415 static int 1416 ext2_strategy(ap) 1417 struct vop_strategy_args /* { 1418 struct vnode *a_vp; 1419 struct buf *a_bp; 1420 } */ *ap; 1421 { 1422 struct buf *bp = ap->a_bp; 1423 struct vnode *vp = ap->a_vp; 1424 struct inode *ip; 1425 struct bufobj *bo; 1426 int32_t blkno; 1427 int error; 1428 1429 ip = VTOI(vp); 1430 if (vp->v_type == VBLK || vp->v_type == VCHR) 1431 panic("ext2_strategy: spec"); 1432 if (bp->b_blkno == bp->b_lblkno) { 1433 error = ext2_bmaparray(vp, bp->b_lblkno, &blkno, NULL, NULL); 1434 bp->b_blkno = blkno; 1435 if (error) { 1436 bp->b_error = error; 1437 bp->b_ioflags |= BIO_ERROR; 1438 bufdone(bp); 1439 return (0); 1440 } 1441 if ((long)bp->b_blkno == -1) 1442 vfs_bio_clrbuf(bp); 1443 } 1444 if ((long)bp->b_blkno == -1) { 1445 bufdone(bp); 1446 return (0); 1447 } 1448 bp->b_iooffset = dbtob(bp->b_blkno); 1449 bo = VFSTOEXT2(vp->v_mount)->um_bo; 1450 BO_STRATEGY(bo, bp); 1451 return (0); 1452 } 1453 1454 /* 1455 * Print out the contents of an inode. 1456 */ 1457 static int 1458 ext2_print(ap) 1459 struct vop_print_args /* { 1460 struct vnode *a_vp; 1461 } */ *ap; 1462 { 1463 struct vnode *vp = ap->a_vp; 1464 struct inode *ip = VTOI(vp); 1465 1466 vn_printf(ip->i_devvp, "\tino %lu", (u_long)ip->i_number); 1467 if (vp->v_type == VFIFO) 1468 fifo_printinfo(vp); 1469 printf("\n"); 1470 return (0); 1471 } 1472 1473 /* 1474 * Close wrapper for fifos. 1475 * 1476 * Update the times on the inode then do device close. 1477 */ 1478 static int 1479 ext2fifo_close(ap) 1480 struct vop_close_args /* { 1481 struct vnode *a_vp; 1482 int a_fflag; 1483 struct ucred *a_cred; 1484 struct thread *a_td; 1485 } */ *ap; 1486 { 1487 struct vnode *vp = ap->a_vp; 1488 1489 VI_LOCK(vp); 1490 if (vp->v_usecount > 1) 1491 ext2_itimes_locked(vp); 1492 VI_UNLOCK(vp); 1493 return (fifo_specops.vop_close(ap)); 1494 } 1495 1496 /* 1497 * Kqfilter wrapper for fifos. 1498 * 1499 * Fall through to ext2 kqfilter routines if needed 1500 */ 1501 static int 1502 ext2fifo_kqfilter(ap) 1503 struct vop_kqfilter_args *ap; 1504 { 1505 int error; 1506 1507 error = fifo_specops.vop_kqfilter(ap); 1508 if (error) 1509 error = vfs_kqfilter(ap); 1510 return (error); 1511 } 1512 1513 /* 1514 * Return POSIX pathconf information applicable to ext2 filesystems. 1515 */ 1516 static int 1517 ext2_pathconf(ap) 1518 struct vop_pathconf_args /* { 1519 struct vnode *a_vp; 1520 int a_name; 1521 int *a_retval; 1522 } */ *ap; 1523 { 1524 1525 switch (ap->a_name) { 1526 case _PC_LINK_MAX: 1527 *ap->a_retval = LINK_MAX; 1528 return (0); 1529 case _PC_NAME_MAX: 1530 *ap->a_retval = NAME_MAX; 1531 return (0); 1532 case _PC_PATH_MAX: 1533 *ap->a_retval = PATH_MAX; 1534 return (0); 1535 case _PC_PIPE_BUF: 1536 *ap->a_retval = PIPE_BUF; 1537 return (0); 1538 case _PC_CHOWN_RESTRICTED: 1539 *ap->a_retval = 1; 1540 return (0); 1541 case _PC_NO_TRUNC: 1542 *ap->a_retval = 1; 1543 return (0); 1544 default: 1545 return (EINVAL); 1546 } 1547 /* NOTREACHED */ 1548 } 1549 1550 /* 1551 * Vnode pointer to File handle 1552 */ 1553 /* ARGSUSED */ 1554 static int 1555 ext2_vptofh(ap) 1556 struct vop_vptofh_args /* { 1557 struct vnode *a_vp; 1558 struct fid *a_fhp; 1559 } */ *ap; 1560 { 1561 struct inode *ip; 1562 struct ufid *ufhp; 1563 1564 ip = VTOI(ap->a_vp); 1565 ufhp = (struct ufid *)ap->a_fhp; 1566 ufhp->ufid_len = sizeof(struct ufid); 1567 ufhp->ufid_ino = ip->i_number; 1568 ufhp->ufid_gen = ip->i_gen; 1569 return (0); 1570 } 1571 1572 /* 1573 * Initialize the vnode associated with a new inode, handle aliased 1574 * vnodes. 1575 */ 1576 int 1577 ext2_vinit(mntp, fifoops, vpp) 1578 struct mount *mntp; 1579 struct vop_vector *fifoops; 1580 struct vnode **vpp; 1581 { 1582 struct inode *ip; 1583 struct vnode *vp; 1584 1585 vp = *vpp; 1586 ip = VTOI(vp); 1587 vp->v_type = IFTOVT(ip->i_mode); 1588 if (vp->v_type == VFIFO) 1589 vp->v_op = fifoops; 1590 1591 if (ip->i_number == EXT2_ROOTINO) 1592 vp->v_vflag |= VV_ROOT; 1593 ip->i_modrev = init_va_filerev(); 1594 *vpp = vp; 1595 return (0); 1596 } 1597 1598 /* 1599 * Allocate a new inode. 1600 */ 1601 static int 1602 ext2_makeinode(mode, dvp, vpp, cnp) 1603 int mode; 1604 struct vnode *dvp; 1605 struct vnode **vpp; 1606 struct componentname *cnp; 1607 { 1608 struct inode *ip, *pdir; 1609 struct vnode *tvp; 1610 int error; 1611 1612 pdir = VTOI(dvp); 1613 #ifdef DIAGNOSTIC 1614 if ((cnp->cn_flags & HASBUF) == 0) 1615 panic("ext2_makeinode: no name"); 1616 #endif 1617 *vpp = NULL; 1618 if ((mode & IFMT) == 0) 1619 mode |= IFREG; 1620 1621 error = ext2_valloc(dvp, mode, cnp->cn_cred, &tvp); 1622 if (error) { 1623 return (error); 1624 } 1625 ip = VTOI(tvp); 1626 ip->i_gid = pdir->i_gid; 1627 #ifdef SUIDDIR 1628 { 1629 /* 1630 * if we are 1631 * not the owner of the directory, 1632 * and we are hacking owners here, (only do this where told to) 1633 * and we are not giving it TOO root, (would subvert quotas) 1634 * then go ahead and give it to the other user. 1635 * Note that this drops off the execute bits for security. 1636 */ 1637 if ( (dvp->v_mount->mnt_flag & MNT_SUIDDIR) && 1638 (pdir->i_mode & ISUID) && 1639 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) { 1640 ip->i_uid = pdir->i_uid; 1641 mode &= ~07111; 1642 } else { 1643 ip->i_uid = cnp->cn_cred->cr_uid; 1644 } 1645 } 1646 #else 1647 ip->i_uid = cnp->cn_cred->cr_uid; 1648 #endif 1649 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE; 1650 ip->i_mode = mode; 1651 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */ 1652 ip->i_nlink = 1; 1653 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred)) { 1654 if (priv_check_cred(cnp->cn_cred, PRIV_VFS_RETAINSUGID, 0)) 1655 ip->i_mode &= ~ISGID; 1656 } 1657 1658 if (cnp->cn_flags & ISWHITEOUT) 1659 ip->i_flags |= UF_OPAQUE; 1660 1661 /* 1662 * Make sure inode goes to disk before directory entry. 1663 */ 1664 error = ext2_update(tvp, !DOINGASYNC(tvp)); 1665 if (error) 1666 goto bad; 1667 error = ext2_direnter(ip, dvp, cnp); 1668 if (error) 1669 goto bad; 1670 1671 *vpp = tvp; 1672 return (0); 1673 1674 bad: 1675 /* 1676 * Write error occurred trying to update the inode 1677 * or the directory so must deallocate the inode. 1678 */ 1679 ip->i_nlink = 0; 1680 ip->i_flag |= IN_CHANGE; 1681 vput(tvp); 1682 return (error); 1683 } 1684 1685 /* 1686 * Vnode op for reading. 1687 */ 1688 static int 1689 ext2_read(ap) 1690 struct vop_read_args /* { 1691 struct vnode *a_vp; 1692 struct uio *a_uio; 1693 int a_ioflag; 1694 struct ucred *a_cred; 1695 } */ *ap; 1696 { 1697 struct vnode *vp; 1698 struct inode *ip; 1699 struct uio *uio; 1700 struct m_ext2fs *fs; 1701 struct buf *bp; 1702 daddr_t lbn, nextlbn; 1703 off_t bytesinfile; 1704 long size, xfersize, blkoffset; 1705 int error, orig_resid, seqcount; 1706 int ioflag; 1707 1708 vp = ap->a_vp; 1709 uio = ap->a_uio; 1710 ioflag = ap->a_ioflag; 1711 1712 seqcount = ap->a_ioflag >> IO_SEQSHIFT; 1713 ip = VTOI(vp); 1714 1715 #ifdef INVARIANTS 1716 if (uio->uio_rw != UIO_READ) 1717 panic("%s: mode", "ext2_read"); 1718 1719 if (vp->v_type == VLNK) { 1720 if ((int)ip->i_size < vp->v_mount->mnt_maxsymlinklen) 1721 panic("%s: short symlink", "ext2_read"); 1722 } else if (vp->v_type != VREG && vp->v_type != VDIR) 1723 panic("%s: type %d", "ext2_read", vp->v_type); 1724 #endif 1725 orig_resid = uio->uio_resid; 1726 KASSERT(orig_resid >= 0, ("ext2_read: uio->uio_resid < 0")); 1727 if (orig_resid == 0) 1728 return (0); 1729 KASSERT(uio->uio_offset >= 0, ("ext2_read: uio->uio_offset < 0")); 1730 fs = ip->i_e2fs; 1731 if (uio->uio_offset < ip->i_size && 1732 uio->uio_offset >= fs->e2fs_maxfilesize) 1733 return (EOVERFLOW); 1734 1735 for (error = 0, bp = NULL; uio->uio_resid > 0; bp = NULL) { 1736 if ((bytesinfile = ip->i_size - uio->uio_offset) <= 0) 1737 break; 1738 lbn = lblkno(fs, uio->uio_offset); 1739 nextlbn = lbn + 1; 1740 size = blksize(fs, ip, lbn); 1741 blkoffset = blkoff(fs, uio->uio_offset); 1742 1743 xfersize = fs->e2fs_fsize - blkoffset; 1744 if (uio->uio_resid < xfersize) 1745 xfersize = uio->uio_resid; 1746 if (bytesinfile < xfersize) 1747 xfersize = bytesinfile; 1748 1749 if (lblktosize(fs, nextlbn) >= ip->i_size) 1750 error = bread(vp, lbn, size, NOCRED, &bp); 1751 else if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) 1752 error = cluster_read(vp, ip->i_size, lbn, size, 1753 NOCRED, blkoffset + uio->uio_resid, seqcount, &bp); 1754 else if (seqcount > 1) { 1755 int nextsize = blksize(fs, ip, nextlbn); 1756 error = breadn(vp, lbn, 1757 size, &nextlbn, &nextsize, 1, NOCRED, &bp); 1758 } else 1759 error = bread(vp, lbn, size, NOCRED, &bp); 1760 if (error) { 1761 brelse(bp); 1762 bp = NULL; 1763 break; 1764 } 1765 1766 /* 1767 * If IO_DIRECT then set B_DIRECT for the buffer. This 1768 * will cause us to attempt to release the buffer later on 1769 * and will cause the buffer cache to attempt to free the 1770 * underlying pages. 1771 */ 1772 if (ioflag & IO_DIRECT) 1773 bp->b_flags |= B_DIRECT; 1774 1775 /* 1776 * We should only get non-zero b_resid when an I/O error 1777 * has occurred, which should cause us to break above. 1778 * However, if the short read did not cause an error, 1779 * then we want to ensure that we do not uiomove bad 1780 * or uninitialized data. 1781 */ 1782 size -= bp->b_resid; 1783 if (size < xfersize) { 1784 if (size == 0) 1785 break; 1786 xfersize = size; 1787 } 1788 error = uiomove((char *)bp->b_data + blkoffset, 1789 (int)xfersize, uio); 1790 if (error) 1791 break; 1792 1793 if (ioflag & (IO_VMIO|IO_DIRECT)) { 1794 /* 1795 * If it's VMIO or direct I/O, then we don't 1796 * need the buf, mark it available for 1797 * freeing. If it's non-direct VMIO, the VM has 1798 * the data. 1799 */ 1800 bp->b_flags |= B_RELBUF; 1801 brelse(bp); 1802 } else { 1803 /* 1804 * Otherwise let whoever 1805 * made the request take care of 1806 * freeing it. We just queue 1807 * it onto another list. 1808 */ 1809 bqrelse(bp); 1810 } 1811 } 1812 1813 /* 1814 * This can only happen in the case of an error 1815 * because the loop above resets bp to NULL on each iteration 1816 * and on normal completion has not set a new value into it. 1817 * so it must have come from a 'break' statement 1818 */ 1819 if (bp != NULL) { 1820 if (ioflag & (IO_VMIO|IO_DIRECT)) { 1821 bp->b_flags |= B_RELBUF; 1822 brelse(bp); 1823 } else { 1824 bqrelse(bp); 1825 } 1826 } 1827 1828 if ((error == 0 || uio->uio_resid != orig_resid) && 1829 (vp->v_mount->mnt_flag & MNT_NOATIME) == 0) 1830 ip->i_flag |= IN_ACCESS; 1831 return (error); 1832 } 1833 1834 /* 1835 * Vnode op for writing. 1836 */ 1837 static int 1838 ext2_write(ap) 1839 struct vop_write_args /* { 1840 struct vnode *a_vp; 1841 struct uio *a_uio; 1842 int a_ioflag; 1843 struct ucred *a_cred; 1844 } */ *ap; 1845 { 1846 struct vnode *vp; 1847 struct uio *uio; 1848 struct inode *ip; 1849 struct m_ext2fs *fs; 1850 struct buf *bp; 1851 daddr_t lbn; 1852 off_t osize; 1853 int blkoffset, error, flags, ioflag, resid, size, seqcount, xfersize; 1854 1855 ioflag = ap->a_ioflag; 1856 uio = ap->a_uio; 1857 vp = ap->a_vp; 1858 1859 seqcount = ioflag >> IO_SEQSHIFT; 1860 ip = VTOI(vp); 1861 1862 #ifdef INVARIANTS 1863 if (uio->uio_rw != UIO_WRITE) 1864 panic("%s: mode", "ext2_write"); 1865 #endif 1866 1867 switch (vp->v_type) { 1868 case VREG: 1869 if (ioflag & IO_APPEND) 1870 uio->uio_offset = ip->i_size; 1871 if ((ip->i_flags & APPEND) && uio->uio_offset != ip->i_size) 1872 return (EPERM); 1873 /* FALLTHROUGH */ 1874 case VLNK: 1875 break; 1876 case VDIR: 1877 /* XXX differs from ffs -- this is called from ext2_mkdir(). */ 1878 if ((ioflag & IO_SYNC) == 0) 1879 panic("ext2_write: nonsync dir write"); 1880 break; 1881 default: 1882 panic("ext2_write: type %p %d (%jd,%jd)", (void *)vp, 1883 vp->v_type, (intmax_t)uio->uio_offset, 1884 (intmax_t)uio->uio_resid); 1885 } 1886 1887 KASSERT(uio->uio_resid >= 0, ("ext2_write: uio->uio_resid < 0")); 1888 KASSERT(uio->uio_offset >= 0, ("ext2_write: uio->uio_offset < 0")); 1889 fs = ip->i_e2fs; 1890 if ((uoff_t)uio->uio_offset + uio->uio_resid > fs->e2fs_maxfilesize) 1891 return (EFBIG); 1892 /* 1893 * Maybe this should be above the vnode op call, but so long as 1894 * file servers have no limits, I don't think it matters. 1895 */ 1896 if (vn_rlimit_fsize(vp, uio, uio->uio_td)) 1897 return (EFBIG); 1898 1899 resid = uio->uio_resid; 1900 osize = ip->i_size; 1901 if (seqcount > BA_SEQMAX) 1902 flags = BA_SEQMAX << BA_SEQSHIFT; 1903 else 1904 flags = seqcount << BA_SEQSHIFT; 1905 if ((ioflag & IO_SYNC) && !DOINGASYNC(vp)) 1906 flags |= IO_SYNC; 1907 1908 for (error = 0; uio->uio_resid > 0;) { 1909 lbn = lblkno(fs, uio->uio_offset); 1910 blkoffset = blkoff(fs, uio->uio_offset); 1911 xfersize = fs->e2fs_fsize - blkoffset; 1912 if (uio->uio_resid < xfersize) 1913 xfersize = uio->uio_resid; 1914 if (uio->uio_offset + xfersize > ip->i_size) 1915 vnode_pager_setsize(vp, uio->uio_offset + xfersize); 1916 1917 /* 1918 * We must perform a read-before-write if the transfer size 1919 * does not cover the entire buffer. 1920 */ 1921 if (fs->e2fs_bsize > xfersize) 1922 flags |= BA_CLRBUF; 1923 else 1924 flags &= ~BA_CLRBUF; 1925 error = ext2_balloc(ip, lbn, blkoffset + xfersize, 1926 ap->a_cred, &bp, flags); 1927 if (error != 0) 1928 break; 1929 1930 /* 1931 * If the buffer is not valid and we did not clear garbage 1932 * out above, we have to do so here even though the write 1933 * covers the entire buffer in order to avoid a mmap()/write 1934 * race where another process may see the garbage prior to 1935 * the uiomove() for a write replacing it. 1936 */ 1937 if ((bp->b_flags & B_CACHE) == 0 && fs->e2fs_bsize <= xfersize) 1938 vfs_bio_clrbuf(bp); 1939 if ((ioflag & (IO_SYNC|IO_INVAL)) == (IO_SYNC|IO_INVAL)) 1940 bp->b_flags |= B_NOCACHE; 1941 if (uio->uio_offset + xfersize > ip->i_size) 1942 ip->i_size = uio->uio_offset + xfersize; 1943 size = blksize(fs, ip, lbn) - bp->b_resid; 1944 if (size < xfersize) 1945 xfersize = size; 1946 1947 error = 1948 uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio); 1949 if (ioflag & (IO_VMIO|IO_DIRECT)) { 1950 bp->b_flags |= B_RELBUF; 1951 } 1952 1953 /* 1954 * If IO_SYNC each buffer is written synchronously. Otherwise 1955 * if we have a severe page deficiency write the buffer 1956 * asynchronously. Otherwise try to cluster, and if that 1957 * doesn't do it then either do an async write (if O_DIRECT), 1958 * or a delayed write (if not). 1959 */ 1960 if (ioflag & IO_SYNC) { 1961 (void)bwrite(bp); 1962 } else if (vm_page_count_severe() || 1963 buf_dirty_count_severe() || 1964 (ioflag & IO_ASYNC)) { 1965 bp->b_flags |= B_CLUSTEROK; 1966 bawrite(bp); 1967 } else if (xfersize + blkoffset == fs->e2fs_fsize) { 1968 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0) { 1969 bp->b_flags |= B_CLUSTEROK; 1970 cluster_write(vp, bp, ip->i_size, seqcount); 1971 } else { 1972 bawrite(bp); 1973 } 1974 } else if (ioflag & IO_DIRECT) { 1975 bp->b_flags |= B_CLUSTEROK; 1976 bawrite(bp); 1977 } else { 1978 bp->b_flags |= B_CLUSTEROK; 1979 bdwrite(bp); 1980 } 1981 if (error || xfersize == 0) 1982 break; 1983 } 1984 /* 1985 * If we successfully wrote any data, and we are not the superuser 1986 * we clear the setuid and setgid bits as a precaution against 1987 * tampering. 1988 */ 1989 if ((ip->i_mode & (ISUID | ISGID)) && resid > uio->uio_resid && 1990 ap->a_cred) { 1991 if (priv_check_cred(ap->a_cred, PRIV_VFS_RETAINSUGID, 0)) 1992 ip->i_mode &= ~(ISUID | ISGID); 1993 } 1994 if (error) { 1995 if (ioflag & IO_UNIT) { 1996 (void)ext2_truncate(vp, osize, 1997 ioflag & IO_SYNC, ap->a_cred, uio->uio_td); 1998 uio->uio_offset -= resid - uio->uio_resid; 1999 uio->uio_resid = resid; 2000 } 2001 } 2002 if (uio->uio_resid != resid) { 2003 ip->i_flag |= IN_CHANGE | IN_UPDATE; 2004 if (ioflag & IO_SYNC) 2005 error = ext2_update(vp, 1); 2006 } 2007 return (error); 2008 } 2009