]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/libxfs.h
xfs: rework remote attr CRCs
[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 #define XFS_BIG_INUMS 1
23 #define XFS_BIG_BLKNOS 1
24
25 #include <xfs/platform_defs.h>
26
27 #include <xfs/list.h>
28 #include <xfs/hlist.h>
29 #include <xfs/cache.h>
30 #include <xfs/bitops.h>
31 #include <xfs/kmem.h>
32 #include <xfs/radix-tree.h>
33 #include <xfs/swab.h>
34 #include <xfs/atomic.h>
35
36 #include <xfs/xfs_types.h>
37 #include <xfs/xfs_fs.h>
38 #include <xfs/xfs_arch.h>
39 #include <xfs/xfs_bit.h>
40 #include <xfs/xfs_inum.h>
41 #include <xfs/xfs_sb.h>
42 #include <xfs/xfs_ag.h>
43 #include <xfs/xfs_dir2.h>
44 #include <xfs/xfs_mount.h>
45 #include <xfs/xfs_da_btree.h>
46 #include <xfs/xfs_bmap_btree.h>
47 #include <xfs/xfs_alloc_btree.h>
48 #include <xfs/xfs_ialloc_btree.h>
49 #include <xfs/xfs_attr_sf.h>
50 #include <xfs/xfs_dinode.h>
51 #include <xfs/xfs_inode.h>
52 #include <xfs/xfs_buf_item.h>
53 #include <xfs/xfs_inode_item.h>
54 #include <xfs/xfs_alloc.h>
55 #include <xfs/xfs_btree.h>
56 #include <xfs/xfs_btree_trace.h>
57 #include <xfs/xfs_bmap.h>
58 #include <xfs/xfs_trace.h>
59 #include <xfs/xfs_symlink.h>
60
61 #ifndef ARRAY_SIZE
62 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
63 #endif
64
65 #ifndef XFS_SUPER_MAGIC
66 #define XFS_SUPER_MAGIC 0x58465342
67 #endif
68
69 #define xfs_isset(a,i) ((a)[(i)/(sizeof((a))*NBBY)] & (1<<((i)%(sizeof((a))*NBBY))))
70
71 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
72 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
73 #define round_down(x, y) ((x) & ~__round_mask(x, y))
74 #define min(a,b) ((a) < (b) ? (a) : (b))
75
76 /*
77 * Argument structure for libxfs_init().
78 */
79 typedef struct {
80 /* input parameters */
81 char *volname; /* pathname of volume */
82 char *dname; /* pathname of data "subvolume" */
83 char *logname; /* pathname of log "subvolume" */
84 char *rtname; /* pathname of realtime "subvolume" */
85 int isreadonly; /* filesystem is only read in applic */
86 int isdirect; /* we can attempt to use direct I/O */
87 int disfile; /* data "subvolume" is a regular file */
88 int dcreat; /* try to create data subvolume */
89 int lisfile; /* log "subvolume" is a regular file */
90 int lcreat; /* try to create log subvolume */
91 int risfile; /* realtime "subvolume" is a reg file */
92 int rcreat; /* try to create realtime subvolume */
93 int setblksize; /* attempt to set device blksize */
94 int usebuflock; /* lock xfs_buf_t's - for MT usage */
95 /* output results */
96 dev_t ddev; /* device for data subvolume */
97 dev_t logdev; /* device for log subvolume */
98 dev_t rtdev; /* device for realtime subvolume */
99 long long dsize; /* size of data subvolume (BBs) */
100 long long logBBsize; /* size of log subvolume (BBs) */
101 /* (blocks allocated for use as
102 * log is stored in mount structure) */
103 long long logBBstart; /* start block of log subvolume (BBs) */
104 long long rtsize; /* size of realtime subvolume (BBs) */
105 int dbsize; /* data subvolume device blksize */
106 int lbsize; /* log subvolume device blksize */
107 int rtbsize; /* realtime subvolume device blksize */
108 int dfd; /* data subvolume file descriptor */
109 int logfd; /* log subvolume file descriptor */
110 int rtfd; /* realtime subvolume file descriptor */
111 } libxfs_init_t;
112
113 #define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */
114 #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
115 #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
116 #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
117 #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
118 #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
119
120 /*
121 * IO verifier callbacks need the xfs_mount pointer, so we have to behave
122 * somewhat like the kernel now for userspace IO in terms of having buftarg
123 * based devices...
124 */
125 struct xfs_buftarg {
126 struct xfs_mount *bt_mount;
127 dev_t dev;
128 };
129
130 extern void libxfs_buftarg_init(struct xfs_mount *mp, dev_t ddev,
131 dev_t logdev, dev_t rtdev);
132
133 extern char *progname;
134 extern int libxfs_init (libxfs_init_t *);
135 extern void libxfs_destroy (void);
136 extern int libxfs_device_to_fd (dev_t);
137 extern dev_t libxfs_device_open (char *, int, int, int);
138 extern void libxfs_device_zero(struct xfs_buftarg *, xfs_daddr_t, uint);
139 extern void libxfs_device_close (dev_t);
140 extern int libxfs_device_alignment (void);
141 extern void libxfs_report(FILE *);
142 extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz);
143
144 /* check or write log footer: specify device, log size in blocks & uuid */
145 typedef xfs_caddr_t (libxfs_get_block_t)(xfs_caddr_t, int, void *);
146
147 extern int libxfs_log_clear (struct xfs_buftarg *, xfs_daddr_t, uint,
148 uuid_t *, int, int, int);
149 extern int libxfs_log_header (xfs_caddr_t, uuid_t *, int, int, int,
150 libxfs_get_block_t *, void *);
151
152
153 /*
154 * Define a user-level mount structure with all we need
155 * in order to make use of the numerous XFS_* macros.
156 */
157 typedef struct xfs_mount {
158 xfs_sb_t m_sb; /* copy of fs superblock */
159 char *m_fsname; /* filesystem name */
160 int m_bsize; /* fs logical block size */
161 xfs_agnumber_t m_agfrotor; /* last ag where space found */
162 xfs_agnumber_t m_agirotor; /* last ag dir inode alloced */
163 xfs_agnumber_t m_maxagi; /* highest inode alloc group */
164 uint m_rsumlevels; /* rt summary levels */
165 uint m_rsumsize; /* size of rt summary, bytes */
166 struct xfs_inode *m_rbmip; /* pointer to bitmap inode */
167 struct xfs_inode *m_rsumip; /* pointer to summary inode */
168 struct xfs_inode *m_rootip; /* pointer to root directory */
169 struct xfs_buftarg *m_ddev_targp;
170 struct xfs_buftarg *m_logdev_targp;
171 struct xfs_buftarg *m_rtdev_targp;
172 #define m_dev m_ddev_targp
173 #define m_logdev m_logdev_targp
174 #define m_rtdev m_rtdev_targp
175 __uint8_t m_dircook_elog; /* log d-cookie entry bits */
176 __uint8_t m_blkbit_log; /* blocklog + NBBY */
177 __uint8_t m_blkbb_log; /* blocklog - BBSHIFT */
178 __uint8_t m_sectbb_log; /* sectorlog - BBSHIFT */
179 __uint8_t m_agno_log; /* log #ag's */
180 __uint8_t m_agino_log; /* #bits for agino in inum */
181 __uint16_t m_inode_cluster_size;/* min inode buf size */
182 uint m_blockmask; /* sb_blocksize-1 */
183 uint m_blockwsize; /* sb_blocksize in words */
184 uint m_blockwmask; /* blockwsize-1 */
185 uint m_alloc_mxr[2]; /* XFS_ALLOC_BLOCK_MAXRECS */
186 uint m_alloc_mnr[2]; /* XFS_ALLOC_BLOCK_MINRECS */
187 uint m_bmap_dmxr[2]; /* XFS_BMAP_BLOCK_DMAXRECS */
188 uint m_bmap_dmnr[2]; /* XFS_BMAP_BLOCK_DMINRECS */
189 uint m_inobt_mxr[2]; /* XFS_INOBT_BLOCK_MAXRECS */
190 uint m_inobt_mnr[2]; /* XFS_INOBT_BLOCK_MINRECS */
191 uint m_ag_maxlevels; /* XFS_AG_MAXLEVELS */
192 uint m_bm_maxlevels[2]; /* XFS_BM_MAXLEVELS */
193 uint m_in_maxlevels; /* XFS_IN_MAXLEVELS */
194 struct radix_tree_root m_perag_tree;
195 uint m_flags; /* global mount flags */
196 uint m_qflags; /* quota status flags */
197 uint m_attroffset; /* inode attribute offset */
198 uint m_dir_node_ents; /* #entries in a dir danode */
199 uint m_attr_node_ents; /* #entries in attr danode */
200 int m_ialloc_inos; /* inodes in inode allocation */
201 int m_ialloc_blks; /* blocks in inode allocation */
202 int m_litino; /* size of inode union area */
203 int m_inoalign_mask;/* mask sb_inoalignmt if used */
204 xfs_trans_reservations_t m_reservations;/* precomputed res values */
205 __uint64_t m_maxicount; /* maximum inode count */
206 int m_dalign; /* stripe unit */
207 int m_swidth; /* stripe width */
208 int m_sinoalign; /* stripe unit inode alignmnt */
209 int m_attr_magicpct;/* 37% of the blocksize */
210 int m_dir_magicpct; /* 37% of the dir blocksize */
211 const struct xfs_nameops *m_dirnameops; /* vector of dir name ops */
212 int m_dirblksize; /* directory block sz--bytes */
213 int m_dirblkfsbs; /* directory block sz--fsbs */
214 xfs_dablk_t m_dirdatablk; /* blockno of dir data v2 */
215 xfs_dablk_t m_dirleafblk; /* blockno of dir non-data v2 */
216 xfs_dablk_t m_dirfreeblk; /* blockno of dirfreeindex v2 */
217 } xfs_mount_t;
218
219
220 #define LIBXFS_MOUNT_ROOTINOS 0x0001
221 #define LIBXFS_MOUNT_DEBUGGER 0x0002
222 #define LIBXFS_MOUNT_32BITINODES 0x0004
223 #define LIBXFS_MOUNT_32BITINOOPT 0x0008
224 #define LIBXFS_MOUNT_COMPAT_ATTR 0x0010
225 #define LIBXFS_MOUNT_ATTR2 0x0020
226
227 #define LIBXFS_IHASHSIZE(sbp) (1<<10)
228 #define LIBXFS_BHASHSIZE(sbp) (1<<10)
229
230 extern xfs_mount_t *libxfs_mount (xfs_mount_t *, xfs_sb_t *,
231 dev_t, dev_t, dev_t, int);
232 extern void libxfs_umount (xfs_mount_t *);
233 extern void libxfs_rtmount_destroy (xfs_mount_t *);
234
235
236 /*
237 * Simple I/O interface
238 */
239 #define XB_PAGES 2
240
241 struct xfs_buf_map {
242 xfs_daddr_t bm_bn; /* block number for I/O */
243 int bm_len; /* size of I/O */
244 };
245
246 #define DEFINE_SINGLE_BUF_MAP(map, blkno, numblk) \
247 struct xfs_buf_map (map) = { .bm_bn = (blkno), .bm_len = (numblk) };
248
249 struct xfs_buf_ops {
250 void (*verify_read)(struct xfs_buf *);
251 void (*verify_write)(struct xfs_buf *);
252 };
253
254 typedef struct xfs_buf {
255 struct cache_node b_node;
256 unsigned int b_flags;
257 xfs_daddr_t b_bn;
258 unsigned b_bcount;
259 unsigned int b_length;
260 struct xfs_buftarg *b_target;
261 #define b_dev b_target->dev
262 pthread_mutex_t b_lock;
263 pthread_t b_holder;
264 unsigned int b_recur;
265 void *b_fspriv;
266 void *b_fsprivate2;
267 void *b_fsprivate3;
268 void *b_addr;
269 int b_error;
270 const struct xfs_buf_ops *b_ops;
271 struct xfs_perag *b_pag;
272 struct xfs_buf_map *b_map;
273 int b_nmaps;
274 #ifdef XFS_BUF_TRACING
275 struct list_head b_lock_list;
276 const char *b_func;
277 const char *b_file;
278 int b_line;
279 #endif
280 } xfs_buf_t;
281
282 enum xfs_buf_flags_t { /* b_flags bits */
283 LIBXFS_B_EXIT = 0x0001, /* ==LIBXFS_EXIT_ON_FAILURE */
284 LIBXFS_B_DIRTY = 0x0002, /* buffer has been modified */
285 LIBXFS_B_STALE = 0x0004, /* buffer marked as invalid */
286 LIBXFS_B_UPTODATE = 0x0008, /* buffer is sync'd to disk */
287 LIBXFS_B_DISCONTIG = 0x0010, /* discontiguous buffer */
288 };
289
290 #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))
291
292 #define XFS_BUF_PTR(bp) ((char *)(bp)->b_addr)
293 #define xfs_buf_offset(bp, offset) (XFS_BUF_PTR(bp) + (offset))
294 #define XFS_BUF_ADDR(bp) ((bp)->b_bn)
295 #define XFS_BUF_SIZE(bp) ((bp)->b_bcount)
296 #define XFS_BUF_COUNT(bp) ((bp)->b_bcount)
297 #define XFS_BUF_TARGET(bp) ((bp)->b_dev)
298 #define XFS_BUF_SET_PTR(bp,p,cnt) ({ \
299 (bp)->b_addr = (char *)(p); \
300 XFS_BUF_SET_COUNT(bp,cnt); \
301 })
302
303 #define XFS_BUF_SET_ADDR(bp,blk) ((bp)->b_bn = (blk))
304 #define XFS_BUF_SET_COUNT(bp,cnt) ((bp)->b_bcount = (cnt))
305
306 #define XFS_BUF_FSPRIVATE(bp,type) ((type)(bp)->b_fspriv)
307 #define XFS_BUF_SET_FSPRIVATE(bp,val) (bp)->b_fspriv = (void *)(val)
308 #define XFS_BUF_FSPRIVATE2(bp,type) ((type)(bp)->b_fsprivate2)
309 #define XFS_BUF_SET_FSPRIVATE2(bp,val) (bp)->b_fsprivate2 = (void *)(val)
310 #define XFS_BUF_FSPRIVATE3(bp,type) ((type)(bp)->b_fsprivate3)
311 #define XFS_BUF_SET_FSPRIVATE3(bp,val) (bp)->b_fsprivate3 = (void *)(val)
312
313 #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \
314 libxfs_bcache, \
315 (struct cache_node *)(bp), \
316 (pri))
317 #define XFS_BUF_PRIORITY(bp) (cache_node_get_priority( \
318 (struct cache_node *)(bp)))
319 #define xfs_buf_set_ref(bp,ref) ((void) 0)
320 #define xfs_buf_ioerror(bp,err) (bp)->b_error = (err);
321
322 /* Buffer Cache Interfaces */
323
324 extern struct cache *libxfs_bcache;
325 extern struct cache_operations libxfs_bcache_operations;
326
327 #define LIBXFS_GETBUF_TRYLOCK (1 << 0)
328
329 #ifdef XFS_BUF_TRACING
330
331 #define libxfs_readbuf(dev, daddr, len, flags, ops) \
332 libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \
333 (dev), (daddr), (len), (flags), (ops))
334 #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
335 libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \
336 (dev), (map), (nmaps), (flags), (ops))
337 #define libxfs_writebuf(buf, flags) \
338 libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \
339 (buf), (flags))
340 #define libxfs_getbuf(dev, daddr, len) \
341 libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
342 (dev), (daddr), (len))
343 #define libxfs_getbuf_map(dev, map, nmaps) \
344 libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \
345 (dev), (map), (nmaps))
346 #define libxfs_getbuf_flags(dev, daddr, len, flags) \
347 libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \
348 (dev), (daddr), (len), (flags))
349 #define libxfs_putbuf(buf) \
350 libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
351
352 extern xfs_buf_t *libxfs_trace_readbuf(const char *, const char *, int,
353 struct xfs_buftarg *, xfs_daddr_t, int, int,
354 const struct xfs_buf_ops *);
355 extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int,
356 struct xfs_buftarg *, struct xfs_buf_map *, int, int,
357 const struct xfs_buf_ops *);
358 extern int libxfs_trace_writebuf(const char *, const char *, int,
359 xfs_buf_t *, int);
360 extern xfs_buf_t *libxfs_trace_getbuf(const char *, const char *, int,
361 struct xfs_buftarg *, xfs_daddr_t, int);
362 extern xfs_buf_t *libxfs_trace_getbuf_map(const char *, const char *, int,
363 struct xfs_buftarg *, struct xfs_buf_map *, int);
364 extern xfs_buf_t *libxfs_trace_getbuf_flags(const char *, const char *, int,
365 struct xfs_buftarg *, xfs_daddr_t, int, unsigned int);
366 extern void libxfs_trace_putbuf (const char *, const char *, int,
367 xfs_buf_t *);
368
369 #else
370
371 extern xfs_buf_t *libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int,
372 const struct xfs_buf_ops *);
373 extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
374 int, int, const struct xfs_buf_ops *);
375 extern int libxfs_writebuf(xfs_buf_t *, int);
376 extern xfs_buf_t *libxfs_getbuf(struct xfs_buftarg *, xfs_daddr_t, int);
377 extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
378 struct xfs_buf_map *, int);
379 extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t,
380 int, unsigned int);
381 extern void libxfs_putbuf (xfs_buf_t *);
382
383 #endif
384
385 extern xfs_buf_t *libxfs_getsb(xfs_mount_t *, int);
386 extern void libxfs_bcache_purge(void);
387 extern void libxfs_bcache_flush(void);
388 extern void libxfs_purgebuf(xfs_buf_t *);
389 extern int libxfs_bcache_overflowed(void);
390 extern int libxfs_bcache_usage(void);
391
392 /* Buffer (Raw) Interfaces */
393 extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, xfs_daddr_t, int);
394 extern void libxfs_putbufr(xfs_buf_t *);
395
396 extern int libxfs_writebuf_int(xfs_buf_t *, int);
397 extern int libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, int, int);
398
399 extern int libxfs_bhash_size;
400 extern int libxfs_ihash_size;
401
402 #define LIBXFS_BREAD 0x1
403 #define LIBXFS_BWRITE 0x2
404 #define LIBXFS_BZERO 0x4
405
406 extern void libxfs_iomove (xfs_buf_t *, uint, int, void *, int);
407
408
409 /*
410 * Transaction interface
411 */
412
413 typedef struct xfs_log_item {
414 struct xfs_log_item_desc *li_desc; /* ptr to current desc*/
415 struct xfs_mount *li_mountp; /* ptr to fs mount */
416 uint li_type; /* item type */
417 xfs_lsn_t li_lsn;
418 } xfs_log_item_t;
419
420 typedef struct xfs_inode_log_item {
421 xfs_log_item_t ili_item; /* common portion */
422 struct xfs_inode *ili_inode; /* inode pointer */
423 unsigned short ili_flags; /* misc flags */
424 unsigned int ili_fields; /* fields to be logged */
425 unsigned int ili_last_fields; /* fields when flushed*/
426 xfs_inode_log_format_t ili_format; /* logged structure */
427 int ili_lock_flags;
428 } xfs_inode_log_item_t;
429
430 typedef struct xfs_buf_log_item {
431 xfs_log_item_t bli_item; /* common item structure */
432 struct xfs_buf *bli_buf; /* real buffer pointer */
433 unsigned int bli_flags; /* misc flags */
434 unsigned int bli_recur; /* recursion count */
435 xfs_buf_log_format_t bli_format; /* in-log header */
436 } xfs_buf_log_item_t;
437
438 #include <xfs/xfs_trans.h>
439
440 typedef struct xfs_trans {
441 unsigned int t_type; /* transaction type */
442 unsigned int t_log_res; /* amt of log space resvd */
443 unsigned int t_log_count; /* count for perm log res */
444 xfs_mount_t *t_mountp; /* ptr to fs mount struct */
445 unsigned int t_flags; /* misc flags */
446 long t_icount_delta; /* superblock icount change */
447 long t_ifree_delta; /* superblock ifree change */
448 long t_fdblocks_delta; /* superblock fdblocks chg */
449 long t_frextents_delta; /* superblock freextents chg */
450 struct list_head t_items; /* first log item desc chunk */
451 } xfs_trans_t;
452
453 extern xfs_trans_t *libxfs_trans_alloc (xfs_mount_t *, int);
454 extern xfs_trans_t *libxfs_trans_dup (xfs_trans_t *);
455 extern int libxfs_trans_reserve (xfs_trans_t *, uint,uint,uint,uint,uint);
456 extern int libxfs_trans_commit (xfs_trans_t *, uint);
457 extern void libxfs_trans_cancel (xfs_trans_t *, int);
458 extern void libxfs_mod_sb (xfs_trans_t *, __int64_t);
459 extern xfs_buf_t *libxfs_trans_getsb (xfs_trans_t *, xfs_mount_t *, int);
460
461 extern int libxfs_trans_iget (xfs_mount_t *, xfs_trans_t *, xfs_ino_t,
462 uint, uint, struct xfs_inode **);
463 extern void libxfs_trans_iput(xfs_trans_t *, struct xfs_inode *, uint);
464 extern void libxfs_trans_ijoin (xfs_trans_t *, struct xfs_inode *, uint);
465 extern void libxfs_trans_ihold (xfs_trans_t *, struct xfs_inode *);
466 extern void libxfs_trans_ijoin_ref(xfs_trans_t *, struct xfs_inode *, int);
467 extern void libxfs_trans_log_inode (xfs_trans_t *, struct xfs_inode *,
468 uint);
469
470 extern void libxfs_trans_brelse (xfs_trans_t *, struct xfs_buf *);
471 extern void libxfs_trans_binval (xfs_trans_t *, struct xfs_buf *);
472 extern void libxfs_trans_bjoin (xfs_trans_t *, struct xfs_buf *);
473 extern void libxfs_trans_bhold (xfs_trans_t *, struct xfs_buf *);
474 extern void libxfs_trans_log_buf (xfs_trans_t *, struct xfs_buf *,
475 uint, uint);
476 /*
477 extern xfs_buf_t *libxfs_trans_get_buf (xfs_trans_t *, dev_t,
478 xfs_daddr_t, int, uint);
479 extern int libxfs_trans_read_buf (xfs_mount_t *, xfs_trans_t *, dev_t,
480 xfs_daddr_t, int, uint, struct xfs_buf **);
481 */
482
483 struct xfs_buf *libxfs_trans_get_buf_map(struct xfs_trans *tp,
484 struct xfs_buftarg *btp,
485 struct xfs_buf_map *map, int nmaps,
486 uint flags);
487
488 static inline struct xfs_buf *
489 libxfs_trans_get_buf(
490 struct xfs_trans *tp,
491 struct xfs_buftarg *btp,
492 xfs_daddr_t blkno,
493 int numblks,
494 uint flags)
495 {
496 DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
497 return libxfs_trans_get_buf_map(tp, btp, &map, 1, flags);
498 }
499
500 int libxfs_trans_read_buf_map(struct xfs_mount *mp,
501 struct xfs_trans *tp,
502 struct xfs_buftarg *btp,
503 struct xfs_buf_map *map, int nmaps,
504 uint flags, struct xfs_buf **bpp,
505 const struct xfs_buf_ops *ops);
506
507 static inline int
508 libxfs_trans_read_buf(
509 struct xfs_mount *mp,
510 struct xfs_trans *tp,
511 struct xfs_buftarg *btp,
512 xfs_daddr_t blkno,
513 int numblks,
514 uint flags,
515 struct xfs_buf **bpp,
516 const struct xfs_buf_ops *ops)
517 {
518 DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
519 return libxfs_trans_read_buf_map(mp, tp, btp, &map, 1,
520 flags, bpp, ops);
521 }
522
523 /*
524 * Inode interface
525 */
526 typedef struct xfs_inode {
527 struct cache_node i_node;
528 xfs_mount_t *i_mount; /* fs mount struct ptr */
529 xfs_ino_t i_ino; /* inode number (agno/agino) */
530 struct xfs_imap i_imap; /* location for xfs_imap() */
531 struct xfs_buftarg i_dev; /* dev for this inode */
532 xfs_ifork_t *i_afp; /* attribute fork pointer */
533 xfs_ifork_t i_df; /* data fork */
534 xfs_trans_t *i_transp; /* ptr to owning transaction */
535 xfs_inode_log_item_t *i_itemp; /* logging information */
536 unsigned int i_delayed_blks; /* count of delay alloc blks */
537 xfs_icdinode_t i_d; /* most of ondisk inode */
538 xfs_fsize_t i_size; /* in-memory size */
539 } xfs_inode_t;
540
541 #define LIBXFS_ATTR_ROOT 0x0002 /* use attrs in root namespace */
542 #define LIBXFS_ATTR_SECURE 0x0008 /* use attrs in security namespace */
543 #define LIBXFS_ATTR_CREATE 0x0010 /* create, but fail if attr exists */
544 #define LIBXFS_ATTR_REPLACE 0x0020 /* set, but fail if attr not exists */
545
546 /*
547 * Project quota id helpers (previously projid was 16bit only and using two
548 * 16bit values to hold new 32bit projid was chosen to retain compatibility with
549 * "old" filesystems).
550 *
551 * Copied here from xfs_inode.h because it has to be defined after the struct
552 * xfs_inode...
553 */
554 static inline prid_t
555 xfs_get_projid(struct xfs_icdinode *id)
556 {
557 return (prid_t)id->di_projid_hi << 16 | id->di_projid_lo;
558 }
559
560 static inline void
561 xfs_set_projid(struct xfs_icdinode *id, prid_t projid)
562 {
563 id->di_projid_hi = (__uint16_t) (projid >> 16);
564 id->di_projid_lo = (__uint16_t) (projid & 0xffff);
565 }
566
567 typedef struct cred {
568 uid_t cr_uid;
569 gid_t cr_gid;
570 } cred_t;
571
572 extern int libxfs_inode_alloc (xfs_trans_t **, xfs_inode_t *, mode_t,
573 nlink_t, xfs_dev_t, struct cred *,
574 struct fsxattr *, xfs_inode_t **);
575 extern void libxfs_trans_inode_alloc_buf (xfs_trans_t *, xfs_buf_t *);
576
577 extern void libxfs_trans_ichgtime(struct xfs_trans *,
578 struct xfs_inode *, int);
579 extern int libxfs_iflush_int (xfs_inode_t *, xfs_buf_t *);
580
581 /* Inode Cache Interfaces */
582 extern struct cache *libxfs_icache;
583 extern struct cache_operations libxfs_icache_operations;
584 extern void libxfs_icache_purge (void);
585 extern int libxfs_iget (xfs_mount_t *, xfs_trans_t *, xfs_ino_t,
586 uint, xfs_inode_t **, xfs_daddr_t);
587 extern void libxfs_iput (xfs_inode_t *, uint);
588
589 #include <xfs/xfs_dir2_format.h>
590
591 /* Shared utility routines */
592 extern unsigned int libxfs_log2_roundup(unsigned int i);
593
594 extern int libxfs_alloc_file_space (xfs_inode_t *, xfs_off_t,
595 xfs_off_t, int, int);
596 extern int libxfs_bmap_finish(xfs_trans_t **, xfs_bmap_free_t *, int *);
597
598 extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount *, char *, ...);
599 extern void libxfs_fs_cmn_err(int, struct xfs_mount *, char *, ...);
600
601 extern void cmn_err(int, char *, ...);
602 enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
603
604
605 #define LIBXFS_BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
606 extern int libxfs_nproc(void);
607 extern unsigned long libxfs_physmem(void); /* in kilobytes */
608
609 #include <xfs/xfs_ialloc.h>
610 #include <xfs/xfs_rtalloc.h>
611
612 #include <xfs/xfs_attr_leaf.h>
613 #include <xfs/xfs_attr_remote.h>
614 #include <xfs/xfs_quota.h>
615 #include <xfs/xfs_trans_space.h>
616 #include <xfs/xfs_log.h>
617 #include <xfs/xfs_log_priv.h>
618
619 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
620 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
621
622 /*
623 * public xfs kernel routines to be called as libxfs_*
624 */
625
626 /* xfs_alloc.c */
627 int libxfs_alloc_fix_freelist(xfs_alloc_arg_t *, int);
628
629 /* xfs_attr.c */
630 int libxfs_attr_get(struct xfs_inode *, const unsigned char *,
631 unsigned char *, int *, int);
632 int libxfs_attr_set(struct xfs_inode *, const unsigned char *,
633 unsigned char *, int, int);
634 int libxfs_attr_remove(struct xfs_inode *, const unsigned char *, int);
635
636 /* xfs_bmap.c */
637 xfs_bmbt_rec_host_t *xfs_bmap_search_extents(xfs_inode_t *, xfs_fileoff_t,
638 int, int *, xfs_extnum_t *, xfs_bmbt_irec_t *,
639 xfs_bmbt_irec_t *);
640 void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
641
642 /* xfs_attr_leaf.h */
643 #define libxfs_attr_leaf_newentsize xfs_attr_leaf_newentsize
644
645 /* xfs_bit.h */
646 #define libxfs_highbit32 xfs_highbit32
647 #define libxfs_highbit64 xfs_highbit64
648
649 /* xfs_bmap.h */
650 #define libxfs_bmap_cancel xfs_bmap_cancel
651 #define libxfs_bmap_last_offset xfs_bmap_last_offset
652 #define libxfs_bmapi_write xfs_bmapi_write
653 #define libxfs_bmapi_read xfs_bmapi_read
654 #define libxfs_bunmapi xfs_bunmapi
655
656 /* xfs_bmap_btree.h */
657 #define libxfs_bmbt_disk_get_all xfs_bmbt_disk_get_all
658
659 /* xfs_da_btree.h */
660 #define libxfs_da_brelse xfs_da_brelse
661 #define libxfs_da_hashname xfs_da_hashname
662 #define libxfs_da_shrink_inode xfs_da_shrink_inode
663 #define libxfs_da_read_buf xfs_da_read_buf
664
665 /* xfs_dir2.h */
666 #define libxfs_dir_createname xfs_dir_createname
667 #define libxfs_dir_init xfs_dir_init
668 #define libxfs_dir_lookup xfs_dir_lookup
669 #define libxfs_dir_replace xfs_dir_replace
670 #define libxfs_dir2_isblock xfs_dir2_isblock
671 #define libxfs_dir2_isleaf xfs_dir2_isleaf
672
673 /* xfs_dir2_data.h */
674 #define libxfs_dir2_data_freescan xfs_dir2_data_freescan
675 #define libxfs_dir2_data_log_entry xfs_dir2_data_log_entry
676 #define libxfs_dir2_data_log_header xfs_dir2_data_log_header
677 #define libxfs_dir2_data_make_free xfs_dir2_data_make_free
678 #define libxfs_dir2_data_use_free xfs_dir2_data_use_free
679 #define libxfs_dir2_shrink_inode xfs_dir2_shrink_inode
680
681 /* xfs_inode.h */
682 #define libxfs_dinode_from_disk xfs_dinode_from_disk
683 #define libxfs_dinode_to_disk xfs_dinode_to_disk
684 void xfs_dinode_from_disk(struct xfs_icdinode *,
685 struct xfs_dinode *);
686 #define libxfs_dinode_calc_crc xfs_dinode_calc_crc
687 #define libxfs_idata_realloc xfs_idata_realloc
688 #define libxfs_idestroy_fork xfs_idestroy_fork
689
690 /* xfs_mount.h */
691 #define libxfs_mod_sb xfs_mod_sb
692 #define libxfs_sb_from_disk xfs_sb_from_disk
693 #define libxfs_sb_to_disk xfs_sb_to_disk
694
695 /* xfs_symlink.h */
696 #define libxfs_symlink_blocks xfs_symlink_blocks
697 #define libxfs_symlink_hdr_ok xfs_symlink_hdr_ok
698
699 /* xfs_rtalloc.c */
700 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
701
702 /* CRC wrappers */
703
704 extern uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len);
705 extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
706
707 #define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l))
708 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
709
710 #include <xfs/xfs_cksum.h>
711
712 #endif /* __LIBXFS_H__ */