]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - spaceman/info.c
xfs: get rid of the log item descriptor
[thirdparty/xfsprogs-dev.git] / spaceman / info.c
1 /*
2 * Copyright (C) 2018 Oracle. All Rights Reserved.
3 *
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 #include "libxfs.h"
21 #include "command.h"
22 #include "init.h"
23 #include "path.h"
24 #include "space.h"
25 #include "fsgeom.h"
26
27 static void
28 info_help(void)
29 {
30 printf(_(
31 "\n"
32 " Pretty-prints the filesystem geometry as derived from the superblock.\n"
33 " The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
34 " The opened file must be an XFS mount point.\n"
35 "\n"
36 ));
37
38 }
39
40 static int
41 info_f(
42 int argc,
43 char **argv)
44 {
45 struct xfs_fsop_geom geo;
46 int error;
47
48 if (fs_table_lookup_mount(file->name) == NULL) {
49 fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
50 return 1;
51 }
52
53 /* get the current filesystem size & geometry */
54 error = ioctl(file->fd, XFS_IOC_FSGEOMETRY, &geo);
55 if (error) {
56 /*
57 * OK, new xfsctl barfed - back off and try earlier version
58 * as we're probably running an older kernel version.
59 * Only field added in the v2 geometry xfsctl is "logsunit"
60 * so we'll zero that out for later display (as zero).
61 */
62 geo.logsunit = 0;
63 error = ioctl(file->fd, XFS_IOC_FSGEOMETRY_V1, &geo);
64 if (error) {
65 fprintf(stderr, _(
66 "%s: cannot determine geometry of filesystem"
67 " mounted at %s: %s\n"),
68 progname, file->name, strerror(errno));
69 exitcode = 1;
70 return 0;
71 }
72 }
73
74 xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
75 file->fs_path.fs_rt);
76 return 0;
77 }
78
79 static const struct cmdinfo info_cmd = {
80 .name = "info",
81 .altname = "i",
82 .cfunc = info_f,
83 .argmin = 0,
84 .argmax = 0,
85 .canpush = 0,
86 .args = NULL,
87 .flags = CMD_FLAG_ONESHOT,
88 .oneline = N_("pretty-print superblock geometry info"),
89 .help = info_help,
90 };
91
92 void
93 info_init(void)
94 {
95 add_command(&info_cmd);
96 }