Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src Apply patch (requested by bouyer):



details:   https://anonhg.NetBSD.org/src/rev/543ee882828d
branches:  netbsd-1-4
changeset: 470254:543ee882828d
user:      he <he%NetBSD.org@localhost>
date:      Tue Feb 01 23:38:39 2000 +0000

description:
Apply patch (requested by bouyer):
  Add support for ext2fs revision 1, with read-only support for
  the 'sparse_super' and 'filetype' options.  Should fix PR#9088.

diffstat:

 sbin/fsck_ext2fs/setup.c       |  31 +++++++++++-----------
 sys/ufs/ext2fs/ext2fs.h        |  22 ++++++++++++++--
 sys/ufs/ext2fs/ext2fs_bswap.c  |   8 ++++-
 sys/ufs/ext2fs/ext2fs_lookup.c |  24 +++++++++--------
 sys/ufs/ext2fs/ext2fs_vfsops.c |  57 ++++++++++++++++++++++++++++++++++++-----
 5 files changed, 104 insertions(+), 38 deletions(-)

diffs (277 lines):

diff -r ff4d971d3f3a -r 543ee882828d sbin/fsck_ext2fs/setup.c
--- a/sbin/fsck_ext2fs/setup.c  Tue Feb 01 23:30:28 2000 +0000
+++ b/sbin/fsck_ext2fs/setup.c  Tue Feb 01 23:38:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setup.c,v 1.10 1999/02/17 13:11:19 bouyer Exp $        */
+/*     $NetBSD: setup.c,v 1.10.2.1 2000/02/01 23:38:39 he Exp $        */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)setup.c    8.5 (Berkeley) 11/23/94";
 #else
-__RCSID("$NetBSD: setup.c,v 1.10 1999/02/17 13:11:19 bouyer Exp $");
+__RCSID("$NetBSD: setup.c,v 1.10.2.1 2000/02/01 23:38:39 he Exp $");
 #endif
 #endif /* not lint */
 
@@ -301,6 +301,20 @@
        if (sblock.e2fs.e2fs_log_bsize > 2) {
                badsb(listerr, "BAD LOG_BSIZE"); return (0);
        }
+       if (sblock.e2fs.e2fs_rev > E2FS_REV1) {
+               badsb(listerr, "BAD REVISION"); return (0);
+       }
+       if (sblock.e2fs.e2fs_rev > E2FS_REV0) {
+               if (fs2h32(sblk.b_un.b_fs->e2fs_features_incompat) != 0 ||
+                   fs2h32(sblk.b_un.b_fs->e2fs_features_rocompat) != 0) {
+                       badsb(listerr, "UNSUPPORTED FEATURE"); return (0);
+               }
+               if (fs2h32(sblk.b_un.b_fs->e2fs_first_ino) != EXT2_FIRSTINO ||
+                   fs2h16(sblk.b_un.b_fs->e2fs_inode_size) != EXT2_DINODE_SIZE) {
+                       badsb(listerr, "UNSUPPORTED INDODE SIZE"); return (0);
+               }
+       }
+
 
        /* compute the dynamic fields of the in-memory sb */
        /* compute dynamic sb infos */
@@ -364,19 +378,6 @@
        asblk.b_un.b_fs->e2fs_rgid = sblk.b_un.b_fs->e2fs_rgid;
        asblk.b_un.b_fs->e2fs_block_group_nr =
            sblk.b_un.b_fs->e2fs_block_group_nr;
