From 1e297b34baab956c09003283b8b8b6900bd6cbdf Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 3 Nov 2016 23:37:09 +0900 Subject: [PATCH] sbin/mount_hammer: Fix/cleanup test_volumes() The requirement of this function is basically the same as __verify_volume() in sbin/hammer/ondisk.c, so make it __verify_volume() based. Note that this function doesn't necessarily print the real reason mount(2) failed, as shown in a comment. This function just takes a wild guess with sanity checks on volume header. The real reason is likely to be in dmesg. This originally didn't exist, but was added by 1a607e3e in 2009. --- sbin/mount_hammer/mount_hammer.c | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/sbin/mount_hammer/mount_hammer.c b/sbin/mount_hammer/mount_hammer.c index fb39474720..ea17b64fce 100644 --- a/sbin/mount_hammer/mount_hammer.c +++ b/sbin/mount_hammer/mount_hammer.c @@ -240,17 +240,44 @@ free_volumes(struct hammer_mount_info *info) free(info->volumes); } +/* + * This function is based on __verify_volume() in sbin/hammer/ondisk.c. + */ +static +void +__verify_volume(hammer_volume_ondisk_t ondisk, + const char *vol_name, int vol_count) +{ + if (ondisk->vol_signature != HAMMER_FSBUF_VOLUME) { + errx(1, "%s: Invalid volume signature %016jx", + vol_name, ondisk->vol_signature); + } + if (ondisk->vol_count != vol_count) { + errx(1, "%s: Invalid volume count %d, " + "volume header says %d volumes", + vol_name, vol_count, ondisk->vol_count); + } + if (ondisk->vol_rootvol != HAMMER_ROOT_VOLNO) { + errx(1, "%s: Invalid root volume# %d", + vol_name, ondisk->vol_rootvol); + } +} + +/* + * This function prints a possible reason that mount(2) failed, + * which isn't really necessary as the real reason is likely to + * be in dmesg anyway, but was originally added by 1a607e3e. + */ static void test_volumes(struct hammer_mount_info *info) { int i, fd; - const char *vol; char buf[2048]; /* sizeof(*ondisk) is 1928 */ hammer_volume_ondisk_t ondisk = (hammer_volume_ondisk_t)buf; for (i = 0; i < info->nvolumes; i++) { - vol = info->volumes[i]; + const char *vol = info->volumes[i]; fd = open(vol, O_RDONLY); if (fd < 0) { fprintf(stderr, "%s: Failed to open\n", vol); @@ -259,23 +286,12 @@ test_volumes(struct hammer_mount_info *info) bzero(buf, sizeof(buf)); if (pread(fd, buf, sizeof(buf), 0) != sizeof(buf)) { - fprintf(stderr, - "%s: Failed to read volume header\n", vol); + fprintf(stderr, "%s: Failed to read volume header\n", + vol); goto next; } - if (ondisk->vol_signature != HAMMER_FSBUF_VOLUME) { - fprintf(stderr, - "%s: Invalid volume signature %016jx\n", - vol, ondisk->vol_signature); - goto next; - } - if (ondisk->vol_count != info->nvolumes) { - fprintf(stderr, - "%s: Volume header says %d volumes\n", - vol, ondisk->vol_count); - goto next; - } + __verify_volume(ondisk, vol, info->nvolumes); next: close(fd); } -- 2.11.4.GIT