2 * fsfreeze.c -- Filesystem freeze/unfreeze IO for Linux
4 * Copyright (C) 2010 Hajime Taira <htaira@redhat.com>
5 * Masatake Yamato <yamato@redhat.com>
7 * This program is free software. You can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation: either version 1 or
10 * (at your option) any later version.
19 #include <sys/ioctl.h>
20 #include <sys/types.h>
26 #include "closestream.h"
29 static int freeze_f(int fd
)
31 return ioctl(fd
, FIFREEZE
, 0);
34 static int unfreeze_f(int fd
)
36 return ioctl(fd
, FITHAW
, 0);
39 static void __attribute__((__noreturn__
)) usage(FILE *out
)
41 fputs(_("\nUsage:\n"), out
);
43 _(" %s [options] <mount point>\n"), program_invocation_short_name
);
45 fputs(_("\nOptions:\n"), out
);
46 fputs(_(" -h, --help this help\n"
47 " -f, --freeze freeze the filesystem\n"
48 " -u, --unfreeze unfreeze the filesystem\n"), out
);
50 fputs(_("\nFor more information see fsfreeze(8).\n"), out
);
52 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
55 int main(int argc
, char **argv
)
58 int freeze
= -1, rc
= EXIT_FAILURE
;
62 static const struct option longopts
[] = {
63 { "help", 0, 0, 'h' },
64 { "freeze", 0, 0, 'f' },
65 { "unfreeze", 0, 0, 'u' },
69 setlocale(LC_ALL
, "");
70 bindtextdomain(PACKAGE
, LOCALEDIR
);
74 while ((c
= getopt_long(argc
, argv
, "hfu", longopts
, NULL
)) != -1) {
92 errx(EXIT_FAILURE
, _("no action specified"));
94 errx(EXIT_FAILURE
, _("no filename specified"));
95 path
= argv
[optind
++];
98 warnx(_("unexpected number of arguments"));
102 fd
= open(path
, O_RDONLY
);
104 err(EXIT_FAILURE
, _("%s: open failed"), path
);
106 if (fstat(fd
, &sb
) == -1) {
107 warn(_("%s: fstat failed"), path
);
111 if (!S_ISDIR(sb
.st_mode
)) {
112 warnx(_("%s: is not a directory"), path
);
118 warn(_("%s: freeze failed"), path
);
122 if (unfreeze_f(fd
)) {
123 warn(_("%s: unfreeze failed"), path
);