]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libfrog/fsgeom.h
libfrog: move workqueue.h to libfrog/
[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);
96aaf9bc 11
3f9efb2e
DW
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 */
17struct xfs_fd {
18 /* ioctl file descriptor */
19 int fd;
20
21 /* filesystem geometry */
22 struct xfs_fsop_geom fsgeom;
5b5c7336
DW
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;
a749451c
DW
35
36 /* bits for agino in inum */
37 unsigned int aginolog;
3f9efb2e
DW
38};
39
40/* Static initializers */
41#define XFS_FD_INIT(_fd) { .fd = (_fd), }
42#define XFS_FD_INIT_EMPTY XFS_FD_INIT(-1)
43
44int xfd_prepare_geometry(struct xfs_fd *xfd);
248af7cb 45int xfd_open(struct xfs_fd *xfd, const char *pathname, int flags);
3f9efb2e
DW
46int xfd_close(struct xfs_fd *xfd);
47
a749451c
DW
48/* Convert AG number and AG inode number into fs inode number. */
49static inline uint64_t
50cvt_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. */
59static inline uint32_t
60cvt_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. */
68static inline uint32_t
69cvt_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 */
81static inline uint64_t
82cvt_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 */
94static inline uint64_t
95cvt_b_to_off_fsbt(
96 const struct xfs_fd *xfd,
97 uint64_t bytes)
98{
99 return bytes >> xfd->blocklog;
100}
101
fee68490 102#endif /* __LIBFROG_FSGEOM_H__ */