]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/libxfs.h
libfrog: move radix-tree.h to libfrog/
[thirdparty/xfsprogs-dev.git] / include / libxfs.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #ifndef __LIBXFS_H__
8 #define __LIBXFS_H__
9
10 #include "libxfs_api_defs.h"
11 #include "platform_defs.h"
12 #include "xfs.h"
13
14 #include "list.h"
15 #include "hlist.h"
16 #include "cache.h"
17 #include "bitops.h"
18 #include "kmem.h"
19 #include "libfrog/radix-tree.h"
20 #include "atomic.h"
21
22 #include "xfs_types.h"
23 #include "xfs_fs.h"
24 #include "xfs_arch.h"
25
26 #include "xfs_shared.h"
27 #include "xfs_format.h"
28 #include "xfs_log_format.h"
29 #include "xfs_quota_defs.h"
30 #include "xfs_trans_resv.h"
31
32
33 /* CRC stuff, buffer API dependent on it */
34 extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
35 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
36
37 #include "xfs_cksum.h"
38
39 /*
40 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
41 * every files via a similar include in the kernel xfs_linux.h.
42 */
43 #include "libxfs_io.h"
44
45 #include "xfs_bit.h"
46 #include "xfs_sb.h"
47 #include "xfs_mount.h"
48 #include "xfs_defer.h"
49 #include "xfs_errortag.h"
50 #include "xfs_da_format.h"
51 #include "xfs_da_btree.h"
52 #include "xfs_dir2.h"
53 #include "xfs_bmap_btree.h"
54 #include "xfs_alloc_btree.h"
55 #include "xfs_ialloc_btree.h"
56 #include "xfs_attr_sf.h"
57 #include "xfs_inode_fork.h"
58 #include "xfs_inode_buf.h"
59 #include "xfs_inode.h"
60 #include "xfs_alloc.h"
61 #include "xfs_btree.h"
62 #include "xfs_btree_trace.h"
63 #include "xfs_bmap.h"
64 #include "xfs_trace.h"
65 #include "xfs_trans.h"
66 #include "xfs_rmap_btree.h"
67 #include "xfs_rmap.h"
68 #include "xfs_refcount_btree.h"
69 #include "xfs_refcount.h"
70
71 #ifndef ARRAY_SIZE
72 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
73 #endif
74
75 #ifndef XFS_SUPER_MAGIC
76 #define XFS_SUPER_MAGIC 0x58465342
77 #endif
78
79 #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY))))
80
81 /*
82 * Argument structure for libxfs_init().
83 */
84 typedef struct libxfs_xinit {
85 /* input parameters */
86 char *volname; /* pathname of volume */
87 char *dname; /* pathname of data "subvolume" */
88 char *logname; /* pathname of log "subvolume" */
89 char *rtname; /* pathname of realtime "subvolume" */
90 int isreadonly; /* filesystem is only read in applic */
91 int isdirect; /* we can attempt to use direct I/O */
92 int disfile; /* data "subvolume" is a regular file */
93 int dcreat; /* try to create data subvolume */
94 int lisfile; /* log "subvolume" is a regular file */
95 int lcreat; /* try to create log subvolume */
96 int risfile; /* realtime "subvolume" is a reg file */
97 int rcreat; /* try to create realtime subvolume */
98 int setblksize; /* attempt to set device blksize */
99 int usebuflock; /* lock xfs_buf_t's - for MT usage */
100 /* output results */
101 dev_t ddev; /* device for data subvolume */
102 dev_t logdev; /* device for log subvolume */
103 dev_t rtdev; /* device for realtime subvolume */
104 long long dsize; /* size of data subvolume (BBs) */
105 long long logBBsize; /* size of log subvolume (BBs) */
106 /* (blocks allocated for use as
107 * log is stored in mount structure) */
108 long long logBBstart; /* start block of log subvolume (BBs) */
109 long long rtsize; /* size of realtime subvolume (BBs) */
110 int dbsize; /* data subvolume device blksize */
111 int lbsize; /* log subvolume device blksize */
112 int rtbsize; /* realtime subvolume device blksize */
113 int dfd; /* data subvolume file descriptor */
114 int logfd; /* log subvolume file descriptor */
115 int rtfd; /* realtime subvolume file descriptor */
116 int icache_flags; /* cache init flags */
117 int bcache_flags; /* cache init flags */
118 } libxfs_init_t;
119
120 #define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */
121 #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
122 #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
123 #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
124 #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
125 #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
126
127 extern char *progname;
128 extern xfs_lsn_t libxfs_max_lsn;
129 extern int libxfs_init (libxfs_init_t *);
130 extern void libxfs_destroy (void);
131 extern int libxfs_device_to_fd (dev_t);
132 extern dev_t libxfs_device_open (char *, int, int, int);
133 extern void libxfs_device_close (dev_t);
134 extern int libxfs_device_alignment (void);
135 extern void libxfs_report(FILE *);
136 extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz);
137 extern int platform_nproc(void);
138
139 /* check or write log footer: specify device, log size in blocks & uuid */
140 typedef char *(libxfs_get_block_t)(char *, int, void *);
141
142 /*
143 * Helpers to clear the log to a particular log cycle.
144 */
145 #define XLOG_INIT_CYCLE 1
146 extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t,
147 uint, uuid_t *, int, int, int, int, bool);
148 extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t,
149 xfs_lsn_t, libxfs_get_block_t *, void *);
150
151
152 /* Shared utility routines */
153
154 extern int libxfs_alloc_file_space (struct xfs_inode *, xfs_off_t,
155 xfs_off_t, int, int);
156
157 /* XXX: this is messy and needs fixing */
158 #ifndef __LIBXFS_INTERNAL_XFS_H__
159 extern void cmn_err(int, char *, ...);
160 enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
161 #endif
162
163
164 extern int libxfs_nproc(void);
165 extern unsigned long libxfs_physmem(void); /* in kilobytes */
166
167 #include "xfs_ialloc.h"
168
169 #include "xfs_attr_leaf.h"
170 #include "xfs_attr_remote.h"
171 #include "xfs_trans_space.h"
172
173 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
174 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
175
176 static inline bool
177 xfs_inobt_is_sparse_disk(
178 struct xfs_inobt_rec *rp,
179 int offset)
180 {
181 int spshift;
182 uint16_t holemask;
183
184 holemask = be16_to_cpu(rp->ir_u.sp.ir_holemask);
185 spshift = offset / XFS_INODES_PER_HOLEMASK_BIT;
186 if ((1 << spshift) & holemask)
187 return true;
188
189 return false;
190 }
191
192 static inline void
193 libxfs_bmbt_disk_get_all(
194 struct xfs_bmbt_rec *rec,
195 struct xfs_bmbt_irec *irec)
196 {
197 uint64_t l0 = get_unaligned_be64(&rec->l0);
198 uint64_t l1 = get_unaligned_be64(&rec->l1);
199
200 irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
201 irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21);
202 irec->br_blockcount = l1 & xfs_mask64lo(21);
203 if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN))
204 irec->br_state = XFS_EXT_UNWRITTEN;
205 else
206 irec->br_state = XFS_EXT_NORM;
207 }
208
209 /* XXX: this is clearly a bug - a shared header needs to export this */
210 /* xfs_rtalloc.c */
211 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
212 bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
213
214 #include "xfs_attr.h"
215
216 #endif /* __LIBXFS_H__ */