]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/fsgeom.h
libfrog: fix bitmap error communication problems
[thirdparty/xfsprogs-dev.git] / libfrog / fsgeom.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4 */
5 #ifndef __LIBFROG_FSGEOM_H__
6 #define __LIBFROG_FSGEOM_H__
7
8 void xfs_report_geom(struct xfs_fsop_geom *geo, const char *mntpoint,
9 const char *logname, const char *rtname);
10 int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo);
11 int xfrog_ag_geometry(int fd, unsigned int agno, struct xfs_ag_geometry *ageo);
12
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 */
18 struct xfs_fd {
19 /* ioctl file descriptor */
20 int fd;
21
22 /* filesystem geometry */
23 struct xfs_fsop_geom fsgeom;
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;
36
37 /* bits for agino in inum */
38 unsigned int aginolog;
39
40 /* log2 of sb_blocksize / sb_sectsize */
41 unsigned int blkbb_log;
42
43 /* XFROG_FLAG_* state flags */
44 unsigned int flags;
45 };
46
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
53 /* Static initializers */
54 #define XFS_FD_INIT(_fd) { .fd = (_fd), }
55 #define XFS_FD_INIT_EMPTY XFS_FD_INIT(-1)
56
57 int xfd_prepare_geometry(struct xfs_fd *xfd);
58 int xfd_open(struct xfs_fd *xfd, const char *pathname, int flags);
59 int xfd_close(struct xfs_fd *xfd);
60
61 /* Convert AG number and AG inode number into fs inode number. */
62 static inline uint64_t
63 cvt_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. */
72 static inline uint32_t
73 cvt_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. */
81 static inline uint32_t
82 cvt_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 */
94 static inline uint64_t
95 cvt_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 */
107 static inline uint64_t
108 cvt_b_to_off_fsbt(
109 const struct xfs_fd *xfd,
110 uint64_t bytes)
111 {
112 return bytes >> xfd->blocklog;
113 }
114
115 /* Convert sector number to bytes. */
116 static inline uint64_t
117 cvt_bbtob(
118 uint64_t daddr)
119 {
120 return daddr << BBSHIFT;
121 }
122
123 /* Convert bytes to sector number, rounding down. */
124 static inline uint64_t
125 cvt_btobbt(
126 uint64_t bytes)
127 {
128 return bytes >> BBSHIFT;
129 }
130
131 /* Convert fs block number to sector number. */
132 static inline uint64_t
133 cvt_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. */
141 static inline uint64_t
142 cvt_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 */
150 static inline uint64_t
151 cvt_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. */
161 static inline uint32_t
162 cvt_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. */
170 static inline uint32_t
171 cvt_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. */
179 static inline uint64_t
180 cvt_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. */
189 static inline xfs_agblock_t
190 cvt_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
197 #endif /* __LIBFROG_FSGEOM_H__ */