Source-Changes-HG archive

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

[src/trunk]: src First cut at ext2fs rev 1 support (as of mke2fs 1.18): suppo...



details:   https://anonhg.NetBSD.org/src/rev/0e177b4c7f67
branches:  trunk
changeset: 481348:0e177b4c7f67
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Jan 26 16:21:31 2000 +0000

description:
First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.

diffstat:

 sbin/fsck_ext2fs/dir.c         |  57 +++++++++++++++++-------
 sbin/fsck_ext2fs/fsck.h        |   3 +-
 sbin/fsck_ext2fs/inode.c       |   8 ++-
 sbin/fsck_ext2fs/main.c        |   8 ++-
 sbin/fsck_ext2fs/pass1.c       |   6 +-
 sbin/fsck_ext2fs/pass2.c       |  62 ++++++++++++++++++++++-----
 sbin/fsck_ext2fs/setup.c       |  20 +++++---
 sys/ufs/ext2fs/ext2fs.h        |  39 +++++++++++++---
 sys/ufs/ext2fs/ext2fs_bswap.c  |  58 ++++++++++++++-----------
 sys/ufs/ext2fs/ext2fs_dinode.h |  16 +++---
 sys/ufs/ext2fs/ext2fs_dir.h    |  14 ++++-
 sys/ufs/ext2fs/ext2fs_lookup.c |  40 +++++++++++------
 sys/ufs/ext2fs/ext2fs_vfsops.c |  95 +++++++++++++++++++++++++----------------
 sys/ufs/ext2fs/ext2fs_vnops.c  |  16 +++++-
 14 files changed, 296 insertions(+), 146 deletions(-)

diffs (truncated from 1001 to 300 lines):

diff -r b7e824c040f1 -r 0e177b4c7f67 sbin/fsck_ext2fs/dir.c
--- a/sbin/fsck_ext2fs/dir.c    Wed Jan 26 15:50:52 2000 +0000
+++ b/sbin/fsck_ext2fs/dir.c    Wed Jan 26 16:21:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.3 1997/10/09 13:19:34 bouyer Exp $   */
+/*     $NetBSD: dir.c,v 1.4 2000/01/26 16:21:31 bouyer Exp $   */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -39,12 +39,13 @@
 #if 0
 static char sccsid[] = "@(#)dir.c      8.5 (Berkeley) 12/8/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.3 1997/10/09 13:19:34 bouyer Exp $");
+__RCSID("$NetBSD: dir.c,v 1.4 2000/01/26 16:21:31 bouyer Exp $");
 #endif
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/time.h>
+#include <ufs/ufs/dir.h>
 #include <ufs/ext2fs/ext2fs_dinode.h>
 #include <ufs/ext2fs/ext2fs_dir.h>
 #include <ufs/ext2fs/ext2fs.h>
@@ -61,12 +62,10 @@
 
 char   *lfname = "lost+found";
 int    lfmode = 01777;
-/* XXX DIRBLKSIZ id bsize ! */
-#define DIRBLKSIZ 0 /* just for now */
 struct ext2fs_dirtemplate emptydir = { 0, DIRBLKSIZ }; 
 struct ext2fs_dirtemplate dirhead = {
-       0, 12, 1, ".",
-       0, DIRBLKSIZ - 12, 2, ".."
+       0, 12, 1, IFTODT(EXT2_IFDIR), ".",
+       0, DIRBLKSIZ - 12, 2, IFTODT(EXT2_IFDIR), ".."
 };
 #undef DIRBLKSIZ
 
@@ -189,6 +188,7 @@
                dp->e2d_reclen = h2fs16(sblock.e2fs_bsize);
                dp->e2d_ino = 0;
                dp->e2d_namlen = 0;
+               dp->e2d_type = 0;
                dp->e2d_name[0] = '\0';
                if (fix)
                        dirty(bp);
@@ -235,7 +235,6 @@
        int size;
        char *cp;
        int spaceleft;
-       u_int16_t namlen;
        u_int16_t reclen = fs2h16(dp->e2d_reclen);
 
        spaceleft = sblock.e2fs_bsize - (idesc->id_loc % sblock.e2fs_bsize);
@@ -246,13 +245,16 @@
                return (0);
        if (dp->e2d_ino == 0)
                return (1);
-       namlen = fs2h16(dp->e2d_namlen);
-       size = EXT2FS_DIRSIZ(namlen);
+       if (sblock.e2fs.e2fs_rev < E2FS_REV0 ||
+           (sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE) == 0)
+               if (dp->e2d_type != 0)
+                       return (1);
+       size = EXT2FS_DIRSIZ(dp->e2d_namlen);
        if (reclen < size ||
            idesc->id_filesize < size ||
-           namlen > EXT2FS_MAXNAMLEN)
+           dp->e2d_namlen > EXT2FS_MAXNAMLEN)
                return (0);
-       for (cp = dp->e2d_name, size = 0; size < namlen; size++)
+       for (cp = dp->e2d_name, size = 0; size < dp->e2d_namlen; size++)
                if (*cp == '\0' || (*cp++ == '/'))
                        return (0);
        return (1);
