summaryrefslogtreecommitdiffstats
path: root/sys-utils/fsfreeze.c
diff options
context:
space:
mode:
authorSami Kerola2013-04-02 21:42:49 +0200
committerKarel Zak2013-04-05 13:56:00 +0200
commit5543aaad235ec5ec8a8e354f4271aa9268ed4e28 (patch)
tree821294a7e24d9206510cc8a592c0588a0aa76a49 /sys-utils/fsfreeze.c
parentdmesg: fix usage() output consistancy (diff)
downloadkernel-qcow2-util-linux-5543aaad235ec5ec8a8e354f4271aa9268ed4e28.tar.gz
kernel-qcow2-util-linux-5543aaad235ec5ec8a8e354f4271aa9268ed4e28.tar.xz
kernel-qcow2-util-linux-5543aaad235ec5ec8a8e354f4271aa9268ed4e28.zip
fsfreeze: tell user when mandatory option is not specified
This commit also removes use of internal magic values by replacing them with a enum definition. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/fsfreeze.c')
-rw-r--r--sys-utils/fsfreeze.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/sys-utils/fsfreeze.c b/sys-utils/fsfreeze.c
index 122d95cbf..961f8c1f9 100644
--- a/sys-utils/fsfreeze.c
+++ b/sys-utils/fsfreeze.c
@@ -27,6 +27,12 @@
#include "closestream.h"
#include "optutils.h"
+enum fs_operation {
+ NOOP,
+ FREEZE,
+ UNFREEZE
+};
+
static int freeze_f(int fd)
{
return ioctl(fd, FIFREEZE, 0);
@@ -56,7 +62,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
int main(int argc, char **argv)
{
int fd = -1, c;
- int freeze = -1, rc = EXIT_FAILURE;
+ int action = NOOP, rc = EXIT_FAILURE;
char *path;
struct stat sb;
@@ -88,10 +94,10 @@ int main(int argc, char **argv)
usage(stdout);
break;
case 'f':
- freeze = TRUE;
+ action = FREEZE;
break;
case 'u':
- freeze = FALSE;
+ action = UNFREEZE;
break;
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -102,8 +108,8 @@ int main(int argc, char **argv)
}
}
- if (freeze == -1)
- usage(stderr);
+ if (action == NOOP)
+ errx(EXIT_FAILURE, _("neither --freeze or --unfreeze specified"));
if (optind == argc)
errx(EXIT_FAILURE, _("no filename specified"));
path = argv[optind++];
@@ -127,16 +133,21 @@ int main(int argc, char **argv)
goto done;
}
- if (freeze) {
+ switch (action) {
+ case FREEZE:
if (freeze_f(fd)) {
warn(_("%s: freeze failed"), path);
goto done;
}
- } else {
+ break;
+ case UNFREEZE:
if (unfreeze_f(fd)) {
warn(_("%s: unfreeze failed"), path);
goto done;
}
+ break;
+ default:
+ abort();
}
rc = EXIT_SUCCESS;