2
* fsfreeze.c -- Filesystem freeze/unfreeze IO for Linux
4
* Copyright (C) 2010 Hajime Taira <htaira@redhat.com>
5
* Masatake Yamato <yamato@redhat.com>
7
* This program is free software. You can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation: either version 1 or
10
* (at your option) any later version.
19
#include <sys/ioctl.h>
20
#include <sys/types.h>
29
static int freeze_f(int fd)
31
return ioctl(fd, FIFREEZE, 0);
34
static int unfreeze_f(int fd)
36
return ioctl(fd, FITHAW, 0);
39
static void __attribute__((__noreturn__)) usage(FILE *out)
41
fprintf(out, _("Usage: %s [options] <mount point>\n\nOptions:\n"),
42
program_invocation_short_name);
45
" -h, --help this help\n"
46
" -f, --freeze freeze the filesystem\n"
47
" -u, --unfreeze unfreeze the filesystem\n"));
49
fprintf(out, _("\nFor more information see fsfreeze(8).\n"));
51
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
54
int main(int argc, char **argv)
57
int freeze = -1, rc = EXIT_FAILURE;
61
struct option longopts[] = {
62
{ "help", 0, 0, 'h' },
63
{ "freeze", 0, 0, 'f' },
64
{ "unfreeze", 0, 0, 'u' },
68
setlocale(LC_ALL, "");
69
bindtextdomain(PACKAGE, LOCALEDIR);
72
while ((c = getopt_long(argc, argv, "hfu", longopts, NULL)) != -1) {
90
errx(EXIT_FAILURE, _("no action specified"));
92
errx(EXIT_FAILURE, _("no filename specified"));
93
path = argv[optind++];
96
warnx(_("unexpected number of arguments"));
100
fd = open(path, O_RDONLY);
102
err(EXIT_FAILURE, _("%s: open failed"), path);
104
if (fstat(fd, &sb) == -1) {
105
warn(_("%s: fstat failed"), path);
109
if (!S_ISDIR(sb.st_mode)) {
110
warnx(_("%s: is not a directory"), path);
116
warn(_("%s: freeze failed"), path);
120
if (unfreeze_f(fd)) {
121
warn(_("%s: unfreeze failed"), path);