Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com> |
| 4 | * |
| 5 | * Licensed under GPLv2, see file LICENSE in this source tree. |
| 6 | */ |
| 7 | |
| 8 | //config:config FSFREEZE |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 9 | //config: bool "fsfreeze (3.6 kb)" |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 10 | //config: default y |
| 11 | //config: select PLATFORM_LINUX |
| 12 | //config: select LONG_OPTS |
| 13 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame^] | 14 | //config: Halt new accesses and flush writes on a mounted filesystem. |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 15 | |
Denys Vlasenko | 67918b3 | 2017-04-11 13:33:54 +0200 | [diff] [blame] | 16 | //applet:IF_FSFREEZE(APPLET(fsfreeze, BB_DIR_USR_SBIN, BB_SUID_DROP)) |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 17 | |
| 18 | //kbuild:lib-$(CONFIG_FSFREEZE) += fsfreeze.o |
| 19 | |
| 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" |
| 24 | |
| 25 | #include "libbb.h" |
| 26 | #include <linux/fs.h> |
| 27 | |
| 28 | #ifndef FIFREEZE |
| 29 | # define FIFREEZE _IOWR('X', 119, int) |
| 30 | # define FITHAW _IOWR('X', 120, int) |
| 31 | #endif |
| 32 | |
| 33 | int fsfreeze_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 34 | int fsfreeze_main(int argc UNUSED_PARAM, char **argv) |
| 35 | { |
| 36 | unsigned opts; |
| 37 | int fd; |
| 38 | |
| 39 | applet_long_options = |
| 40 | "freeze\0" No_argument "\xff" |
| 41 | "unfreeze\0" No_argument "\xfe" |
| 42 | ; |
| 43 | /* exactly one non-option arg: the mountpoint */ |
| 44 | /* one of opts is required */ |
| 45 | /* opts are mutually exclusive */ |
| 46 | opt_complementary = "=1:""\xff:\xfe:""\xff--\xfe:\xfe--\xff"; |
| 47 | opts = getopt32(argv, ""); |
| 48 | |
| 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); |
| 52 | |
| 53 | return EXIT_SUCCESS; |
| 54 | } |