ext2_vfsops.c (41591) | ext2_vfsops.c (43301) |
---|---|
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) 1989, 1991, 1993, 1994 --- 175 unchanged lines hidden (view full) --- 184 struct vnode *devvp; 185 struct ufs_args args; 186 struct ufsmount *ump = 0; 187 register struct ext2_sb_info *fs; 188 u_int size; 189 int error, flags; 190 mode_t accessmode; 191 | 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) 1989, 1991, 1993, 1994 --- 175 unchanged lines hidden (view full) --- 184 struct vnode *devvp; 185 struct ufs_args args; 186 struct ufsmount *ump = 0; 187 register struct ext2_sb_info *fs; 188 u_int size; 189 int error, flags; 190 mode_t accessmode; 191 |
192 if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args))) | 192 if ((error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args))) != 0) |
193 return (error); 194 /* 195 * If updating, check whether changing from read-only to 196 * read/write; if there is no device name, that's all we do. 197 * Disallow clearing MNT_NOCLUSTERR and MNT_NOCLUSTERW flags, 198 * if block device requests. 199 */ 200 if (mp->mnt_flag & MNT_UPDATE) { --- 25 unchanged lines hidden (view full) --- 226 if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) { 227 /* 228 * If upgrade to read-write by non-root, then verify 229 * that user has necessary permissions on the device. 230 */ 231 if (p->p_ucred->cr_uid != 0) { 232 devvp = ump->um_devvp; 233 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); | 193 return (error); 194 /* 195 * If updating, check whether changing from read-only to 196 * read/write; if there is no device name, that's all we do. 197 * Disallow clearing MNT_NOCLUSTERR and MNT_NOCLUSTERW flags, 198 * if block device requests. 199 */ 200 if (mp->mnt_flag & MNT_UPDATE) { --- 25 unchanged lines hidden (view full) --- 226 if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) { 227 /* 228 * If upgrade to read-write by non-root, then verify 229 * that user has necessary permissions on the device. 230 */ 231 if (p->p_ucred->cr_uid != 0) { 232 devvp = ump->um_devvp; 233 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); |
234 if (error = VOP_ACCESS(devvp, VREAD | VWRITE, 235 p->p_ucred, p)) { | 234 if ((error = VOP_ACCESS(devvp, VREAD | VWRITE, 235 p->p_ucred, p)) != 0) { |
236 VOP_UNLOCK(devvp, 0, p); 237 return (error); 238 } 239 VOP_UNLOCK(devvp, 0, p); 240 } 241 242 if ((fs->s_es->s_state & EXT2_VALID_FS) == 0 || 243 (fs->s_es->s_state & EXT2_ERROR_FS)) { --- 19 unchanged lines hidden (view full) --- 263 return (vfs_export(mp, &ump->um_export, &args.export)); 264 } 265 } 266 /* 267 * Not an update, or updating the name: look up the name 268 * and verify that it refers to a sensible block device. 269 */ 270 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p); | 236 VOP_UNLOCK(devvp, 0, p); 237 return (error); 238 } 239 VOP_UNLOCK(devvp, 0, p); 240 } 241 242 if ((fs->s_es->s_state & EXT2_VALID_FS) == 0 || 243 (fs->s_es->s_state & EXT2_ERROR_FS)) { --- 19 unchanged lines hidden (view full) --- 263 return (vfs_export(mp, &ump->um_export, &args.export)); 264 } 265 } 266 /* 267 * Not an update, or updating the name: look up the name 268 * and verify that it refers to a sensible block device. 269 */ 270 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p); |
271 if (error = namei(ndp)) | 271 if ((error = namei(ndp)) != 0) |
272 return (error); 273 devvp = ndp->ni_vp; 274 275 if (devvp->v_type != VBLK) { 276 vrele(devvp); 277 return (ENOTBLK); 278 } 279 if (major(devvp->v_rdev) >= nblkdev || --- 6 unchanged lines hidden (view full) --- 286 * If mount by non-root, then verify that user has necessary 287 * permissions on the device. 288 */ 289 if (p->p_ucred->cr_uid != 0) { 290 accessmode = VREAD; 291 if ((mp->mnt_flag & MNT_RDONLY) == 0) 292 accessmode |= VWRITE; 293 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); | 272 return (error); 273 devvp = ndp->ni_vp; 274 275 if (devvp->v_type != VBLK) { 276 vrele(devvp); 277 return (ENOTBLK); 278 } 279 if (major(devvp->v_rdev) >= nblkdev || --- 6 unchanged lines hidden (view full) --- 286 * If mount by non-root, then verify that user has necessary 287 * permissions on the device. 288 */ 289 if (p->p_ucred->cr_uid != 0) { 290 accessmode = VREAD; 291 if ((mp->mnt_flag & MNT_RDONLY) == 0) 292 accessmode |= VWRITE; 293 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); |
294 if (error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) { | 294 if ((error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) != 0) { |
295 vput(devvp); 296 return (error); 297 } 298 VOP_UNLOCK(devvp, 0, p); 299 } 300 301 if ((mp->mnt_flag & MNT_UPDATE) == 0) { 302 if (bdevsw[major(devvp->v_rdev)]->d_flags & D_NOCLUSTERR) --- 210 unchanged lines hidden (view full) --- 513 */ 514 devvp = VFSTOUFS(mountp)->um_devvp; 515 if (vinvalbuf(devvp, 0, cred, p, 0, 0)) 516 panic("ext2_reload: dirty1"); 517 /* 518 * Step 2: re-read superblock from disk. 519 * constants have been adjusted for ext2 520 */ | 295 vput(devvp); 296 return (error); 297 } 298 VOP_UNLOCK(devvp, 0, p); 299 } 300 301 if ((mp->mnt_flag & MNT_UPDATE) == 0) { 302 if (bdevsw[major(devvp->v_rdev)]->d_flags & D_NOCLUSTERR) --- 210 unchanged lines hidden (view full) --- 513 */ 514 devvp = VFSTOUFS(mountp)->um_devvp; 515 if (vinvalbuf(devvp, 0, cred, p, 0, 0)) 516 panic("ext2_reload: dirty1"); 517 /* 518 * Step 2: re-read superblock from disk. 519 * constants have been adjusted for ext2 520 */ |
521 if (error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) | 521 if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0) |
522 return (error); 523 es = (struct ext2_super_block *)bp->b_data; 524 if (es->s_magic != EXT2_SUPER_MAGIC) { 525 if(es->s_magic == EXT2_PRE_02B_MAGIC) 526 printf("This filesystem bears the magic number of a pre " 527 "0.2b version of ext2. This is not supported by " 528 "Lites.\n"); 529 else 530 printf("Wrong magic number: %x (expected %x for ext2 fs\n", 531 es->s_magic, EXT2_SUPER_MAGIC); 532 brelse(bp); 533 return (EIO); /* XXX needs translation */ 534 } 535 fs = VFSTOUFS(mountp)->um_e2fs; 536 bcopy(bp->b_data, fs->s_es, sizeof(struct ext2_super_block)); 537 | 522 return (error); 523 es = (struct ext2_super_block *)bp->b_data; 524 if (es->s_magic != EXT2_SUPER_MAGIC) { 525 if(es->s_magic == EXT2_PRE_02B_MAGIC) 526 printf("This filesystem bears the magic number of a pre " 527 "0.2b version of ext2. This is not supported by " 528 "Lites.\n"); 529 else 530 printf("Wrong magic number: %x (expected %x for ext2 fs\n", 531 es->s_magic, EXT2_SUPER_MAGIC); 532 brelse(bp); 533 return (EIO); /* XXX needs translation */ 534 } 535 fs = VFSTOUFS(mountp)->um_e2fs; 536 bcopy(bp->b_data, fs->s_es, sizeof(struct ext2_super_block)); 537 |
538 if(error = compute_sb_data(devvp, es, fs)) { | 538 if((error = compute_sb_data(devvp, es, fs)) != 0) { |
539 brelse(bp); 540 return error; 541 } 542#ifdef UNKLAR 543 if (fs->fs_sbsize < SBSIZE) 544 bp->b_flags |= B_INVAL; 545#endif 546 brelse(bp); --- 63 unchanged lines hidden (view full) --- 610 int ronly; 611 612 /* 613 * Disallow multiple mounts of the same device. 614 * Disallow mounting of a device that is currently in use 615 * (except for root, which might share swap device for miniroot). 616 * Flush out any old buffers remaining from a previous use. 617 */ | 539 brelse(bp); 540 return error; 541 } 542#ifdef UNKLAR 543 if (fs->fs_sbsize < SBSIZE) 544 bp->b_flags |= B_INVAL; 545#endif 546 brelse(bp); --- 63 unchanged lines hidden (view full) --- 610 int ronly; 611 612 /* 613 * Disallow multiple mounts of the same device. 614 * Disallow mounting of a device that is currently in use 615 * (except for root, which might share swap device for miniroot). 616 * Flush out any old buffers remaining from a previous use. 617 */ |
618 if (error = vfs_mountedon(devvp)) | 618 if ((error = vfs_mountedon(devvp)) != 0) |
619 return (error); 620 if (vcount(devvp) > 1 && devvp != rootvp) 621 return (EBUSY); | 619 return (error); 620 if (vcount(devvp) > 1 && devvp != rootvp) 621 return (EBUSY); |
622 if (error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) | 622 if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0) |
623 return (error); 624#ifdef READONLY 625/* turn on this to force it to be read-only */ 626 mp->mnt_flag |= MNT_RDONLY; 627#endif 628 629 ronly = (mp->mnt_flag & MNT_RDONLY) != 0; | 623 return (error); 624#ifdef READONLY 625/* turn on this to force it to be read-only */ 626 mp->mnt_flag |= MNT_RDONLY; 627#endif 628 629 ronly = (mp->mnt_flag & MNT_RDONLY) != 0; |
630 if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p)) | 630 if ((error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p)) != 0) |
631 return (error); 632 if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0) 633 size = DEV_BSIZE; 634 else { 635 havepart = 1; 636 size = dpart.disklab->d_secsize; 637 } 638 639 bp = NULL; 640 ump = NULL; | 631 return (error); 632 if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0) 633 size = DEV_BSIZE; 634 else { 635 havepart = 1; 636 size = dpart.disklab->d_secsize; 637 } 638 639 bp = NULL; 640 ump = NULL; |
641 if (error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) | 641 if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0) |
642 goto out; 643 es = (struct ext2_super_block *)bp->b_data; 644 if (es->s_magic != EXT2_SUPER_MAGIC) { 645 if(es->s_magic == EXT2_PRE_02B_MAGIC) 646 printf("This filesystem bears the magic number of a pre " 647 "0.2b version of ext2. This is not supported by " 648 "Lites.\n"); 649 else --- 96 unchanged lines hidden (view full) --- 746 int error, flags, ronly, i; 747 748 flags = 0; 749 if (mntflags & MNT_FORCE) { 750 if (mp->mnt_flag & MNT_ROOTFS) 751 return (EINVAL); 752 flags |= FORCECLOSE; 753 } | 642 goto out; 643 es = (struct ext2_super_block *)bp->b_data; 644 if (es->s_magic != EXT2_SUPER_MAGIC) { 645 if(es->s_magic == EXT2_PRE_02B_MAGIC) 646 printf("This filesystem bears the magic number of a pre " 647 "0.2b version of ext2. This is not supported by " 648 "Lites.\n"); 649 else --- 96 unchanged lines hidden (view full) --- 746 int error, flags, ronly, i; 747 748 flags = 0; 749 if (mntflags & MNT_FORCE) { 750 if (mp->mnt_flag & MNT_ROOTFS) 751 return (EINVAL); 752 flags |= FORCECLOSE; 753 } |
754 if (error = ext2_flushfiles(mp, flags, p)) | 754 if ((error = ext2_flushfiles(mp, flags, p)) != 0) |
755 return (error); 756 ump = VFSTOUFS(mp); 757 fs = ump->um_e2fs; 758 ronly = fs->s_rd_only; 759 if (ronly == 0) { 760 if (fs->s_wasvalid) 761 fs->s_es->s_state |= EXT2_VALID_FS; 762 ext2_sbupdate(ump, MNT_WAIT); --- 38 unchanged lines hidden (view full) --- 801 int error; 802#if QUOTA 803 int i; 804#endif 805 806 ump = VFSTOUFS(mp); 807#if QUOTA 808 if (mp->mnt_flag & MNT_QUOTA) { | 755 return (error); 756 ump = VFSTOUFS(mp); 757 fs = ump->um_e2fs; 758 ronly = fs->s_rd_only; 759 if (ronly == 0) { 760 if (fs->s_wasvalid) 761 fs->s_es->s_state |= EXT2_VALID_FS; 762 ext2_sbupdate(ump, MNT_WAIT); --- 38 unchanged lines hidden (view full) --- 801 int error; 802#if QUOTA 803 int i; 804#endif 805 806 ump = VFSTOUFS(mp); 807#if QUOTA 808 if (mp->mnt_flag & MNT_QUOTA) { |
809 if (error = vflush(mp, NULLVP, SKIPSYSTEM|flags)) | 809 if ((error = vflush(mp, NULLVP, SKIPSYSTEM|flags)) != 0) |
810 return (error); 811 for (i = 0; i < MAXQUOTAS; i++) { 812 if (ump->um_quotas[i] == NULLVP) 813 continue; 814 quotaoff(p, mp, i); 815 } 816 /* 817 * Here we fall through to vflush again to ensure --- 107 unchanged lines hidden (view full) --- 925 simple_unlock(&mntvnode_slock); 926 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, p); 927 if (error) { 928 simple_lock(&mntvnode_slock); 929 if (error == ENOENT) 930 goto loop; 931 continue; 932 } | 810 return (error); 811 for (i = 0; i < MAXQUOTAS; i++) { 812 if (ump->um_quotas[i] == NULLVP) 813 continue; 814 quotaoff(p, mp, i); 815 } 816 /* 817 * Here we fall through to vflush again to ensure --- 107 unchanged lines hidden (view full) --- 925 simple_unlock(&mntvnode_slock); 926 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, p); 927 if (error) { 928 simple_lock(&mntvnode_slock); 929 if (error == ENOENT) 930 goto loop; 931 continue; 932 } |
933 if (error = VOP_FSYNC(vp, cred, waitfor, p)) | 933 if ((error = VOP_FSYNC(vp, cred, waitfor, p)) != 0) |
934 allerror = error; 935 VOP_UNLOCK(vp, 0, p); 936 vrele(vp); 937 simple_lock(&mntvnode_slock); 938 } 939 simple_unlock(&mntvnode_slock); 940 /* 941 * Force stale file system control information to be flushed. --- 65 unchanged lines hidden (view full) --- 1007 * it might block, leaving a vnode with a NULL v_data to be 1008 * found by ext2_sync() if a sync happens to fire right then, 1009 * which will cause a panic because ext2_sync() blindly 1010 * dereferences vp->v_data (as well it should). 1011 */ 1012 MALLOC(ip, struct inode *, sizeof(struct inode), M_EXT2NODE, M_WAITOK); 1013 1014 /* Allocate a new vnode/inode. */ | 934 allerror = error; 935 VOP_UNLOCK(vp, 0, p); 936 vrele(vp); 937 simple_lock(&mntvnode_slock); 938 } 939 simple_unlock(&mntvnode_slock); 940 /* 941 * Force stale file system control information to be flushed. --- 65 unchanged lines hidden (view full) --- 1007 * it might block, leaving a vnode with a NULL v_data to be 1008 * found by ext2_sync() if a sync happens to fire right then, 1009 * which will cause a panic because ext2_sync() blindly 1010 * dereferences vp->v_data (as well it should). 1011 */ 1012 MALLOC(ip, struct inode *, sizeof(struct inode), M_EXT2NODE, M_WAITOK); 1013 1014 /* Allocate a new vnode/inode. */ |
1015 if (error = getnewvnode(VT_UFS, mp, ext2_vnodeop_p, &vp)) { | 1015 if ((error = getnewvnode(VT_UFS, mp, ext2_vnodeop_p, &vp)) != 0) { |
1016 if (ext2fs_inode_hash_lock < 0) 1017 wakeup(&ext2fs_inode_hash_lock); 1018 ext2fs_inode_hash_lock = 0; 1019 *vpp = NULL; 1020 FREE(ip, M_EXT2NODE); 1021 return (error); 1022 } 1023 bzero((caddr_t)ip, sizeof(struct inode)); --- 18 unchanged lines hidden (view full) --- 1042 if (ext2fs_inode_hash_lock < 0) 1043 wakeup(&ext2fs_inode_hash_lock); 1044 ext2fs_inode_hash_lock = 0; 1045 1046 /* Read in the disk contents for the inode, copy into the inode. */ 1047#if 0 1048printf("ext2_vget(%d) dbn= %d ", ino, fsbtodb(fs, ino_to_fsba(fs, ino))); 1049#endif | 1016 if (ext2fs_inode_hash_lock < 0) 1017 wakeup(&ext2fs_inode_hash_lock); 1018 ext2fs_inode_hash_lock = 0; 1019 *vpp = NULL; 1020 FREE(ip, M_EXT2NODE); 1021 return (error); 1022 } 1023 bzero((caddr_t)ip, sizeof(struct inode)); --- 18 unchanged lines hidden (view full) --- 1042 if (ext2fs_inode_hash_lock < 0) 1043 wakeup(&ext2fs_inode_hash_lock); 1044 ext2fs_inode_hash_lock = 0; 1045 1046 /* Read in the disk contents for the inode, copy into the inode. */ 1047#if 0 1048printf("ext2_vget(%d) dbn= %d ", ino, fsbtodb(fs, ino_to_fsba(fs, ino))); 1049#endif |
1050 if (error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)), 1051 (int)fs->s_blocksize, NOCRED, &bp)) { | 1050 if ((error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)), 1051 (int)fs->s_blocksize, NOCRED, &bp)) != 0) { |
1052 /* 1053 * The inode does not contain anything useful, so it would 1054 * be misleading to leave it on its hash chain. With mode 1055 * still zero, it will be unlinked and returned to the free 1056 * list by vput(). 1057 */ 1058 vput(vp); 1059 brelse(bp); --- 21 unchanged lines hidden (view full) --- 1081 ext2_print_inode(ip); 1082*/ 1083 brelse(bp); 1084 1085 /* 1086 * Initialize the vnode from the inode, check for aliases. 1087 * Note that the underlying vnode may have changed. 1088 */ | 1052 /* 1053 * The inode does not contain anything useful, so it would 1054 * be misleading to leave it on its hash chain. With mode 1055 * still zero, it will be unlinked and returned to the free 1056 * list by vput(). 1057 */ 1058 vput(vp); 1059 brelse(bp); --- 21 unchanged lines hidden (view full) --- 1081 ext2_print_inode(ip); 1082*/ 1083 brelse(bp); 1084 1085 /* 1086 * Initialize the vnode from the inode, check for aliases. 1087 * Note that the underlying vnode may have changed. 1088 */ |
1089 if (error = ufs_vinit(mp, ext2_specop_p, ext2_fifoop_p, &vp)) { | 1089 if ((error = ufs_vinit(mp, ext2_specop_p, ext2_fifoop_p, &vp)) != 0) { |
1090 vput(vp); 1091 *vpp = NULL; 1092 return (error); 1093 } 1094 /* 1095 * Finish inode initialization now that aliasing has been resolved. 1096 */ 1097 ip->i_devvp = ump->um_devvp; --- 94 unchanged lines hidden --- | 1090 vput(vp); 1091 *vpp = NULL; 1092 return (error); 1093 } 1094 /* 1095 * Finish inode initialization now that aliasing has been resolved. 1096 */ 1097 ip->i_devvp = ump->um_devvp; --- 94 unchanged lines hidden --- |