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>
27 #include "closestream.h"
36 static void __attribute__((__noreturn__
)) usage(void)
39 fputs(USAGE_HEADER
, out
);
41 _(" %s [options] <mountpoint>\n"), program_invocation_short_name
);
43 fputs(USAGE_SEPARATOR
, out
);
44 fputs(_("Suspend access to a filesystem.\n"), out
);
46 fputs(USAGE_OPTIONS
, out
);
47 fputs(_(" -f, --freeze freeze the filesystem\n"), out
);
48 fputs(_(" -u, --unfreeze unfreeze the filesystem\n"), out
);
49 fputs(USAGE_SEPARATOR
, out
);
50 fputs(USAGE_HELP
, out
);
51 fputs(USAGE_VERSION
, out
);
52 fprintf(out
, USAGE_MAN_TAIL("fsfreeze(8)"));
57 int main(int argc
, char **argv
)
60 int action
= NOOP
, rc
= EXIT_FAILURE
;
64 static const struct option longopts
[] = {
65 { "help", no_argument
, NULL
, 'h' },
66 { "freeze", no_argument
, NULL
, 'f' },
67 { "unfreeze", no_argument
, NULL
, 'u' },
68 { "version", no_argument
, NULL
, 'V' },
72 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
73 { 'f','u' }, /* freeze, unfreeze */
76 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
78 setlocale(LC_ALL
, "");
79 bindtextdomain(PACKAGE
, LOCALEDIR
);
83 while ((c
= getopt_long(argc
, argv
, "hfuV", longopts
, NULL
)) != -1) {
85 err_exclusive_options(c
, longopts
, excl
, excl_st
);
98 printf(UTIL_LINUX_VERSION
);
101 errtryhelp(EXIT_FAILURE
);
106 errx(EXIT_FAILURE
, _("neither --freeze or --unfreeze specified"));
108 errx(EXIT_FAILURE
, _("no filename specified"));
109 path
= argv
[optind
++];
111 if (optind
!= argc
) {
112 warnx(_("unexpected number of arguments"));
113 errtryhelp(EXIT_FAILURE
);
116 fd
= open(path
, O_RDONLY
);
118 err(EXIT_FAILURE
, _("cannot open %s"), path
);
120 if (fstat(fd
, &sb
) == -1) {
121 warn(_("stat of %s failed"), path
);
125 if (!S_ISDIR(sb
.st_mode
)) {
126 warnx(_("%s: is not a directory"), path
);
132 if (ioctl(fd
, FIFREEZE
, 0)) {
133 warn(_("%s: freeze failed"), path
);
138 if (ioctl(fd
, FITHAW
, 0)) {
139 warn(_("%s: unfreeze failed"), path
);