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