1/* See LICENSE file for copyright and license details. */
2
3
4#include <sys/ioctl.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7
8#include <fcntl.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
12
13#include "util.h"
14
15#define FIFREEZE _IOWR('X', 119, int) /* Freeze */
16#define FITHAW _IOWR('X', 120, int) /* Thaw */
17
18static void
19usage(void)
20{
21 eprintf("usage: %s (-f | -u) mountpoint\n", argv0);
22}
23
24// ?man fsfreeze: suspend access to a filesystem
25// ?man arguments: (-f | -u) mountpoint
26// ?man freeze or unfreeze a filesystem to allow safe backups
27int
28main(int argc, char *argv[])
29{
30 int fflag = 0;
31 int uflag = 0;
32 long p = 1;
33 int fd;
34
35 ARGBEGIN {
36 // ?man -f: force the operation
37 case 'f':
38 fflag = 1;
39 break;
40 // ?man -u: unbuffered output
41 case 'u':
42 uflag = 1;
43 break;
44 default:
45 usage();
46 } ARGEND;
47
48 if (argc != 1)
49 usage();
50
51 if ((fflag ^ uflag) == 0)
52 usage();
53
54 fd = open(argv[0], O_RDONLY);
55 if (fd < 0)
56 eprintf("open: %s:", argv[0]);
57 if (ioctl(fd, fflag == 1 ? FIFREEZE : FITHAW, &p) < 0)
58 eprintf("%s %s:", fflag == 1 ? "FIFREEZE" : "FITHAW", argv[0]);
59 close(fd);
60 return 0;
61}