]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - spaceman/info.c
libfrog: refactor online geometry queries
[thirdparty/xfsprogs-dev.git] / spaceman / info.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0+
6719d622
DW
2/*
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
6719d622 4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
6719d622
DW
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
13static void
14info_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
26static int
27info_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 */
9612817d 40 error = xfrog_geometry(file->fd, &geo);
6719d622 41 if (error) {
9612817d
DW
42 fprintf(stderr,
43 _("%s: cannot determine geometry of filesystem mounted at %s: %s\n"),
44 progname, file->name, strerror(error));
45 exitcode = 1;
46 return 0;
6719d622
DW
47 }
48
49 xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
50 file->fs_path.fs_rt);
51 return 0;
52}
53
54static const struct cmdinfo info_cmd = {
55 .name = "info",
56 .altname = "i",
57 .cfunc = info_f,
58 .argmin = 0,
59 .argmax = 0,
60 .canpush = 0,
61 .args = NULL,
62 .flags = CMD_FLAG_ONESHOT,
63 .oneline = N_("pretty-print superblock geometry info"),
64 .help = info_help,
65};
66
67void
68info_init(void)
69{
70 add_command(&info_cmd);
71}