Source-Changes-HG archive

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

[src/trunk]: src/sys/lib/libsa push the FFSv1 superblock code into ffs_find_s...



details:   https://anonhg.NetBSD.org/src/rev/b0d6dd460731
branches:  trunk
changeset: 379118:b0d6dd460731
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed May 12 08:45:28 2021 +0000

description:
push the FFSv1 superblock code into ffs_find_superblock() and
hide all the ugliness in this function, out of ufs_open().

NFC, objects same size if not identical.

diffstat:

 sys/lib/libsa/ufs.c |  51 ++++++++++++++++++++-------------------------------
 1 files changed, 20 insertions(+), 31 deletions(-)

diffs (101 lines):

diff -r b5ff21cbbae4 -r b0d6dd460731 sys/lib/libsa/ufs.c
--- a/sys/lib/libsa/ufs.c       Wed May 12 06:39:28 2021 +0000
+++ b/sys/lib/libsa/ufs.c       Wed May 12 08:45:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs.c,v 1.78 2020/12/19 08:51:03 rin Exp $     */
+/*     $NetBSD: ufs.c,v 1.79 2021/05/12 08:45:28 mrg Exp $     */
 
 /*-
  * Copyright (c) 1993
@@ -201,9 +201,6 @@ static int search_directory(const char *
 #ifdef LIBSA_FFSv1
 static void ffs_oldfscompat(FS *);
 #endif
-#ifdef LIBSA_FFSv2
-static int ffs_find_superblock(struct open_file *, FS *);
-#endif
 
 
 #ifdef LIBSA_LFS
@@ -513,15 +510,14 @@ search_directory(const char *name, int l
        return ENOENT;
 }
 
-#ifdef LIBSA_FFSv2
-
-daddr_t sblock_try[] = SBLOCKSEARCH;
-
-static int
+static __inline__ int
 ffs_find_superblock(struct open_file *f, FS *fs)
 {
-       int i, rc;
+       int rc;
        size_t buf_size;
+#ifdef LIBSA_FFSv2
+       static daddr_t sblock_try[] = SBLOCKSEARCH;
+       int i;
 
        for (i = 0; sblock_try[i] != -1; i++) {
                rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
@@ -536,10 +532,21 @@ ffs_find_superblock(struct open_file *f,
                }
        }
        return EINVAL;
+#else /* LIBSA_FFSv2 */
+       rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
+               SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
+       if (rc)
+               return rc;
+       if (buf_size != SBLOCKSIZE ||
+#ifdef LIBSA_LFS
+           fs->lfs_version != REQUIRED_LFS_VERSION ||
+#endif
+           fs->fs_magic != FS_MAGIC)
+               return EINVAL;
+       return 0;
+#endif /* !LIBSA_FFSv2 */
 }
 
-#endif
-
 /*
  * Open a file.
  */
@@ -571,26 +578,10 @@ ufs_open(const char *path, struct open_f
        fp->f_fs = fs;
        twiddle();
 
-#ifdef LIBSA_FFSv2
        rc = ffs_find_superblock(f, fs);
        if (rc)
                goto out;
-#else
-       {
-               size_t buf_size;
-               rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-                       SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size);
-               if (rc)
-                       goto out;
-               if (buf_size != SBLOCKSIZE ||
-#ifdef LIBSA_LFS
-                   fs->lfs_version != REQUIRED_LFS_VERSION ||
-#endif
-                   fs->fs_magic != FS_MAGIC) {
-                       rc = EINVAL;
-                       goto out;
-               }
-       }
+
 #if defined(LIBSA_LFS) && REQUIRED_LFS_VERSION == 2
        /*
         * XXX  We should check the second superblock and use the eldest
@@ -604,8 +595,6 @@ ufs_open(const char *path, struct open_f
        fs->lfs_dobyteswap = 0;
        fs->lfs_hasolddirfmt = (fs->fs_maxsymlinklen <= 0);
 #endif
-#endif
-
 #ifdef LIBSA_FFSv1
        ffs_oldfscompat(fs);
 #endif



Home | Main Index | Thread Index | Old Index