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.
This commit is contained in:
mrg 2021-05-12 08:45:28 +00:00
parent ac6ba04d2d
commit 201465fecc
1 changed files with 20 additions and 31 deletions

View File

@ -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 *, int, struct open_file *, ino32_t *);
#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 length, struct open_file *f,
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, FS *fs)
}
}
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_file *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_file *f)
fs->lfs_dobyteswap = 0;
fs->lfs_hasolddirfmt = (fs->fs_maxsymlinklen <= 0);
#endif
#endif
#ifdef LIBSA_FFSv1
ffs_oldfscompat(fs);
#endif