]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
48c46ee3 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
48c46ee3 NS |
5 | */ |
6 | ||
6b803e5a CH |
7 | #include "command.h" |
8 | #include "input.h" | |
48c46ee3 NS |
9 | #include "init.h" |
10 | #include "io.h" | |
11 | ||
12 | static cmdinfo_t shutdown_cmd; | |
13 | ||
14 | static int | |
15 | shutdown_f( | |
16 | int argc, | |
17 | char **argv) | |
18 | { | |
19 | int c, flag = XFS_FSOP_GOING_FLAGS_NOLOGFLUSH; | |
20 | ||
21 | while ((c = getopt(argc, argv, "fv")) != -1) { | |
22 | switch (c) { | |
23 | case 'f': | |
24 | flag = XFS_FSOP_GOING_FLAGS_LOGFLUSH; | |
25 | break; | |
26 | default: | |
27 | return command_usage(&shutdown_cmd); | |
28 | } | |
29 | } | |
30 | ||
31 | if ((xfsctl(file->name, file->fd, XFS_IOC_GOINGDOWN, &flag)) < 0) { | |
32 | perror("XFS_IOC_GOINGDOWN"); | |
33 | return 0; | |
34 | } | |
35 | return 0; | |
36 | } | |
37 | ||
0d88afd6 CM |
38 | static void |
39 | shutdown_help(void) | |
40 | { | |
41 | printf(_( | |
42 | "\n" | |
43 | " Shuts down the filesystem and prevents any further IO from occurring.\n" | |
44 | "\n" | |
45 | " By default, shutdown will not flush completed transactions to disk\n" | |
46 | " before shutting the filesystem down, simulating a disk failure or crash.\n" | |
47 | " With -f, the log will be flushed to disk, matching XFS behavior when\n" | |
48 | " metadata corruption is encountered.\n" | |
49 | "\n" | |
50 | " -f -- Flush completed transactions to disk before shut down.\n" | |
51 | "\n")); | |
52 | } | |
53 | ||
48c46ee3 NS |
54 | void |
55 | shutdown_init(void) | |
56 | { | |
ad765595 | 57 | shutdown_cmd.name = "shutdown"; |
48c46ee3 NS |
58 | shutdown_cmd.cfunc = shutdown_f; |
59 | shutdown_cmd.argmin = 0; | |
60 | shutdown_cmd.argmax = 1; | |
75dc6781 | 61 | shutdown_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK; |
48c46ee3 | 62 | shutdown_cmd.args = _("[-f]"); |
0d88afd6 | 63 | shutdown_cmd.help = shutdown_help; |
48c46ee3 NS |
64 | shutdown_cmd.oneline = |
65 | _("shuts down the filesystem where the current file resides"); | |
66 | ||
67 | if (expert) | |
68 | add_command(&shutdown_cmd); | |
69 | } |