diff options
Diffstat (limited to 'lib/libufs/sblock.c')
-rw-r--r-- | lib/libufs/sblock.c | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/lib/libufs/sblock.c b/lib/libufs/sblock.c index 5708d50aa4f9..09d478bfe71e 100644 --- a/lib/libufs/sblock.c +++ b/lib/libufs/sblock.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2002 Juli Mallett. All rights reserved. * @@ -27,9 +27,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/mount.h> #include <sys/disklabel.h> @@ -73,6 +70,30 @@ sbread(struct uufsd *disk) return (handle_disk_read(disk, fs, error)); } +/* + * Make an extensive search to find a superblock. If the superblock + * in the standard place cannot be used, try looking for one of the + * backup superblocks. + * + * The flags parameter is made up of the following or'ed together options: + * + * UFS_NOMSG indicates that superblock inconsistency error messages + * should not be printed. + * + * UFS_NOCSUM causes only the superblock itself to be returned, but does + * not read in any auxillary data structures like the cylinder group + * summary information. + */ +int +sbfind(struct uufsd *disk, int flags) +{ + struct fs *fs; + int error; + + error = sbsearch(disk->d_fd, &fs, flags); + return (handle_disk_read(disk, fs, error)); +} + static int handle_disk_read(struct uufsd *disk, struct fs *fs, int error) { @@ -174,8 +195,27 @@ static int use_pwrite(void *devfd, off_t loc, void *buf, int size); int sbget(int devfd, struct fs **fsp, off_t sblockloc, int flags) { + int error; + + error = ffs_sbget(&devfd, fsp, sblockloc, flags, "user", use_pread); + fflush(NULL); /* flush any messages */ + return (error); +} + +/* + * Make an extensive search of the devfd device to find a superblock. + * If the superblock in the standard place cannot be used, try looking + * for one of the backup superblocks. If found, memory is allocated and + * returned in fsp. + */ +int +sbsearch(int devfd, struct fs **fsp, int flags) +{ + int error; - return (ffs_sbget(&devfd, fsp, sblockloc, flags, "user", use_pread)); + error = ffs_sbsearch(&devfd, fsp, flags, "user", use_pread); + fflush(NULL); /* flush any messages */ + return (error); } /* @@ -187,7 +227,8 @@ use_pread(void *devfd, off_t loc, void **bufp, int size) int fd; fd = *(int *)devfd; - if ((*bufp = malloc(size)) == NULL) + BUF_MALLOC(bufp, NULL, size); + if (*bufp == NULL) return (ENOSPC); if (pread(fd, *bufp, size, loc) != size) return (EIO); @@ -209,11 +250,10 @@ sbput(int devfd, struct fs *fs, int numaltwrite) off_t savedactualloc; int i, error; - if ((error = ffs_sbput(&devfd, fs, fs->fs_sblockactualloc, - use_pwrite)) != 0) + error = ffs_sbput(&devfd, fs, fs->fs_sblockactualloc, use_pwrite); + fflush(NULL); /* flush any messages */ + if (error != 0 || numaltwrite == 0) return (error); - if (numaltwrite == 0) - return (0); savedactualloc = fs->fs_sblockactualloc; if (fs->fs_si != NULL) { savedcsp = fs->fs_csp; @@ -223,6 +263,7 @@ sbput(int devfd, struct fs *fs, int numaltwrite) fs->fs_sblockactualloc = dbtob(fsbtodb(fs, cgsblock(fs, i))); if ((error = ffs_sbput(&devfd, fs, fs->fs_sblockactualloc, use_pwrite)) != 0) { + fflush(NULL); /* flush any messages */ fs->fs_sblockactualloc = savedactualloc; fs->fs_csp = savedcsp; return (error); @@ -231,6 +272,7 @@ sbput(int devfd, struct fs *fs, int numaltwrite) fs->fs_sblockactualloc = savedactualloc; if (fs->fs_si != NULL) fs->fs_csp = savedcsp; + fflush(NULL); /* flush any messages */ return (0); } |