Module Name:    src
Committed By:   mrg
Date:           Wed May 12 08:45:28 UTC 2021

Modified Files:
        src/sys/lib/libsa: ufs.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/lib/libsa/ufs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/lib/libsa/ufs.c
diff -u src/sys/lib/libsa/ufs.c:1.78 src/sys/lib/libsa/ufs.c:1.79
--- src/sys/lib/libsa/ufs.c:1.78	Sat Dec 19 08:51:03 2020
+++ src/sys/lib/libsa/ufs.c	Wed May 12 08:45:28 2021
@@ -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,9 +532,20 @@ 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 */
+}
 
 /*
  * 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

Reply via email to