From b9512fa6b32dacabdec3edf12ebfab927d1402ae Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 11 Apr 2017 11:53:05 +0200 Subject: [PATCH] fsfreeze: new applet NAME fsfreeze - suspend access to a filesystem (Ext3/4, ReiserFS, JFS, XFS) SYNOPSIS fsfreeze --freeze|--unfreeze mountpoint DESCRIPTION fsfreeze suspends or resumes access to a filesystem. fsfreeze halts any new access to the filesystem and creates a stable image on disk. AVAILABILITY The fsfreeze command is part of the util-linux 2.28 function old new delta fsfreeze_main - 81 +81 applet_names 2597 2606 +9 applet_main 1504 1508 +4 applet_suid 94 95 +1 applet_install_loc 188 189 +1 Signed-off-by: Denys Vlasenko --- util-linux/fsfreeze.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 util-linux/fsfreeze.c diff --git a/util-linux/fsfreeze.c b/util-linux/fsfreeze.c new file mode 100644 index 000000000..fb1ebdc1e --- /dev/null +++ b/util-linux/fsfreeze.c @@ -0,0 +1,54 @@ +/* vi: set sw=4 ts=4: */ +/* + * Copyright (C) 2017 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ + +//config:config FSFREEZE +//config: bool "fsfreeze" +//config: default y +//config: select PLATFORM_LINUX +//config: select LONG_OPTS +//config: help +//config: Halt new accesses and flush writes on a mounted filesystem. + +//applet:IF_FSFREEZE(APPLET(fsfreeze, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_FSFREEZE) += fsfreeze.o + +//usage:#define fsfreeze_trivial_usage +//usage: "--[un]freeze MOUNTPOINT" +//usage:#define fsfreeze_full_usage "\n\n" +//usage: "Flush and halt writes to MOUNTPOINT" + +#include "libbb.h" +#include + +#ifndef FIFREEZE +# define FIFREEZE _IOWR('X', 119, int) +# define FITHAW _IOWR('X', 120, int) +#endif + +int fsfreeze_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int fsfreeze_main(int argc UNUSED_PARAM, char **argv) +{ + unsigned opts; + int fd; + + applet_long_options = + "freeze\0" No_argument "\xff" + "unfreeze\0" No_argument "\xfe" + ; + /* exactly one non-option arg: the mountpoint */ + /* one of opts is required */ + /* opts are mutually exclusive */ + opt_complementary = "=1:""\xff:\xfe:""\xff--\xfe:\xfe--\xff"; + opts = getopt32(argv, ""); + + fd = xopen(argv[optind], O_RDONLY); + /* Works with NULL arg on linux-4.8.0 */ + xioctl(fd, (opts & 1) ? FIFREEZE : FITHAW, NULL); + + return EXIT_SUCCESS; +} -- 2.25.1