]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/fsgeom.c
xfs_info: Report NREXT64 feature status
[thirdparty/xfsprogs-dev.git] / libfrog / fsgeom.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4 */
5 #include "platform_defs.h"
6 #include "xfs.h"
7 #include "bitops.h"
8 #include "fsgeom.h"
9 #include "util.h"
10
11 void
12 xfs_report_geom(
13 struct xfs_fsop_geom *geo,
14 const char *mntpoint,
15 const char *logname,
16 const char *rtname)
17 {
18 int isint;
19 int lazycount;
20 int dirversion;
21 int logversion;
22 int attrversion;
23 int projid32bit;
24 int crcs_enabled;
25 int cimode;
26 int ftype_enabled;
27 int finobt_enabled;
28 int spinodes;
29 int rmapbt_enabled;
30 int reflink_enabled;
31 int bigtime_enabled;
32 int inobtcount;
33 int nrext64;
34
35 isint = geo->logstart > 0;
36 lazycount = geo->flags & XFS_FSOP_GEOM_FLAGS_LAZYSB ? 1 : 0;
37 dirversion = geo->flags & XFS_FSOP_GEOM_FLAGS_DIRV2 ? 2 : 1;
38 logversion = geo->flags & XFS_FSOP_GEOM_FLAGS_LOGV2 ? 2 : 1;
39 attrversion = geo->flags & XFS_FSOP_GEOM_FLAGS_ATTR2 ? 2 : \
40 (geo->flags & XFS_FSOP_GEOM_FLAGS_ATTR ? 1 : 0);
41 cimode = geo->flags & XFS_FSOP_GEOM_FLAGS_DIRV2CI ? 1 : 0;
42 projid32bit = geo->flags & XFS_FSOP_GEOM_FLAGS_PROJID32 ? 1 : 0;
43 crcs_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_V5SB ? 1 : 0;
44 ftype_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_FTYPE ? 1 : 0;
45 finobt_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_FINOBT ? 1 : 0;
46 spinodes = geo->flags & XFS_FSOP_GEOM_FLAGS_SPINODES ? 1 : 0;
47 rmapbt_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_RMAPBT ? 1 : 0;
48 reflink_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_REFLINK ? 1 : 0;
49 bigtime_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_BIGTIME ? 1 : 0;
50 inobtcount = geo->flags & XFS_FSOP_GEOM_FLAGS_INOBTCNT ? 1 : 0;
51 nrext64 = geo->flags & XFS_FSOP_GEOM_FLAGS_NREXT64 ? 1 : 0;
52
53 printf(_(
54 "meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n"
55 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
56 " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n"
57 " =%-22s reflink=%-4u bigtime=%u inobtcount=%u nrext64=%u\n"
58 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
59 " =%-22s sunit=%-6u swidth=%u blks\n"
60 "naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n"
61 "log =%-22s bsize=%-6d blocks=%u, version=%d\n"
62 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
63 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
64 mntpoint, geo->inodesize, geo->agcount, geo->agblocks,
65 "", geo->sectsize, attrversion, projid32bit,
66 "", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
67 "", reflink_enabled, bigtime_enabled, inobtcount, nrext64,
68 "", geo->blocksize, (unsigned long long)geo->datablocks,
69 geo->imaxpct,
70 "", geo->sunit, geo->swidth,
71 dirversion, geo->dirblocksize, cimode, ftype_enabled,
72 isint ? _("internal log") : logname ? logname : _("external"),
73 geo->blocksize, geo->logblocks, logversion,
74 "", geo->logsectsize, geo->logsunit / geo->blocksize, lazycount,
75 !geo->rtblocks ? _("none") : rtname ? rtname : _("external"),
76 geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
77 (unsigned long long)geo->rtextents);
78 }
79
80 /* Try to obtain the xfs geometry. On error returns a negative error code. */
81 int
82 xfrog_geometry(
83 int fd,
84 struct xfs_fsop_geom *fsgeo)
85 {
86 int ret;
87
88 memset(fsgeo, 0, sizeof(*fsgeo));
89
90 ret = ioctl(fd, XFS_IOC_FSGEOMETRY, fsgeo);
91 if (!ret)
92 return 0;
93
94 ret = ioctl(fd, XFS_IOC_FSGEOMETRY_V4, fsgeo);
95 if (!ret)
96 return 0;
97
98 ret = ioctl(fd, XFS_IOC_FSGEOMETRY_V1, fsgeo);
99 if (!ret)
100 return 0;
101
102 return -errno;
103 }
104
105 /*
106 * Prepare xfs_fd structure for future ioctl operations by computing the xfs
107 * geometry for @xfd->fd. Returns zero or a negative error code.
108 */
109 int
110 xfd_prepare_geometry(
111 struct xfs_fd *xfd)
112 {
113 int ret;
114
115 ret = xfrog_geometry(xfd->fd, &xfd->fsgeom);
116 if (ret)
117 return ret;
118
119 xfd->agblklog = log2_roundup(xfd->fsgeom.agblocks);
120 xfd->blocklog = highbit32(xfd->fsgeom.blocksize);
121 xfd->inodelog = highbit32(xfd->fsgeom.inodesize);
122 xfd->inopblog = xfd->blocklog - xfd->inodelog;
123 xfd->aginolog = xfd->agblklog + xfd->inopblog;
124 xfd->blkbb_log = xfd->blocklog - BBSHIFT;
125 return 0;
126 }
127
128 /* Open a file on an XFS filesystem. Returns zero or a negative error code. */
129 int
130 xfd_open(
131 struct xfs_fd *xfd,
132 const char *pathname,
133 int flags)
134 {
135 int ret;
136
137 xfd->fd = open(pathname, flags);
138 if (xfd->fd < 0)
139 return -errno;
140
141 ret = xfd_prepare_geometry(xfd);
142 if (ret) {
143 xfd_close(xfd);
144 return ret;
145 }
146
147 return 0;
148 }
149
150 /*
151 * Release any resources associated with this xfs_fd structure. Returns zero
152 * or a negative error code.
153 */
154 int
155 xfd_close(
156 struct xfs_fd *xfd)
157 {
158 int ret = 0;
159
160 if (xfd->fd < 0)
161 return 0;
162
163 ret = close(xfd->fd);
164 xfd->fd = -1;
165 if (ret < 0)
166 return -errno;
167
168 return 0;
169 }
170
171 /* Try to obtain an AG's geometry. Returns zero or a negative error code. */
172 int
173 xfrog_ag_geometry(
174 int fd,
175 unsigned int agno,
176 struct xfs_ag_geometry *ageo)
177 {
178 int ret;
179
180 ageo->ag_number = agno;
181 ret = ioctl(fd, XFS_IOC_AG_GEOMETRY, ageo);
182 if (ret)
183 return -errno;
184 return 0;
185 }