]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - spaceman/info.c
xfsprogs: Release v6.7.0
[thirdparty/xfsprogs-dev.git] / spaceman / info.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6 #include "libxfs.h"
7 #include "command.h"
8 #include "init.h"
9 #include "path.h"
10 #include "space.h"
11 #include "fsgeom.h"
12
13 static void
14 info_help(void)
15 {
16 printf(_(
17 "\n"
18 " Pretty-prints the filesystem geometry as derived from the superblock.\n"
19 " The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
20 " The opened file must be an XFS mount point.\n"
21 "\n"
22 ));
23
24 }
25
26 static int
27 info_f(
28 int argc,
29 char **argv)
30 {
31 struct xfs_fsop_geom geo;
32 int error;
33
34 if (fs_table_lookup_mount(file->name) == NULL) {
35 fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
36 return 1;
37 }
38
39 /* get the current filesystem size & geometry */
40 error = ioctl(file->fd, XFS_IOC_FSGEOMETRY, &geo);
41 if (error) {
42 /*
43 * OK, new xfsctl barfed - back off and try earlier version
44 * as we're probably running an older kernel version.
45 * Only field added in the v2 geometry xfsctl is "logsunit"
46 * so we'll zero that out for later display (as zero).
47 */
48 geo.logsunit = 0;
49 error = ioctl(file->fd, XFS_IOC_FSGEOMETRY_V1, &geo);
50 if (error) {
51 fprintf(stderr, _(
52 "%s: cannot determine geometry of filesystem"
53 " mounted at %s: %s\n"),
54 progname, file->name, strerror(errno));
55 exitcode = 1;
56 return 0;
57 }
58 }
59
60 xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
61 file->fs_path.fs_rt);
62 return 0;
63 }
64
65 static const struct cmdinfo info_cmd = {
66 .name = "info",
67 .altname = "i",
68 .cfunc = info_f,
69 .argmin = 0,
70 .argmax = 0,
71 .canpush = 0,
72 .args = NULL,
73 .flags = CMD_FLAG_ONESHOT,
74 .oneline = N_("pretty-print superblock geometry info"),
75 .help = info_help,
76 };
77
78 void
79 info_init(void)
80 {
81 add_command(&info_cmd);
82 }