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 | */ |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 7 | //config:config FSFREEZE |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 8 | //config: bool "fsfreeze (3.5 kb)" |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 9 | //config: default y |
Samuel Thibault | 77216c3 | 2022-10-16 02:04:59 +0200 | [diff] [blame^] | 10 | //config: select PLATFORM_LINUX |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 11 | //config: select LONG_OPTS |
| 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: Halt new accesses and flush writes on a mounted filesystem. |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 14 | |
Denys Vlasenko | 9f59849 | 2017-08-05 01:29:12 +0200 | [diff] [blame] | 15 | //applet:IF_FSFREEZE(APPLET_NOEXEC(fsfreeze, fsfreeze, BB_DIR_USR_SBIN, BB_SUID_DROP, fsfreeze)) |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 16 | |
| 17 | //kbuild:lib-$(CONFIG_FSFREEZE) += fsfreeze.o |
| 18 | |
| 19 | //usage:#define fsfreeze_trivial_usage |
| 20 | //usage: "--[un]freeze MOUNTPOINT" |
| 21 | //usage:#define fsfreeze_full_usage "\n\n" |
| 22 | //usage: "Flush and halt writes to MOUNTPOINT" |
| 23 | |
| 24 | #include "libbb.h" |
| 25 | #include <linux/fs.h> |
| 26 | |
| 27 | #ifndef FIFREEZE |
| 28 | # define FIFREEZE _IOWR('X', 119, int) |
| 29 | # define FITHAW _IOWR('X', 120, int) |
| 30 | #endif |
| 31 | |
| 32 | int fsfreeze_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 33 | int fsfreeze_main(int argc UNUSED_PARAM, char **argv) |
| 34 | { |
| 35 | unsigned opts; |
| 36 | int fd; |
| 37 | |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 38 | /* exactly one non-option arg: the mountpoint */ |
| 39 | /* one of opts is required */ |
| 40 | /* opts are mutually exclusive */ |
Denys Vlasenko | 22542ec | 2017-08-08 21:55:02 +0200 | [diff] [blame] | 41 | opts = getopt32long(argv, "^" |
| 42 | "" /* no opts */ |
| 43 | "\0" "=1:""\xff:\xfe:""\xff--\xfe:\xfe--\xff", |
Denys Vlasenko | 036585a | 2017-08-08 16:38:18 +0200 | [diff] [blame] | 44 | "freeze\0" No_argument "\xff" |
| 45 | "unfreeze\0" No_argument "\xfe" |
| 46 | ); |
Denys Vlasenko | b9512fa | 2017-04-11 11:53:05 +0200 | [diff] [blame] | 47 | |
| 48 | fd = xopen(argv[optind], O_RDONLY); |
| 49 | /* Works with NULL arg on linux-4.8.0 */ |
| 50 | xioctl(fd, (opts & 1) ? FIFREEZE : FITHAW, NULL); |
| 51 | |
| 52 | return EXIT_SUCCESS; |
| 53 | } |