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