git: 02b7bf07c5d2 - main - Improve dumpfs(8) error messages when a cylinder group read fails.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 06 Aug 2023 06:10:58 UTC
The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=02b7bf07c5d2ec578fc044b60229c6e951f26087 commit 02b7bf07c5d2ec578fc044b60229c6e951f26087 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2023-08-06 06:09:18 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2023-08-06 06:10:15 +0000 Improve dumpfs(8) error messages when a cylinder group read fails. Previously dumpfs(8) exited when a cylinder group read failed (such as a cylinder-group check-hash failure). Now an error message indicating the cylinder group number and the type of failure is printed and the output continues for the remaining cylinder groups. MFC-after: 1 week Sponsored-by: The FreeBSD Foundation --- sbin/dumpfs/dumpfs.c | 58 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/sbin/dumpfs/dumpfs.c b/sbin/dumpfs/dumpfs.c index a0767c39e6bf..739f281feb7f 100644 --- a/sbin/dumpfs/dumpfs.c +++ b/sbin/dumpfs/dumpfs.c @@ -74,6 +74,7 @@ static const char rcsid[] = #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #define afs disk.d_fs @@ -89,7 +90,7 @@ static void dumpfreespacecg(int); static int marshal(const char *); static void pbits(void *, int); static void pblklist(void *, int, off_t, int); -static void ufserr(const char *); +static const char *ufserr(void); static void usage(void) __dead2; int @@ -132,7 +133,7 @@ main(int argc, char *argv[]) while ((name = *argv++) != NULL) { if (ufs_disk_fillout_blank(&disk, name) == -1 || sbfind(&disk, 0) == -1) { - ufserr(name); + printf("\n%s: %s\n", name, ufserr()); eval |= 1; continue; } @@ -163,7 +164,7 @@ dumpfs(const char *name, int dosb) time_t fstime, fsmtime; int64_t fssize; int32_t fsflags; - int i; + int i, ret; switch (disk.d_ufs) { case 2: @@ -188,7 +189,8 @@ dumpfs(const char *name, int dosb) afs.fs_ncg, (intmax_t)fssize, (intmax_t)afs.fs_dsize); break; default: - goto err; + printf("Unknown filesystem type %d\n", disk.d_ufs); + return (1); } printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n", afs.fs_bsize, afs.fs_bshift, afs.fs_bmask); @@ -243,7 +245,8 @@ dumpfs(const char *name, int dosb) afs.fs_old_nsect, afs.fs_old_npsect, afs.fs_old_spc); break; default: - goto err; + printf("Unknown filesystem type %d\n", disk.d_ufs); + return (1); } printf("old_cpg\t%d\tsize_cg\t%zu\tCGSIZE\t%zu\n", afs.fs_old_cpg, sizeof(struct cg), CGSIZE(&afs)); @@ -329,14 +332,15 @@ dumpfs(const char *name, int dosb) } if (dosb) return (0); + ret = 0; while ((i = cgread(&disk)) != 0) { - if (i == -1 || dumpcg()) - goto err; + if (i == -1) { + ret = 1; + printf("\ncg %d: %s\n", disk.d_lcg, ufserr()); + } else if (dumpcg()) + ret = 1; } - return (0); - -err: ufserr(name); - return (1); + return (ret); } static int @@ -402,17 +406,22 @@ dumpcg(void) static int dumpfreespace(const char *name, int fflag) { - int i; + intmax_t startblkno; + int i, ret; + ret = 0; while ((i = cgread(&disk)) != 0) { - if (i == -1) - goto err; - dumpfreespacecg(fflag); + if (i != -1) { + dumpfreespacecg(fflag); + } else { + startblkno = disk.d_lcg * afs.fs_fpg; + printf("\nBlocks %jd-%jd of cg %d skipped: %s\n", + startblkno, startblkno + afs.fs_fpg - 1, + disk.d_lcg, ufserr()); + ret = 1; + } } - return (0); -err: - ufserr(name); - return (1); + return (ret); } static void @@ -521,13 +530,14 @@ pblklist(void *vp, int max, off_t offset, int fflag) } } -static void -ufserr(const char *name) +static const char * +ufserr(void) { if (disk.d_error != NULL) - warnx("%s: %s", name, disk.d_error); - else if (errno) - warn("%s", name); + return(disk.d_error); + if (errno) + return (strerror(errno)); + return ("unknown error"); } static void