@@ -330,10 +332,13 @@
        struct ext2fs_direct newent;
        int newlen, oldlen;
 
-       newent.e2d_namlen = h2fs16(strlen(idesc->id_name));
-       newlen = EXT2FS_DIRSIZ(fs2h16(newent.e2d_namlen));
+       newent.e2d_namlen = strlen(idesc->id_name);
+       if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
+           (sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
+               newent.e2d_type = typemap[idesc->id_parent];
+       newlen = EXT2FS_DIRSIZ(newent.e2d_namlen);
        if (dirp->e2d_ino != 0)
-               oldlen = EXT2FS_DIRSIZ(fs2h16(dirp->e2d_namlen));
+               oldlen = EXT2FS_DIRSIZ(dirp->e2d_namlen);
        else
                oldlen = 0;
        if (fs2h16(dirp->e2d_reclen) - oldlen < newlen)
@@ -344,7 +349,8 @@
        dirp->e2d_ino = h2fs32(idesc->id_parent); /* ino to be entered is in id_parent */
        dirp->e2d_reclen = newent.e2d_reclen;
        dirp->e2d_namlen = newent.e2d_namlen;
-       memcpy(dirp->e2d_name, idesc->id_name, (size_t)fs2h16(dirp->e2d_namlen));
+       dirp->e2d_type = newent.e2d_type;
+       memcpy(dirp->e2d_name, idesc->id_name, (size_t)(dirp->e2d_namlen));
        return (ALTERED|STOP);
 }
 