-       if (sblk.b_un.b_fs->e2fs_features_compat != 0 ||
-           sblk.b_un.b_fs->e2fs_features_incompat != 0 ||
-           sblk.b_un.b_fs->e2fs_features_compat_ro != 0) {
-               if (debug) {
-                       printf("compat 0x%08x, incompat 0x%08x, compat_ro "
-                           "0x%08x\n",
-                           sblk.b_un.b_fs->e2fs_features_compat,
-                           sblk.b_un.b_fs->e2fs_features_incompat,
-                           sblk.b_un.b_fs->e2fs_features_compat_ro);
-               }
-               badsb(listerr,"UNKNOWN FEATURE BITS IN SUPER BLOCK");
-               return 0;
-       }
        if (memcmp(sblk.b_un.b_fs, asblk.b_un.b_fs, SBSIZE)) {
                if (debug) {
                        u_int32_t *nlp, *olp, *endlp;
diff -r ff4d971d3f3a -r 543ee882828d sys/ufs/ext2fs/ext2fs.h
--- a/sys/ufs/ext2fs/ext2fs.h   Tue Feb 01 23:30:28 2000 +0000
+++ b/sys/ufs/ext2fs/ext2fs.h   Tue Feb 01 23:38:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs.h,v 1.8 1999/02/17 13:09:43 bouyer Exp $        */
+/*     $NetBSD: ext2fs.h,v 1.8.2.1 2000/02/01 23:38:39 he Exp $        */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -132,7 +132,7 @@
        u_int16_t  e2fs_block_group_nr; /* block grp number of this sblk*/
        u_int32_t  e2fs_features_compat; /*  OK to mount if unknown */
        u_int32_t  e2fs_features_incompat; /* not OK to mount if unknown */
-       u_int32_t  e2fs_features_compat_ro; /* OK to mount ro if unknown */
+       u_int32_t  e2fs_features_rocompat; /* OK to mount ro if unknown */
        u_int32_t  reserved2[230];
 };
 
@@ -161,7 +161,23 @@
  * Filesystem identification
  */
 #define        E2FS_MAGIC      0xef53  /* the ext2fs magic number */
-#define E2FS_REV       0       /* revision level */
+#define E2FS_REV0      0       /* revision level */
+#define E2FS_REV1      1       /* revision level */
+
+/* compatible/imcompatible features */
+#define EXT2F_COMPAT_PREALLOC          0x0001
+
+#define EXT2F_ROCOMPAT_SPARSESUPER     0x0001
+#define EXT2F_ROCOMPAT_LARGEFILE       0x0002
+#define EXT2F_ROCOMPAT_BTREE_DIR       0x0004
+
+#define EXT2F_INCOMPAT_COMP            0x0001
+#define EXT2F_INCOMPAT_FTYPE           0x0002
+
+/* features supported in this implementation */
+#define EXT2F_COMPAT_SUPP              0x0000
+#define EXT2F_ROCOMPAT_SUPP            0x0000
+#define EXT2F_INCOMPAT_SUPP            EXT2F_INCOMPAT_FTYPE
 
 /*
  * OS identification
diff -r ff4d971d3f3a -r 543ee882828d sys/ufs/ext2fs/ext2fs_bswap.c
--- a/sys/ufs/ext2fs/ext2fs_bswap.c     Tue Feb 01 23:30:28 2000 +0000
+++ b/sys/ufs/ext2fs/ext2fs_bswap.c     Tue Feb 01 23:38:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_bswap.c,v 1.2 1998/08/09 20:15:38 perry Exp $   */
+/*     $NetBSD: ext2fs_bswap.c,v 1.2.6.1 2000/02/01 23:38:39 he Exp $  */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -69,7 +69,11 @@
        new->e2fs_state                 =               bswap16(old->e2fs_state);
        new->e2fs_beh                   =               bswap16(old->e2fs_beh);
        new->e2fs_ruid                  =               bswap16(old->e2fs_ruid);
-       new->e2fs_rgid                  =               bswap16(old->e2fs_rgid);
+       new->e2fs_rgid                  =               bswap16(old->e2fs_rgid);        new->e2fs_first_ino             =               bswap32(old->e2fs_first_ino);
+       new->e2fs_inode_size            =               bswap16(old->e2fs_inode_size);
+       new->e2fs_features_compat       =               bswap32(old->e2fs_features_compat);
+       new->e2fs_features_incompat     =               bswap32(old->e2fs_features_incompat);
+       new->e2fs_features_rocompat     =               bswap32(old->e2fs_features_rocompat);
 }
 
 void e2fs_cg_bswap(old, new, size)
