push the FFSv1 superblock code into ffs_find_superblock() and hide all the ugliness in this function, out of ufs_open(). NFC. Index: ufs.c =================================================================== RCS file: /cvsroot/src/sys/lib/libsa/ufs.c,v retrieving revision 1.78 diff -p -u -r1.78 ufs.c --- ufs.c 19 Dec 2020 08:51:03 -0000 1.78 +++ ufs.c 12 May 2021 08:41:07 -0000 @@ -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