@@ -353,12 +359,17 @@
        struct inodesc *idesc;
 {
        struct ext2fs_direct *dirp = idesc->id_dirp;
-       u_int16_t namlen = fs2h16(dirp->e2d_namlen);
+       u_int16_t namlen = dirp->e2d_namlen;
 
        if (strlen(idesc->id_name) != namlen ||
                strncmp(dirp->e2d_name, idesc->id_name, (int)namlen))
                return (KEEPON);
        dirp->e2d_ino = h2fs32(idesc->id_parent);
+       if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
+           (sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
+               dirp->e2d_type = typemap[idesc->id_parent];
+       else
+               dirp->e2d_type = 0;
        return (ALTERED|STOP);
 }
 
@@ -601,8 +612,18 @@
        ino = allocino(request, IFDIR|mode);
        dirhead.dot_reclen = h2fs16(12); /* XXX */
        dirhead.dotdot_reclen = h2fs16(sblock.e2fs_bsize - 12); /* XXX */
-       dirhead.dot_namlen = h2fs16(1);
-       dirhead.dotdot_namlen = h2fs16(2);
+       dirhead.dot_namlen = 1;
+       if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
+           (sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
+               dirhead.dot_type = IFTODT(EXT2_IFDIR);
+       else
+               dirhead.dot_type = 0;
+       dirhead.dotdot_namlen = 2;
+       if (sblock.e2fs.e2fs_rev > E2FS_REV0 &&
+           (sblock.e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE))
+               dirhead.dotdot_type = IFTODT(EXT2_IFDIR);
+       else
+               dirhead.dotdot_type = 0;
        dirp = &dirhead;
        dirp->dot_ino = h2fs32(ino);
        dirp->dotdot_ino = h2fs32(parent);
diff -r b7e824c040f1 -r 0e177b4c7f67 sbin/fsck_ext2fs/fsck.h
--- a/sbin/fsck_ext2fs/fsck.h   Wed Jan 26 15:50:52 2000 +0000
+++ b/sbin/fsck_ext2fs/fsck.h   Wed Jan 26 16:21:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fsck.h,v 1.2 1997/10/09 13:19:35 bouyer Exp $  */
+/*     $NetBSD: fsck.h,v 1.3 2000/01/26 16:21:31 bouyer Exp $  */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -184,6 +184,7 @@
 ino_t  maxino;                 /* number of inodes in file system */
 ino_t  lastino;                /* last inode in use */
 char   *statemap;              /* ptr to inode state table */
+u_char *typemap;               /* ptr to inode type table */
 int16_t        *lncntp;                /* ptr to link count table */
 
 ino_t  lfdir;                  /* lost & found directory inode number */
diff -r b7e824c040f1 -r 0e177b4c7f67 sbin/fsck_ext2fs/inode.c
--- a/sbin/fsck_ext2fs/inode.c  Wed Jan 26 15:50:52 2000 +0000
+++ b/sbin/fsck_ext2fs/inode.c  Wed Jan 26 16:21:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inode.c,v 1.6 1999/02/17 13:11:19 bouyer Exp $ */
+/*     $NetBSD: inode.c,v 1.7 2000/01/26 16:21:32 bouyer Exp $ */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)inode.c    8.5 (Berkeley) 2/8/95";
 #else
-__RCSID("$NetBSD: inode.c,v 1.6 1999/02/17 13:11:19 bouyer Exp $");
+__RCSID("$NetBSD: inode.c,v 1.7 2000/01/26 16:21:32 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -50,6 +50,7 @@
 #include <ufs/ext2fs/ext2fs.h>
 
 #include <ufs/ufs/dinode.h> /* for IFMT & friends */
+#include <ufs/ufs/dir.h> /* for IFTODT & friends */
 #ifndef SMALL
 #include <pwd.h>
 #endif
@@ -502,7 +503,7 @@
        struct inodesc *idesc;
 {
        struct ext2fs_direct *dirp = idesc->id_dirp;
-       u_int16_t namlen = fs2h16(dirp->e2d_namlen);
+       u_int16_t namlen = dirp->e2d_namlen;
 
        if (fs2h32(dirp->e2d_ino) != idesc->id_parent)
                return (KEEPON);
@@ -637,6 +638,7 @@
        dp->e2di_nblock = h2fs32(btodb(sblock.e2fs_bsize));
        n_files++;
        inodirty();
+       typemap[ino] = IFTODT(type);
        return (ino);
 }
 
diff -r b7e824c040f1 -r 0e177b4c7f67 sbin/fsck_ext2fs/main.c
--- a/sbin/fsck_ext2fs/main.c   Wed Jan 26 15:50:52 2000 +0000
+++ b/sbin/fsck_ext2fs/main.c   Wed Jan 26 16:21:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.6 1998/07/26 20:27:20 mycroft Exp $ */
+/*     $NetBSD: main.c,v 1.7 2000/01/26 16:21:32 bouyer Exp $  */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.2 (Berkeley) 1/23/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.6 1998/07/26 20:27:20 mycroft Exp $");
+__RCSID("$NetBSD: main.c,v 1.7 2000/01/26 16:21:32 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -193,6 +193,10 @@
         * 1: scan inodes tallying blocks used
         */
        if (preen == 0) {
+               if (sblock.e2fs.e2fs_rev > E2FS_REV0) {
+                       printf("** Last Mounted on %s\n",
+                           sblock.e2fs.e2fs_fsmnt);
+               }
                if (hotroot())
                        printf("** Root file system\n");
                printf("** Phase 1 - Check Blocks and Sizes\n");
diff -r b7e824c040f1 -r 0e177b4c7f67 sbin/fsck_ext2fs/pass1.c
--- a/sbin/fsck_ext2fs/pass1.c  Wed Jan 26 15:50:52 2000 +0000
+++ b/sbin/fsck_ext2fs/pass1.c  Wed Jan 26 16:21:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pass1.c,v 1.6 1999/02/17 13:11:19 bouyer Exp $ */
+/*     $NetBSD: pass1.c,v 1.7 2000/01/26 16:21:32 bouyer Exp $ */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)pass1.c    8.1 (Berkeley) 6/5/93";
 #else
-__RCSID("$NetBSD: pass1.c,v 1.6 1999/02/17 13:11:19 bouyer Exp $");
+__RCSID("$NetBSD: pass1.c,v 1.7 2000/01/26 16:21:32 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -50,6 +50,7 @@
 #include <ufs/ext2fs/ext2fs.h>
 
 #include <ufs/ufs/dinode.h> /* for IFMT & friends */
+#include <ufs/ufs/dir.h> /* for IFTODT & friends */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -247,6 +248,7 @@
        } else {
                statemap[inumber] = FSTATE;
        }
+       typemap[inumber] = IFTODT(mode);
        badblk = dupblk = 0;
        idesc->id_number = inumber;
        (void)ckinode(dp, idesc);
diff -r b7e824c040f1 -r 0e177b4c7f67 sbin/fsck_ext2fs/pass2.c
--- a/sbin/fsck_ext2fs/pass2.c  Wed Jan 26 15:50:52 2000 +0000
+++ b/sbin/fsck_ext2fs/pass2.c  Wed Jan 26 16:21:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pass2.c,v 1.4 1997/10/09 13:19:38 bouyer Exp $ */
+/*     $NetBSD: pass2.c,v 1.5 2000/01/26 16:21:32 bouyer Exp $ */
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)pass2.c    8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: pass2.c,v 1.4 1997/10/09 13:19:38 bouyer Exp $");
+__RCSID("$NetBSD: pass2.c,v 1.5 2000/01/26 16:21:32 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -50,6 +50,7 @@
 #include <ufs/ext2fs/ext2fs.h>
 
 #include <ufs/ufs/dinode.h> /* for IFMT & friends */
+#include <ufs/ufs/dir.h> /* for IFTODT & friends */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -216,7 +217,7 @@
         */
        if (idesc->id_entryno != 0)
                goto chk1;
-       if (fs2h32(dirp->e2d_ino) != 0 && fs2h16(dirp->e2d_namlen) == 1 &&
+       if (fs2h32(dirp->e2d_ino) != 0 && dirp->e2d_namlen == 1 &&
                dirp->e2d_name[0] == '.') {
                if (fs2h32(dirp->e2d_ino) != idesc->id_number) {



Home | Main Index | Thread Index | Old Index