diff -r ff4d971d3f3a -r 543ee882828d sys/ufs/ext2fs/ext2fs_lookup.c
--- a/sys/ufs/ext2fs/ext2fs_lookup.c    Tue Feb 01 23:30:28 2000 +0000
+++ b/sys/ufs/ext2fs/ext2fs_lookup.c    Tue Feb 01 23:38:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_lookup.c,v 1.9 1998/12/02 10:44:52 bouyer Exp $ */
+/*     $NetBSD: ext2fs_lookup.c,v 1.9.4.1 2000/02/01 23:38:39 he Exp $ */
 
 /* 
  * Modified for NetBSD 1.2E
@@ -95,17 +95,13 @@
 {
        memset(ffsdir, 0, sizeof(struct dirent));
        ffsdir->d_fileno = fs2h32(e2dir->e2d_ino);
+       /*
+        * d_namlen is u_int8_t to the rigth thing will happen even with
+        * filetype
+        */
        ffsdir->d_namlen = fs2h16(e2dir->e2d_namlen);
 
        ffsdir->d_type = DT_UNKNOWN;            /* don't know more here */
-#ifdef DIAGNOSTIC
-       /*
-        * XXX Rigth now this can't happen, but if one day
-        * MAXNAMLEN != E2FS_MAXNAMLEN we should handle this more gracefully !
-        */
-       if (fs2h16(e2dir->e2d_namlen) > MAXNAMLEN)
-               panic("ext2fs: e2dir->e2d_namlen\n");
-#endif
        strncpy(ffsdir->d_name, e2dir->e2d_name, ffsdir->d_namlen);
 
        /* Godmar thinks: since e2dir->e2d_reclen can be big and means 
@@ -481,6 +477,9 @@
                 */
                if (ep->e2d_ino) {
                        namlen = fs2h16(ep->e2d_namlen);
+                       if (VTOI(ap->a_dvp)->i_e2fs->e2fs.e2fs_rev > E2FS_REV0
+                           && (VTOI(ap->a_dvp)->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE) != 0)
+                               namlen &= 0xff;
                        if (namlen == cnp->cn_namelen &&
                                !memcmp(cnp->cn_nameptr, ep->e2d_name,
                                (unsigned)namlen)) {
@@ -578,11 +577,11 @@
         * Check that directory length properly reflects presence
         * of this entry.
         */
-       if (entryoffsetinblock + EXT2FS_DIRSIZ(fs2h16(ep->e2d_namlen))
+       if (entryoffsetinblock + EXT2FS_DIRSIZ(namlen)
                > dp->i_e2fs_size) {
                ufs_dirbad(dp, dp->i_offset, "i_size too small");
                dp->i_e2fs_size = entryoffsetinblock +
-                       EXT2FS_DIRSIZ(fs2h16(ep->e2d_namlen));
+                       EXT2FS_DIRSIZ(namlen);
                dp->i_flag |= IN_CHANGE | IN_UPDATE;
        }
 
@@ -745,6 +744,9 @@
                int reclen = fs2h16(de->e2d_reclen);
                int namlen = fs2h16(de->e2d_namlen);
 
+               if (VTOI(dp)->i_e2fs->e2fs.e2fs_rev > E2FS_REV0
+                   && (VTOI(dp)->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE) != 0)
+                       namlen &= 0xff;
                if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */
                                error_msg = "rec_len is smaller than minimal";
                else if (reclen % 4 != 0)
diff -r ff4d971d3f3a -r 543ee882828d sys/ufs/ext2fs/ext2fs_vfsops.c
--- a/sys/ufs/ext2fs/ext2fs_vfsops.c    Tue Feb 01 23:30:28 2000 +0000
+++ b/sys/ufs/ext2fs/ext2fs_vfsops.c    Tue Feb 01 23:38:39 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_vfsops.c,v 1.24.2.2 1999/10/18 05:05:30 cgd Exp $       */
+/*     $NetBSD: ext2fs_vfsops.c,v 1.24.2.3 2000/02/01 23:38:39 he Exp $        */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -369,14 +369,32 @@
                brelse(bp);
                return (EIO);           /* XXX needs translation */
        }
-       if (fs2h32(newfs->e2fs_rev) != E2FS_REV) {
+       if (fs2h32(newfs->e2fs_rev) > E2FS_REV1) {
 #ifdef DIAGNOSTIC
-               printf("Ext2 fs: unsupported revision number: %x (expected %x)\n",
-                                       fs2h32(newfs->e2fs_rev), E2FS_REV);
+               printf("Ext2 fs: unsupported revision number: %x\n",
+                                       fs2h32(newfs->e2fs_rev));
 #endif
                brelse(bp);
                return (EIO);           /* XXX needs translation */
        }
+       if (fs2h32(newfs->e2fs_rev) > E2FS_REV0) {
+               if ((fs2h32(newfs->e2fs_features_incompat) &
+                   ~EXT2F_INCOMPAT_SUPP) != 0) {
+#ifdef DIAGNOSTIC
+                       printf("Ext2 fs: unsupported features\n");
+#endif
+                       return (EINVAL);
+               }
+               if (fs2h32(newfs->e2fs_first_ino) != EXT2_FIRSTINO ||
+                   fs2h16(newfs->e2fs_inode_size) != EXT2_DINODE_SIZE) {
+                       printf("Ext2 fs: unsupported inode size\n");
+                       return (EINVAL);
+               }
+               /*
+                * We're sure we are read-only here, no need to check
+                * e2fs_features_rocompat
+                */
+       }
        if (fs2h32(newfs->e2fs_log_bsize) > 2) { /* block size = 1024|2048|4096 */
 #ifdef DIAGNOSTIC
                printf("Ext2 fs: bad block size: %d (expected <=2 for ext2 fs)\n",
@@ -525,14 +543,39 @@
                error = EINVAL;         /* XXX needs translation */
                goto out;
        }
-       if (fs2h32(fs->e2fs_rev) != E2FS_REV) {
+       if (fs2h32(fs->e2fs_rev) > E2FS_REV1) {
 #ifdef DIAGNOSTIC
-               printf("Ext2 fs: unsupported revision number: %x (expected %x)\n",
-                                       fs2h32(fs->e2fs_rev), E2FS_REV);
+               printf("Ext2 fs: unsupported revision number: %x\n",
+                                       fs2h32(fs->e2fs_rev));
 #endif
                error = EINVAL;         /* XXX needs translation */
                goto out;
        }
+       if (fs2h32(fs->e2fs_rev) > E2FS_REV0) {
+               if ((fs2h32(fs->e2fs_features_incompat) &
+                   ~EXT2F_INCOMPAT_SUPP) != 0) {
+#ifdef DIAGNOSTIC
+                       printf("Ext2 fs: unsupported features\n");
+#endif
+                       error = EINVAL;
+                       goto out;
+               }
+               if (fs2h32(fs->e2fs_first_ino) != EXT2_FIRSTINO ||
+                   fs2h16(fs->e2fs_inode_size) != EXT2_DINODE_SIZE) {
+                       printf("Ext2 fs: unsupported inode size\n");
+                       return (EINVAL);
+               }
+               /* EXT2F_INCOMPAT_FTYPE only supported read-only */
+               if ((fs2h32(fs->e2fs_features_incompat) &
+                   EXT2F_INCOMPAT_FTYPE) != 0 ||
+                   (fs2h32(fs->e2fs_features_rocompat) &
+                   ~EXT2F_ROCOMPAT_SUPP) != 0) {
+                       if (!ronly) {
+                               error = EROFS;
+                               goto out;
+                       }
+               }
+       }
        if (fs2h32(fs->e2fs_log_bsize) > 2) { /* block size = 1024|2048|4096 */
 #ifdef DIAGNOSTIC
                printf("Ext2 fs: bad block size: %d (expected <=2 for ext2 fs)\n",



Home | Main Index | Thread Index | Old Index