]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/shutdown.c
3c29ea790643f885bc8c4130a40d7c4d601a5ed1
[thirdparty/xfsprogs-dev.git] / io / shutdown.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "command.h"
8 #include "input.h"
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 exitcode = 1;
28 return command_usage(&shutdown_cmd);
29 }
30 }
31
32 if ((xfsctl(file->name, file->fd, XFS_IOC_GOINGDOWN, &flag)) < 0) {
33 perror("XFS_IOC_GOINGDOWN");
34 exitcode = 1;
35 return 0;
36 }
37 return 0;
38 }
39
40 static void
41 shutdown_help(void)
42 {
43 printf(_(
44 "\n"
45 " Shuts down the filesystem and prevents any further IO from occurring.\n"
46 "\n"
47 " By default, shutdown will not flush completed transactions to disk\n"
48 " before shutting the filesystem down, simulating a disk failure or crash.\n"
49 " With -f, the log will be flushed to disk, matching XFS behavior when\n"
50 " metadata corruption is encountered.\n"
51 "\n"
52 " -f -- Flush completed transactions to disk before shut down.\n"
53 "\n"));
54 }
55
56 void
57 shutdown_init(void)
58 {
59 shutdown_cmd.name = "shutdown";
60 shutdown_cmd.cfunc = shutdown_f;
61 shutdown_cmd.argmin = 0;
62 shutdown_cmd.argmax = 1;
63 shutdown_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK;
64 shutdown_cmd.args = _("[-f]");
65 shutdown_cmd.help = shutdown_help;
66 shutdown_cmd.oneline =
67 _("shuts down the filesystem where the current file resides");
68
69 if (expert)
70 add_command(&shutdown_cmd);
71 }