]>
Commit | Line | Data |
---|---|---|
d9eab45c SL |
1 | /* |
2 | * Copyright (c) 2001 Silicon Graphics, Inc. All Rights Reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | ||
33 | #include <libxfs.h> | |
34 | #include <sys/ioctl.h> | |
35 | #include <sys/vfs.h> | |
36 | ||
37 | char *progname; | |
38 | ||
39 | static void | |
40 | usage(void) | |
41 | { | |
42 | fprintf(stderr, | |
43 | "Usage: %s [options] mountpoint\n\n\ | |
44 | Options:\n\ | |
45 | -f freeze filesystem access\n\ | |
46 | -u unfreeze filesystem access\n", | |
47 | progname); | |
48 | exit(2); | |
49 | } | |
50 | ||
51 | int | |
52 | main(int argc, char **argv) | |
53 | { | |
54 | int c; /* current option character */ | |
55 | int ffd; /* mount point file descriptor */ | |
56 | int fflag, uflag; | |
57 | int level; | |
58 | struct statfs buf; | |
59 | ||
60 | fflag = uflag = 0; | |
61 | progname = basename(argv[0]); | |
62 | while ((c = getopt(argc, argv, "fu")) != EOF) { | |
63 | switch (c) { | |
64 | case 'f': | |
65 | fflag = 1; | |
66 | break; | |
67 | case 'u': | |
68 | uflag = 1; | |
69 | break; | |
70 | case '?': | |
71 | default: | |
72 | usage(); | |
73 | } | |
74 | } | |
75 | if (argc - optind != 1) | |
76 | usage(); | |
77 | if ((fflag + uflag) != 1) | |
78 | usage(); | |
79 | ||
80 | ffd = open(argv[optind], O_RDONLY); | |
81 | if (ffd < 0) { | |
82 | perror(argv[optind]); | |
83 | return 1; | |
84 | } | |
85 | fstatfs(ffd, &buf); | |
86 | if (buf.f_type != XFS_SUPER_MAGIC) { | |
87 | fprintf(stderr, | |
88 | "%s: specified file is not on an XFS filesystem\n", | |
89 | progname); | |
90 | exit(1); | |
91 | } | |
92 | ||
93 | if (fflag) { | |
94 | level = 1; | |
95 | if (ioctl(ffd, XFS_IOC_FREEZE, &level) < 0) { | |
96 | fprintf(stderr, "%s: cannot freeze filesystem" | |
97 | " mounted at %s: %s\n", | |
98 | progname, argv[optind], strerror(errno)); | |
99 | exit(1); | |
100 | } | |
101 | } | |
102 | ||
103 | if (uflag) { | |
104 | if (ioctl(ffd, XFS_IOC_THAW, &level) < 0) { | |
105 | fprintf(stderr, "%s: cannot unfreeze filesystem" | |
106 | " mounted at %s: %s\n", | |
107 | progname, argv[optind], strerror(errno)); | |
108 | exit(1); | |
109 | } | |
110 | } | |
111 | ||
112 | close(ffd); | |
113 | } |