From 06a1d31fe1e13bc69789a3ebb767957fa9271217 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Tue, 11 Apr 2017 22:22:41 +0300 Subject: [PATCH] sbin/hammer: Add is_regfile() (avoid directly using a string literal) --- sbin/hammer/cmd_volume.c | 2 +- sbin/hammer/hammer_util.h | 1 + sbin/hammer/ondisk.c | 6 ++++++ sbin/newfs_hammer/newfs_hammer.c | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sbin/hammer/cmd_volume.c b/sbin/hammer/cmd_volume.c index 3d36623fc3..8f1d383b19 100644 --- a/sbin/hammer/cmd_volume.c +++ b/sbin/hammer/cmd_volume.c @@ -71,7 +71,7 @@ hammer_cmd_volume_add(char **av, int ac) */ volume = init_volume(device, O_RDONLY, -1); assert(volume->vol_no == -1); - if (strcmp(volume->type, "DEVICE")) + if (is_regfile(volume)) errx(1, "Not a block device: %s", device); close(volume->fd); diff --git a/sbin/hammer/hammer_util.h b/sbin/hammer/hammer_util.h index 59819234a2..921f059dfc 100644 --- a/sbin/hammer/hammer_util.h +++ b/sbin/hammer/hammer_util.h @@ -121,6 +121,7 @@ extern const char *zone_labels[]; struct volume_info *init_volume(const char *filename, int oflags, int32_t vol_no); struct volume_info *load_volume(const char *filename, int oflags, int verify); +int is_regfile(struct volume_info *volume); void assert_volume_offset(struct volume_info *volume); struct volume_info *get_volume(int32_t vol_no); struct volume_info *get_root_volume(void); diff --git a/sbin/hammer/ondisk.c b/sbin/hammer/ondisk.c index 13d591164e..cdd45dd453 100644 --- a/sbin/hammer/ondisk.c +++ b/sbin/hammer/ondisk.c @@ -244,6 +244,12 @@ check_volume(struct volume_info *volume) } } +int +is_regfile(struct volume_info *volume) +{ + return(strcmp(volume->type, "REGFILE") ? 0 : 1); +} + void assert_volume_offset(struct volume_info *volume) { diff --git a/sbin/newfs_hammer/newfs_hammer.c b/sbin/newfs_hammer/newfs_hammer.c index 97e265a78f..cb666d7999 100644 --- a/sbin/newfs_hammer/newfs_hammer.c +++ b/sbin/newfs_hammer/newfs_hammer.c @@ -477,7 +477,7 @@ nowtime(void) } /* - * TRIM the volume, but only if the backing store is a DEVICE + * TRIM the volume, but only if the backing store is not a regular file */ static int @@ -489,7 +489,7 @@ trim_volume(struct volume_info *volume) int trim_enabled; off_t ioarg[2]; - if (strcmp(volume->type, "DEVICE")) { + if (is_regfile(volume)) { hwarnx("Cannot TRIM regular file %s", volume->name); return(-1); } -- 2.11.4.GIT