aboutsummaryrefslogtreecommitdiffstats
path: root/sbin/fsck_ffs
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 /sbin/fsck_ffs
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 'sbin/fsck_ffs')
-rw-r--r--sbin/fsck_ffs/fsck.h2
-rw-r--r--sbin/fsck_ffs/fsutil.c13
-rw-r--r--sbin/fsck_ffs/globs.c2
-rw-r--r--sbin/fsck_ffs/setup.c72
4 files changed, 31 insertions, 58 deletions
diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h
index 83c559aa16a1..56f01501022a 100644
--- a/sbin/fsck_ffs/fsck.h
+++ b/sbin/fsck_ffs/fsck.h
@@ -308,7 +308,7 @@ extern u_int real_dev_bsize; /* actual disk sector size, not overridden */
extern char nflag; /* assume a no response */
extern char yflag; /* assume a yes response */
extern int bkgrdflag; /* use a snapshot to run on an active system */
-extern ufs2_daddr_t bflag; /* location of alternate super block */
+extern off_t bflag; /* location of alternate super block */
extern int debug; /* output debugging info */
extern int Eflag; /* delete empty data blocks */
extern int Zflag; /* zero empty data blocks */
diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c
index 69c92d7f35c9..d4a5f81bbfa7 100644
--- a/sbin/fsck_ffs/fsutil.c
+++ b/sbin/fsck_ffs/fsutil.c
@@ -348,7 +348,6 @@ getblk(struct bufarea *bp, ufs2_daddr_t blk, long size)
void
flush(int fd, struct bufarea *bp)
{
- int i, j;
if (!bp->b_dirty)
return;
@@ -370,14 +369,8 @@ flush(int fd, struct bufarea *bp)
if (bp != &sblk)
pfatal("BUFFER %p DOES NOT MATCH SBLK %p\n",
bp, &sblk);
- blwrite(fd, bp->b_un.b_buf, bp->b_bno, bp->b_size);
- for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize,
- j++) {
- blwrite(fswritefd, (char *)sblock.fs_csp + i,
- fsbtodb(&sblock,
- sblock.fs_csaddr + j * sblock.fs_frag),
- MIN(sblock.fs_cssize - i, sblock.fs_bsize));
- }
+ if (sbput(fd, (struct fs *)bp->b_un.b_buf, 0) == 0)
+ fsmodified = 1;
break;
case BT_CYLGRP:
if (cgput(&disk, (struct cg *)bp->b_un.b_buf) == 0)
@@ -439,6 +432,8 @@ ckfini(int markclean)
if (havesb && cursnapshot == 0 && sblock.fs_magic == FS_UFS2_MAGIC &&
sblk.b_bno != sblock.fs_sblockloc / dev_bsize &&
!preen && reply("UPDATE STANDARD SUPERBLOCK")) {
+ /* Change the write destination to standard superblock */
+ sblock.fs_sblockactualloc = sblock.fs_sblockloc;
sblk.b_bno = sblock.fs_sblockloc / dev_bsize;
sbdirty();
flush(fswritefd, &sblk);
diff --git a/sbin/fsck_ffs/globs.c b/sbin/fsck_ffs/globs.c
index f3522973404e..6ce7dfd032c4 100644
--- a/sbin/fsck_ffs/globs.c
+++ b/sbin/fsck_ffs/globs.c
@@ -80,7 +80,7 @@ u_int real_dev_bsize; /* actual disk sector size, not overridden */
char nflag; /* assume a no response */
char yflag; /* assume a yes response */
int bkgrdflag; /* use a snapshot to run on an active system */
-ufs2_daddr_t bflag; /* location of alternate super block */
+off_t bflag; /* location of alternate super block */
int debug; /* output debugging info */
int Eflag; /* delete empty data blocks */
int Zflag; /* zero empty data blocks */
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index c1e8d45e21db..0cc943797c10 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -311,70 +311,48 @@ badsb:
}
/*
- * Possible superblock locations ordered from most to least likely.
- */
-static int sblock_try[] = SBLOCKSEARCH;
-
-#define BAD_MAGIC_MSG \
-"The previous newfs operation on this volume did not complete.\n" \
-"You must complete newfs before mounting this volume.\n"
-
-/*
* Read in the super block and its summary info.
*/
int
readsb(int listerr)
{
- ufs2_daddr_t super;
- int i, bad;
+ off_t super;
+ int bad, ret;
+ struct fs *fs;
- if (bflag) {
- super = bflag;
- readcnt[sblk.b_type]++;
- if ((blread(fsreadfd, (char *)&sblock, super, (long)SBLOCKSIZE)))
- return (0);
- if (sblock.fs_magic == FS_BAD_MAGIC) {
- fprintf(stderr, BAD_MAGIC_MSG);
+ super = bflag ? bflag * dev_bsize : -1;
+ readcnt[sblk.b_type]++;
+ if ((ret = sbget(fsreadfd, &fs, super)) != 0) {
+ switch (ret) {
+ case EINVAL:
+ fprintf(stderr, "The previous newfs operation "
+ "on this volume did not complete.\nYou must "
+ "complete newfs before using this volume.\n");
exit(11);
- }
- if (sblock.fs_magic != FS_UFS1_MAGIC &&
- sblock.fs_magic != FS_UFS2_MAGIC) {
- fprintf(stderr, "%jd is not a file system superblock\n",
- bflag);
+ case ENOENT:
+ if (bflag)
+ fprintf(stderr, "%jd is not a file system "
+ "superblock\n", super / dev_bsize);
+ else
+ fprintf(stderr, "Cannot find file system "
+ "superblock\n");
return (0);
- }
- } else {
- for (i = 0; sblock_try[i] != -1; i++) {
- super = sblock_try[i] / dev_bsize;
- readcnt[sblk.b_type]++;
- if ((blread(fsreadfd, (char *)&sblock, super,
- (long)SBLOCKSIZE)))
- return (0);
- if (sblock.fs_magic == FS_BAD_MAGIC) {
- fprintf(stderr, BAD_MAGIC_MSG);
- exit(11);
- }
- if ((sblock.fs_magic == FS_UFS1_MAGIC ||
- (sblock.fs_magic == FS_UFS2_MAGIC &&
- sblock.fs_sblockloc == sblock_try[i])) &&
- sblock.fs_ncg >= 1 &&
- sblock.fs_bsize >= MINBSIZE &&
- sblock.fs_sbsize >= roundup(sizeof(struct fs), dev_bsize))
- break;
- }
- if (sblock_try[i] == -1) {
- fprintf(stderr, "Cannot find file system superblock\n");
+ case EIO:
+ default:
+ fprintf(stderr, "I/O error reading %jd\n",
+ super / dev_bsize);
return (0);
}
}
+ memcpy(&sblock, fs, fs->fs_sbsize);
+ free(fs);
/*
* Compute block size that the file system is based on,
* according to fsbtodb, and adjust superblock block number
* so we can tell if this is an alternate later.
*/
- super *= dev_bsize;
dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
- sblk.b_bno = super / dev_bsize;
+ sblk.b_bno = sblock.fs_sblockactualloc / dev_bsize;
sblk.b_size = SBLOCKSIZE;
/*
* Compare all fields that should not differ in alternate super block.