]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/libxfs.h
libfrog: move 64-bit division wrappers to libfrog
[thirdparty/xfsprogs-dev.git] / include / libxfs.h
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
f302e9e4
NS
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18 5 */
5e656dbb 6
2bd0ea18
NS
7#ifndef __LIBXFS_H__
8#define __LIBXFS_H__
9
6b803e5a
CH
10#include "libxfs_api_defs.h"
11#include "platform_defs.h"
dcabd4e7 12#include "xfs.h"
2bd0ea18 13
6b803e5a
CH
14#include "list.h"
15#include "hlist.h"
16#include "cache.h"
17#include "bitops.h"
18#include "kmem.h"
8bf7924e 19#include "libfrog/radix-tree.h"
03dc2ef2 20#include "libfrog/bitmask.h"
af71e8c1 21#include "libfrog/div64.h"
6b803e5a 22#include "atomic.h"
686bddf9 23#include "spinlock.h"
f1b058f9 24
6b803e5a
CH
25#include "xfs_types.h"
26#include "xfs_fs.h"
27#include "xfs_arch.h"
2d4bfb91 28
6b803e5a
CH
29#include "xfs_shared.h"
30#include "xfs_format.h"
31#include "xfs_log_format.h"
32#include "xfs_quota_defs.h"
33#include "xfs_trans_resv.h"
2d4bfb91 34
b626fb59
DC
35
36/* CRC stuff, buffer API dependent on it */
b626fb59 37extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
b626fb59
DC
38#define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
39
75f533e6
CH
40/* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */
41struct iomap;
6b803e5a 42#include "xfs_cksum.h"
b626fb59 43
e778c95d
CH
44#define __round_mask(x, y) ((__typeof__(x))((y)-1))
45#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
e169cc9b 46#define unlikely(x) (x)
e778c95d 47
b626fb59
DC
48/*
49 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
50 * every files via a similar include in the kernel xfs_linux.h.
51 */
6b803e5a
CH
52#include "libxfs_io.h"
53
54#include "xfs_bit.h"
55#include "xfs_sb.h"
56#include "xfs_mount.h"
f944d3d0 57#include "xfs_defer.h"
904d9719 58#include "xfs_errortag.h"
6b803e5a
CH
59#include "xfs_da_format.h"
60#include "xfs_da_btree.h"
e169cc9b 61#include "xfs_inode.h"
6b803e5a 62#include "xfs_dir2.h"
bd045c51 63#include "xfs_dir2_priv.h"
6b803e5a
CH
64#include "xfs_bmap_btree.h"
65#include "xfs_alloc_btree.h"
66#include "xfs_ialloc_btree.h"
c749b4e1 67#include "xfs_attr.h"
6b803e5a
CH
68#include "xfs_attr_sf.h"
69#include "xfs_inode_fork.h"
70#include "xfs_inode_buf.h"
6b803e5a
CH
71#include "xfs_alloc.h"
72#include "xfs_btree.h"
6b803e5a
CH
73#include "xfs_bmap.h"
74#include "xfs_trace.h"
75#include "xfs_trans.h"
7b754805 76#include "xfs_ag.h"
631ac87a 77#include "xfs_rmap_btree.h"
794a5604 78#include "xfs_rmap.h"
e7be6330 79#include "xfs_refcount_btree.h"
db17bb0e 80#include "xfs_refcount.h"
49031e66 81#include "xfs_btree_staging.h"
cc085d77 82
1167ddc4
AE
83#ifndef ARRAY_SIZE
84#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
85#endif
2bd0ea18 86
b391b7cd
NS
87#ifndef XFS_SUPER_MAGIC
88#define XFS_SUPER_MAGIC 0x58465342
89#endif
90
de2f203d 91#define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY))))
a580302f 92
fc83c757
CH
93struct libxfs_dev {
94 /* input parameters */
95 char *name; /* pathname of the device */
96 bool isfile; /* is the device a file? */
97 bool create; /* create file if it doesn't exist */
98
99 /* output parameters */
100 dev_t dev; /* device name for the device */
101 long long size; /* size of subvolume (BBs) */
102 int bsize; /* device blksize */
103 int fd; /* file descriptor */
104};
105
2bd0ea18
NS
106/*
107 * Argument structure for libxfs_init().
108 */
01dcfd9e 109struct libxfs_init {
fc83c757
CH
110 struct libxfs_dev data;
111 struct libxfs_dev log;
112 struct libxfs_dev rt;
113
114 /* input parameters */
23d88955 115 unsigned flags; /* LIBXFS_* flags below */
ba9ecd40 116 int bcache_flags; /* cache init flags */
fc83c757 117 int setblksize; /* value to set device blksizes to */
01dcfd9e 118};
2bd0ea18 119
23d88955
CH
120/* disallow all mounted filesystems: */
121#define LIBXFS_ISREADONLY (1U << 0)
122
123/* allow mounted only if mounted ro: */
124#define LIBXFS_ISINACTIVE (1U << 1)
125
126/* repairing a device mounted ro: */
127#define LIBXFS_DANGEROUSLY (1U << 2)
128
129/* disallow other accesses (O_EXCL): */
130#define LIBXFS_EXCLUSIVELY (1U << 3)
131
132/* can use direct I/O, not buffered: */
133#define LIBXFS_DIRECT (1U << 4)
134
135/* lock xfs_buf's - for MT usage */
136#define LIBXFS_USEBUFLOCK (1U << 5)
2bd0ea18
NS
137
138extern char *progname;
7d77349c 139extern xfs_lsn_t libxfs_max_lsn;
01dcfd9e
CH
140
141int libxfs_init(struct libxfs_init *);
142void libxfs_destroy(struct libxfs_init *li);
143
b74a1f6a 144extern int libxfs_device_alignment (void);
b6281496 145extern void libxfs_report(FILE *);
2bd0ea18
NS
146
147/* check or write log footer: specify device, log size in blocks & uuid */
d60ba955 148typedef char *(libxfs_get_block_t)(char *, int, void *);
989b74bc 149
0c12ba5f
BF
150/*
151 * Helpers to clear the log to a particular log cycle.
152 */
153#define XLOG_INIT_CYCLE 1
1c12a814 154extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t,
571a78a7 155 uint, uuid_t *, int, int, int, int, bool);
0c12ba5f
BF
156extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t,
157 xfs_lsn_t, libxfs_get_block_t *, void *);
989b74bc 158
75c8b434 159
5e656dbb 160/* Shared utility routines */
2bd0ea18 161
b626fb59 162extern int libxfs_alloc_file_space (struct xfs_inode *, xfs_off_t,
2bd0ea18
NS
163 xfs_off_t, int, int);
164
b626fb59
DC
165/* XXX: this is messy and needs fixing */
166#ifndef __LIBXFS_INTERNAL_XFS_H__
1552a820
NS
167extern void cmn_err(int, char *, ...);
168enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
b626fb59 169#endif
f302e9e4 170
6b803e5a 171#include "xfs_ialloc.h"
f302e9e4 172
6b803e5a
CH
173#include "xfs_attr_leaf.h"
174#include "xfs_attr_remote.h"
175#include "xfs_trans_space.h"
f302e9e4 176
5e656dbb
BN
177#define XFS_INOBT_IS_FREE_DISK(rp,i) \
178 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
56b2de80 179
c749bd55
BF
180static inline bool
181xfs_inobt_is_sparse_disk(
182 struct xfs_inobt_rec *rp,
183 int offset)
184{
185 int spshift;
186 uint16_t holemask;
187
188 holemask = be16_to_cpu(rp->ir_u.sp.ir_holemask);
189 spshift = offset / XFS_INODES_PER_HOLEMASK_BIT;
190 if ((1 << spshift) & holemask)
191 return true;
192
193 return false;
194}
195
ff105f75
DC
196static inline void
197libxfs_bmbt_disk_get_all(
b37d753d 198 struct xfs_bmbt_rec *rec,
ff105f75
DC
199 struct xfs_bmbt_irec *irec)
200{
b37d753d
CH
201 uint64_t l0 = get_unaligned_be64(&rec->l0);
202 uint64_t l1 = get_unaligned_be64(&rec->l1);
203
204 irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
205 irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21);
206 irec->br_blockcount = l1 & xfs_mask64lo(21);
207 if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN))
208 irec->br_state = XFS_EXT_UNWRITTEN;
209 else
210 irec->br_state = XFS_EXT_NORM;
ff105f75 211}
5e656dbb 212
f616e2bf 213/* XXX: this is clearly a bug - a shared header needs to export this */
5e656dbb
BN
214/* xfs_rtalloc.c */
215int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
0cf6a3a9 216bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
5e656dbb 217
6778635b 218#include "xfs_attr.h"
6bc3531c 219#include "topology.h"
e515cca1 220
586d90c3
DC
221/*
222 * Superblock helpers for programs that act on independent superblock
223 * structures. These used to be part of xfs_format.h.
224 */
225static inline bool xfs_sb_version_haslazysbcount(struct xfs_sb *sbp)
226{
227 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
228 (xfs_sb_version_hasmorebits(sbp) &&
229 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
230}
231
232static inline bool xfs_sb_version_hascrc(struct xfs_sb *sbp)
233{
234 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
235}
236
237static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp)
238{
239 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
240 (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID);
241}
242
243static inline bool xfs_sb_version_hasalign(struct xfs_sb *sbp)
244{
245 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
246 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
247}
248
249static inline bool xfs_sb_version_hasdalign(struct xfs_sb *sbp)
250{
251 return (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
252}
253
254static inline bool xfs_sb_version_haslogv2(struct xfs_sb *sbp)
255{
256 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
257 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
258}
259
260static inline bool xfs_sb_version_hassector(struct xfs_sb *sbp)
261{
262 return (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
263}
264
265static inline bool xfs_sb_version_needsrepair(struct xfs_sb *sbp)
266{
267 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
268 (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR);
269}
270
271static inline bool xfs_sb_version_hassparseinodes(struct xfs_sb *sbp)
272{
273 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
274 xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_SPINODES);
275}
276
2bd0ea18 277#endif /* __LIBXFS_H__ */