1 /* vi: set sw=4 ts=4: */
3 * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
5 * Licensed under GPLv2, see file LICENSE in this source tree.
8 //config:config FSFREEZE
9 //config: bool "fsfreeze (3.6 kb)"
11 //config: select PLATFORM_LINUX
12 //config: select LONG_OPTS
14 //config: Halt new accesses and flush writes on a mounted filesystem.
16 //applet:IF_FSFREEZE(APPLET_NOEXEC(fsfreeze, fsfreeze, BB_DIR_USR_SBIN, BB_SUID_DROP, fsfreeze))
18 //kbuild:lib-$(CONFIG_FSFREEZE) += fsfreeze.o
20 //usage:#define fsfreeze_trivial_usage
21 //usage: "--[un]freeze MOUNTPOINT"
22 //usage:#define fsfreeze_full_usage "\n\n"
23 //usage: "Flush and halt writes to MOUNTPOINT"
29 # define FIFREEZE _IOWR('X', 119, int)
30 # define FITHAW _IOWR('X', 120, int)
33 int fsfreeze_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34 int fsfreeze_main(int argc UNUSED_PARAM, char **argv)
39 /* exactly one non-option arg: the mountpoint */
40 /* one of opts is required */
41 /* opts are mutually exclusive */
42 opts = getopt32long(argv, "^"
44 "\0" "=1:""\xff:\xfe:""\xff--\xfe:\xfe--\xff",
45 "freeze\0" No_argument "\xff"
46 "unfreeze\0" No_argument "\xfe"
49 fd = xopen(argv[optind], O_RDONLY);
50 /* Works with NULL arg on linux-4.8.0 */
51 xioctl(fd, (opts & 1) ? FIFREEZE : FITHAW, NULL);