-
Notifications
You must be signed in to change notification settings - Fork 71
/
godown.c
112 lines (93 loc) · 2.04 KB
/
godown.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2004 Silicon Graphics, Inc.
* All Rights Reserved.
*/
#include <syslog.h>
#include "global.h"
static char *xprogname;
static void
usage(void)
{
fprintf(stderr, "usage: %s [-f] [-v] mnt-dir\n", xprogname);
}
int
main(int argc, char *argv[])
{
int c;
int flag;
int flushlog_opt = 0;
int verbose_opt = 0;
struct stat st;
char *mnt_dir;
int fd;
xprogname = argv[0];
while ((c = getopt(argc, argv, "fv")) != -1) {
switch (c) {
case 'f':
flushlog_opt = 1;
break;
case 'v':
verbose_opt = 1;
break;
case '?':
usage();
return 1;
}
}
/* process required cmd argument */
if (optind == argc-1) {
mnt_dir = argv[optind];
}
else {
usage();
return 1;
}
if ((stat(mnt_dir, &st)) == -1) {
fprintf(stderr, "%s: error on stat \"%s\": %s\n",
xprogname, mnt_dir, strerror(errno));
return 1;
}
if (!S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s: argument \"%s\" is not a directory\n",
xprogname, mnt_dir);
return 1;
}
#if 0
{
struct statvfs stvfs;
if ((statvfs(mnt_dir, &stvfs)) == -1) {
fprintf(stderr, "%s: error on statfs \"%s\": %s\n",
xprogname, mnt_dir, strerror(errno));
return 1;
}
if (strcmp(stvfs.f_basetype, "xfs") != 0) {
fprintf(stderr, "%s: filesys for \"%s\" is not XFS:\"%s\"\n",
xprogname, mnt_dir, stvfs.f_basetype);
return 1;
}
}
#endif
flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH
: XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
if (verbose_opt) {
printf("Opening \"%s\"\n", mnt_dir);
}
if ((fd = open(mnt_dir, O_RDONLY)) == -1) {
fprintf(stderr, "%s: error on open of \"%s\": %s\n",
xprogname, mnt_dir, strerror(errno));
return 1;
}
if (verbose_opt) {
printf("Calling XFS_IOC_GOINGDOWN\n");
}
syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
mnt_dir);
if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
xprogname, mnt_dir, strerror(errno));
return 1;
}
close(fd);
return 0;
}