]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libfrog/fsgeom.h
libfrog: fix bitmap error communication problems
[thirdparty/xfsprogs-dev.git] / libfrog / fsgeom.h
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
96aaf9bc 2/*
959ef981 3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
96aaf9bc 4 */
fee68490
DW
5#ifndef __LIBFROG_FSGEOM_H__
6#define __LIBFROG_FSGEOM_H__
96aaf9bc
DW
7
8void xfs_report_geom(struct xfs_fsop_geom *geo, const char *mntpoint,
9 const char *logname, const char *rtname);
9612817d 10int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo);
bb85ae74 11int xfrog_ag_geometry(int fd, unsigned int agno, struct xfs_ag_geometry *ageo);
96aaf9bc 12
3f9efb2e
DW
13/*
14 * Structure for recording whatever observations we want about the level of
15 * xfs runtime support for this fd. Right now we only store the fd and fs
16 * geometry.
17 */
18struct xfs_fd {
19 /* ioctl file descriptor */
20 int fd;
21
22 /* filesystem geometry */
23 struct xfs_fsop_geom fsgeom;
5b5c7336
DW
24
25 /* log2 of sb_agblocks (rounded up) */
26 unsigned int agblklog;
27
28 /* log2 of sb_blocksize */
29 unsigned int blocklog;
30
31 /* log2 of sb_inodesize */
32 unsigned int inodelog;
33
34 /* log2 of sb_inopblock */
35 unsigned int inopblog;
a749451c
DW
36
37 /* bits for agino in inum */
38 unsigned int aginolog;
b3803ff1
DW
39
40 /* log2 of sb_blocksize / sb_sectsize */
41 unsigned int blkbb_log;
4cca629d
DW
42
43 /* XFROG_FLAG_* state flags */
44 unsigned int flags;
3f9efb2e
DW
45};
46
4cca629d
DW
47/* Only use v1 bulkstat/inumbers ioctls. */
48#define XFROG_FLAG_BULKSTAT_FORCE_V1 (1 << 0)
49
50/* Only use v5 bulkstat/inumbers ioctls. */
51#define XFROG_FLAG_BULKSTAT_FORCE_V5 (1 << 1)
52
3f9efb2e
DW
53/* Static initializers */
54#define XFS_FD_INIT(_fd) { .fd = (_fd), }
55#define XFS_FD_INIT_EMPTY XFS_FD_INIT(-1)
56
57int xfd_prepare_geometry(struct xfs_fd *xfd);
248af7cb 58int xfd_open(struct xfs_fd *xfd, const char *pathname, int flags);
3f9efb2e
DW
59int xfd_close(struct xfs_fd *xfd);
60
a749451c
DW
61/* Convert AG number and AG inode number into fs inode number. */
62static inline uint64_t
63cvt_agino_to_ino(
64 const struct xfs_fd *xfd,
65 uint32_t agno,
66 uint32_t agino)
67{
68 return ((uint64_t)agno << xfd->aginolog) + agino;
69}
70
71/* Convert fs inode number into AG number. */
72static inline uint32_t
73cvt_ino_to_agno(
74 const struct xfs_fd *xfd,
75 uint64_t ino)
76{
77 return ino >> xfd->aginolog;
78}
79
80/* Convert fs inode number into AG inode number. */
81static inline uint32_t
82cvt_ino_to_agino(
83 const struct xfs_fd *xfd,
84 uint64_t ino)
85{
86 return ino & ((1ULL << xfd->aginolog) - 1);
87}
88
89/*
90 * Convert a linear fs block offset number into bytes. This is the runtime
91 * equivalent of XFS_FSB_TO_B, which means that it is /not/ for segmented fsbno
92 * format (= agno | agbno) that we use internally for the data device.
93 */
94static inline uint64_t
95cvt_off_fsb_to_b(
96 const struct xfs_fd *xfd,
97 uint64_t fsb)
98{
99 return fsb << xfd->blocklog;
100}
101
102/*
103 * Convert bytes into a (rounded down) linear fs block offset number. This is
104 * the runtime equivalent of XFS_B_TO_FSBT. It does not produce segmented
105 * fsbno numbers (= agno | agbno).
106 */
107static inline uint64_t
108cvt_b_to_off_fsbt(
109 const struct xfs_fd *xfd,
110 uint64_t bytes)
111{
112 return bytes >> xfd->blocklog;
113}
114
b3803ff1
DW
115/* Convert sector number to bytes. */
116static inline uint64_t
117cvt_bbtob(
118 uint64_t daddr)
119{
120 return daddr << BBSHIFT;
121}
122
123/* Convert bytes to sector number, rounding down. */
124static inline uint64_t
125cvt_btobbt(
126 uint64_t bytes)
127{
128 return bytes >> BBSHIFT;
129}
130
131/* Convert fs block number to sector number. */
132static inline uint64_t
133cvt_off_fsb_to_bb(
134 struct xfs_fd *xfd,
135 uint64_t fsbno)
136{
137 return fsbno << xfd->blkbb_log;
138}
139
140/* Convert sector number to fs block number, rounded down. */
141static inline uint64_t
142cvt_bb_to_off_fsbt(
143 struct xfs_fd *xfd,
144 uint64_t daddr)
145{
146 return daddr >> xfd->blkbb_log;
147}
148
149/* Convert AG number and AG block to fs block number */
150static inline uint64_t
151cvt_agb_to_daddr(
152 struct xfs_fd *xfd,
153 uint32_t agno,
154 uint32_t agbno)
155{
156 return cvt_off_fsb_to_bb(xfd,
157 (uint64_t)agno * xfd->fsgeom.agblocks + agbno);
158}
159
160/* Convert sector number to AG number. */
161static inline uint32_t
162cvt_daddr_to_agno(
163 struct xfs_fd *xfd,
164 uint64_t daddr)
165{
166 return cvt_bb_to_off_fsbt(xfd, daddr) / xfd->fsgeom.agblocks;
167}
168
169/* Convert sector number to AG block number. */
170static inline uint32_t
171cvt_daddr_to_agbno(
172 struct xfs_fd *xfd,
173 uint64_t daddr)
174{
175 return cvt_bb_to_off_fsbt(xfd, daddr) % xfd->fsgeom.agblocks;
176}
177
178/* Convert AG number and AG block to a byte location on disk. */
179static inline uint64_t
180cvt_agbno_to_b(
181 struct xfs_fd *xfd,
182 xfs_agnumber_t agno,
183 xfs_agblock_t agbno)
184{
185 return cvt_bbtob(cvt_agb_to_daddr(xfd, agno, agbno));
186}
187
188/* Convert byte location on disk to AG block. */
189static inline xfs_agblock_t
190cvt_b_to_agbno(
191 struct xfs_fd *xfd,
192 uint64_t byteno)
193{
194 return cvt_daddr_to_agbno(xfd, cvt_btobbt(byteno));
195}
196
fee68490 197#endif /* __LIBFROG_FSGEOM_H__ */