]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/fsgeom.h
libfrog: move workqueue.h to libfrog/
[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
12 /*
13 * Structure for recording whatever observations we want about the level of
14 * xfs runtime support for this fd. Right now we only store the fd and fs
15 * geometry.
16 */
17 struct xfs_fd {
18 /* ioctl file descriptor */
19 int fd;
20
21 /* filesystem geometry */
22 struct xfs_fsop_geom fsgeom;
23
24 /* log2 of sb_agblocks (rounded up) */
25 unsigned int agblklog;
26
27 /* log2 of sb_blocksize */
28 unsigned int blocklog;
29
30 /* log2 of sb_inodesize */
31 unsigned int inodelog;
32
33 /* log2 of sb_inopblock */
34 unsigned int inopblog;
35
36 /* bits for agino in inum */
37 unsigned int aginolog;
38 };
39
40 /* Static initializers */
41 #define XFS_FD_INIT(_fd) { .fd = (_fd), }
42 #define XFS_FD_INIT_EMPTY XFS_FD_INIT(-1)
43
44 int xfd_prepare_geometry(struct xfs_fd *xfd);
45 int xfd_open(struct xfs_fd *xfd, const char *pathname, int flags);
46 int xfd_close(struct xfs_fd *xfd);
47
48 /* Convert AG number and AG inode number into fs inode number. */
49 static inline uint64_t
50 cvt_agino_to_ino(
51 const struct xfs_fd *xfd,
52 uint32_t agno,
53 uint32_t agino)
54 {
55 return ((uint64_t)agno << xfd->aginolog) + agino;
56 }
57
58 /* Convert fs inode number into AG number. */
59 static inline uint32_t
60 cvt_ino_to_agno(
61 const struct xfs_fd *xfd,
62 uint64_t ino)
63 {
64 return ino >> xfd->aginolog;
65 }
66
67 /* Convert fs inode number into AG inode number. */
68 static inline uint32_t
69 cvt_ino_to_agino(
70 const struct xfs_fd *xfd,
71 uint64_t ino)
72 {
73 return ino & ((1ULL << xfd->aginolog) - 1);
74 }
75
76 /*
77 * Convert a linear fs block offset number into bytes. This is the runtime
78 * equivalent of XFS_FSB_TO_B, which means that it is /not/ for segmented fsbno
79 * format (= agno | agbno) that we use internally for the data device.
80 */
81 static inline uint64_t
82 cvt_off_fsb_to_b(
83 const struct xfs_fd *xfd,
84 uint64_t fsb)
85 {
86 return fsb << xfd->blocklog;
87 }
88
89 /*
90 * Convert bytes into a (rounded down) linear fs block offset number. This is
91 * the runtime equivalent of XFS_B_TO_FSBT. It does not produce segmented
92 * fsbno numbers (= agno | agbno).
93 */
94 static inline uint64_t
95 cvt_b_to_off_fsbt(
96 const struct xfs_fd *xfd,
97 uint64_t bytes)
98 {
99 return bytes >> xfd->blocklog;
100 }
101
102 #endif /* __LIBFROG_FSGEOM_H__ */