]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/fsgeom.h
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
5 #ifndef __LIBFROG_FSGEOM_H__
6 #define __LIBFROG_FSGEOM_H__
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
);
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
19 /* ioctl file descriptor */
22 /* filesystem geometry */
23 struct xfs_fsop_geom fsgeom
;
25 /* log2 of sb_agblocks (rounded up) */
26 unsigned int agblklog
;
28 /* log2 of sb_blocksize */
29 unsigned int blocklog
;
31 /* log2 of sb_inodesize */
32 unsigned int inodelog
;
34 /* log2 of sb_inopblock */
35 unsigned int inopblog
;
37 /* bits for agino in inum */
38 unsigned int aginolog
;
40 /* log2 of sb_blocksize / sb_sectsize */
41 unsigned int blkbb_log
;
43 /* XFROG_FLAG_* state flags */
47 /* Only use v1 bulkstat/inumbers ioctls. */
48 #define XFROG_FLAG_BULKSTAT_FORCE_V1 (1 << 0)
50 /* Only use v5 bulkstat/inumbers ioctls. */
51 #define XFROG_FLAG_BULKSTAT_FORCE_V5 (1 << 1)
53 /* Static initializers */
54 #define XFS_FD_INIT(_fd) { .fd = (_fd), }
55 #define XFS_FD_INIT_EMPTY XFS_FD_INIT(-1)
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
);
61 /* Convert AG number and AG inode number into fs inode number. */
62 static inline uint64_t
64 const struct xfs_fd
*xfd
,
68 return ((uint64_t)agno
<< xfd
->aginolog
) + agino
;
71 /* Convert fs inode number into AG number. */
72 static inline uint32_t
74 const struct xfs_fd
*xfd
,
77 return ino
>> xfd
->aginolog
;
80 /* Convert fs inode number into AG inode number. */
81 static inline uint32_t
83 const struct xfs_fd
*xfd
,
86 return ino
& ((1ULL << xfd
->aginolog
) - 1);
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.
94 static inline uint64_t
96 const struct xfs_fd
*xfd
,
99 return fsb
<< xfd
->blocklog
;
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).
107 static inline uint64_t
109 const struct xfs_fd
*xfd
,
112 return bytes
>> xfd
->blocklog
;
115 /* Convert sector number to bytes. */
116 static inline uint64_t
120 return daddr
<< BBSHIFT
;
123 /* Convert bytes to sector number, rounding down. */
124 static inline uint64_t
128 return bytes
>> BBSHIFT
;
131 /* Convert fs block number to sector number. */
132 static inline uint64_t
137 return fsbno
<< xfd
->blkbb_log
;
140 /* Convert sector number to fs block number, rounded down. */
141 static inline uint64_t
146 return daddr
>> xfd
->blkbb_log
;
149 /* Convert AG number and AG block to fs block number */
150 static inline uint64_t
156 return cvt_off_fsb_to_bb(xfd
,
157 (uint64_t)agno
* xfd
->fsgeom
.agblocks
+ agbno
);
160 /* Convert sector number to AG number. */
161 static inline uint32_t
166 return cvt_bb_to_off_fsbt(xfd
, daddr
) / xfd
->fsgeom
.agblocks
;
169 /* Convert sector number to AG block number. */
170 static inline uint32_t
175 return cvt_bb_to_off_fsbt(xfd
, daddr
) % xfd
->fsgeom
.agblocks
;
178 /* Convert AG number and AG block to a byte location on disk. */
179 static inline uint64_t
185 return cvt_bbtob(cvt_agb_to_daddr(xfd
, agno
, agbno
));
188 /* Convert byte location on disk to AG block. */
189 static inline xfs_agblock_t
194 return cvt_daddr_to_agbno(xfd
, cvt_btobbt(byteno
));
197 #endif /* __LIBFROG_FSGEOM_H__ */