aboutsummaryrefslogtreecommitdiff
path: root/stand/libsa/ufs.c
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2018-01-26 00:58:32 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2018-01-26 00:58:32 +0000
commitdffce2150eeac1c7f424324a5cade7a97b308979 (patch)
tree3de8c223a1cb007078f3bb3e3c062127eb1b80a8 /stand/libsa/ufs.c
parenta99028fc70be602db425c092b70dd0221e253bb3 (diff)
downloadsrc-dffce2150eeac1c7f424324a5cade7a97b308979.tar.gz
src-dffce2150eeac1c7f424324a5cade7a97b308979.zip
Refactoring of reading and writing of the UFS/FFS superblock.
Specifically reading is done if ffs_sbget() and writing is done in ffs_sbput(). These functions are exported to libufs via the sbget() and sbput() functions which then used in the various filesystem utilities. This work is in preparation for adding subperblock check hashes. No functional change intended. Reviewed by: kib
Notes
Notes: svn path=/head/; revision=328426
Diffstat (limited to 'stand/libsa/ufs.c')
-rw-r--r--stand/libsa/ufs.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/stand/libsa/ufs.c b/stand/libsa/ufs.c
index e0ceed804d9a..1f0b7d3591f6 100644
--- a/stand/libsa/ufs.c
+++ b/stand/libsa/ufs.c
@@ -133,6 +133,11 @@ static int block_map(struct open_file *, ufs2_daddr_t, ufs2_daddr_t *);
static int buf_read_file(struct open_file *, char **, size_t *);
static int buf_write_file(struct open_file *, char *, size_t *);
static int search_directory(char *, struct open_file *, ino_t *);
+static int ufs_use_sa_read(void *, off_t, void **, int);
+
+/* from ffs_subr.c */
+int ffs_sbget(void *, struct fs **, off_t, char *,
+ int (*)(void *, off_t, void **, int));
/*
* Read a new inode into a file structure.
@@ -485,8 +490,6 @@ search_directory(name, f, inumber_p)
return (ENOENT);
}
-static int sblock_try[] = SBLOCKSEARCH;
-
/*
* Open a file.
*/
@@ -512,31 +515,11 @@ ufs_open(upath, f)
bzero(fp, sizeof(struct file));
f->f_fsdata = (void *)fp;
- /* allocate space and read super block */
- fs = malloc(SBLOCKSIZE);
- fp->f_fs = fs;
+ /* read super block */
twiddle(1);
- /*
- * Try reading the superblock in each of its possible locations.
- */
- for (i = 0; sblock_try[i] != -1; i++) {
- rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
- sblock_try[i] / DEV_BSIZE, SBLOCKSIZE,
- (char *)fs, &buf_size);
- if (rc)
- goto out;
- if ((fs->fs_magic == FS_UFS1_MAGIC ||
- (fs->fs_magic == FS_UFS2_MAGIC &&
- fs->fs_sblockloc == sblock_try[i])) &&
- buf_size == SBLOCKSIZE &&
- fs->fs_bsize <= MAXBSIZE &&
- fs->fs_bsize >= sizeof(struct fs))
- break;
- }
- if (sblock_try[i] == -1) {
- rc = EINVAL;
+ if ((rc = ffs_sbget(f, &fs, -1, 0, ufs_use_sa_read)) != 0)
goto out;
- }
+ fp->f_fs = fs;
/*
* Calculate indirect block levels.
*/
@@ -693,6 +676,28 @@ out:
return (rc);
}
+/*
+ * A read function for use by standalone-layer routines.
+ */
+static int
+ufs_use_sa_read(void *devfd, off_t loc, void **bufp, int size)
+{
+ struct open_file *f;
+ size_t buf_size;
+ int error;
+
+ f = (struct open_file *)devfd;
+ if ((*bufp = malloc(size)) == NULL)
+ return (ENOSPC);
+ error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, loc / DEV_BSIZE,
+ size, *bufp, &buf_size);
+ if (error != 0)
+ return (error);
+ if (buf_size != size)
+ return (EIO);
+ return (0);
+}
+
static int
ufs_close(f)
struct open_file *f;