2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
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.
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.
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
22 #define XFS_BIG_INUMS 1
23 #define XFS_BIG_BLKNOS 1
25 #include <xfs/platform_defs.h>
28 #include <xfs/hlist.h>
29 #include <xfs/cache.h>
30 #include <xfs/bitops.h>
32 #include <xfs/radix-tree.h>
34 #include <xfs/atomic.h>
36 #include <xfs/xfs_types.h>
37 #include <xfs/xfs_fs.h>
38 #include <xfs/xfs_arch.h>
40 #include <xfs/xfs_shared.h>
41 #include <xfs/xfs_format.h>
42 #include <xfs/xfs_log_format.h>
43 #include <xfs/xfs_quota_defs.h>
44 #include <xfs/xfs_trans_resv.h>
46 #include <xfs/xfs_bit.h>
47 #include <xfs/xfs_inum.h>
48 #include <xfs/xfs_sb.h>
49 #include <xfs/xfs_ag.h>
50 #include <xfs/xfs_bmap_btree.h>
51 #include <xfs/xfs_alloc_btree.h>
52 #include <xfs/xfs_ialloc_btree.h>
53 #include <xfs/xfs_attr_sf.h>
54 #include <xfs/xfs_dinode.h>
55 #include <xfs/xfs_inode_fork.h>
56 #include <xfs/xfs_inode_buf.h>
57 #include <xfs/xfs_alloc.h>
58 #include <xfs/xfs_btree.h>
59 #include <xfs/xfs_btree_trace.h>
60 #include <xfs/xfs_bmap.h>
61 #include <xfs/xfs_trace.h>
65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
68 #ifndef XFS_SUPER_MAGIC
69 #define XFS_SUPER_MAGIC 0x58465342
72 #define xfs_isset(a,i) ((a)[(i)/(sizeof((a))*NBBY)] & (1<<((i)%(sizeof((a))*NBBY))))
74 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
75 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
76 #define round_down(x, y) ((x) & ~__round_mask(x, y))
79 * Argument structure for libxfs_init().
82 /* input parameters */
83 char *volname
; /* pathname of volume */
84 char *dname
; /* pathname of data "subvolume" */
85 char *logname
; /* pathname of log "subvolume" */
86 char *rtname
; /* pathname of realtime "subvolume" */
87 int isreadonly
; /* filesystem is only read in applic */
88 int isdirect
; /* we can attempt to use direct I/O */
89 int disfile
; /* data "subvolume" is a regular file */
90 int dcreat
; /* try to create data subvolume */
91 int lisfile
; /* log "subvolume" is a regular file */
92 int lcreat
; /* try to create log subvolume */
93 int risfile
; /* realtime "subvolume" is a reg file */
94 int rcreat
; /* try to create realtime subvolume */
95 int setblksize
; /* attempt to set device blksize */
96 int usebuflock
; /* lock xfs_buf_t's - for MT usage */
98 dev_t ddev
; /* device for data subvolume */
99 dev_t logdev
; /* device for log subvolume */
100 dev_t rtdev
; /* device for realtime subvolume */
101 long long dsize
; /* size of data subvolume (BBs) */
102 long long logBBsize
; /* size of log subvolume (BBs) */
103 /* (blocks allocated for use as
104 * log is stored in mount structure) */
105 long long logBBstart
; /* start block of log subvolume (BBs) */
106 long long rtsize
; /* size of realtime subvolume (BBs) */
107 int dbsize
; /* data subvolume device blksize */
108 int lbsize
; /* log subvolume device blksize */
109 int rtbsize
; /* realtime subvolume device blksize */
110 int dfd
; /* data subvolume file descriptor */
111 int logfd
; /* log subvolume file descriptor */
112 int rtfd
; /* realtime subvolume file descriptor */
115 #define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */
116 #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
117 #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
118 #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
119 #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
120 #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
123 * IO verifier callbacks need the xfs_mount pointer, so we have to behave
124 * somewhat like the kernel now for userspace IO in terms of having buftarg
128 struct xfs_mount
*bt_mount
;
132 extern void libxfs_buftarg_init(struct xfs_mount
*mp
, dev_t ddev
,
133 dev_t logdev
, dev_t rtdev
);
135 extern char *progname
;
136 extern int libxfs_init (libxfs_init_t
*);
137 extern void libxfs_destroy (void);
138 extern int libxfs_device_to_fd (dev_t
);
139 extern dev_t
libxfs_device_open (char *, int, int, int);
140 extern void libxfs_device_zero(struct xfs_buftarg
*, xfs_daddr_t
, uint
);
141 extern void libxfs_device_close (dev_t
);
142 extern int libxfs_device_alignment (void);
143 extern void libxfs_report(FILE *);
144 extern void platform_findsizes(char *path
, int fd
, long long *sz
, int *bsz
);
146 /* check or write log footer: specify device, log size in blocks & uuid */
147 typedef xfs_caddr_t (libxfs_get_block_t
)(xfs_caddr_t
, int, void *);
149 extern int libxfs_log_clear (struct xfs_buftarg
*, xfs_daddr_t
, uint
,
150 uuid_t
*, int, int, int);
151 extern int libxfs_log_header (xfs_caddr_t
, uuid_t
*, int, int, int,
152 libxfs_get_block_t
*, void *);
156 * Define a user-level mount structure with all we need
157 * in order to make use of the numerous XFS_* macros.
159 typedef struct xfs_mount
{
160 xfs_sb_t m_sb
; /* copy of fs superblock */
161 char *m_fsname
; /* filesystem name */
162 int m_bsize
; /* fs logical block size */
163 xfs_agnumber_t m_agfrotor
; /* last ag where space found */
164 xfs_agnumber_t m_agirotor
; /* last ag dir inode alloced */
165 xfs_agnumber_t m_maxagi
; /* highest inode alloc group */
166 uint m_rsumlevels
; /* rt summary levels */
167 uint m_rsumsize
; /* size of rt summary, bytes */
168 struct xfs_inode
*m_rbmip
; /* pointer to bitmap inode */
169 struct xfs_inode
*m_rsumip
; /* pointer to summary inode */
170 struct xfs_buftarg
*m_ddev_targp
;
171 struct xfs_buftarg
*m_logdev_targp
;
172 struct xfs_buftarg
*m_rtdev_targp
;
173 #define m_dev m_ddev_targp
174 #define m_logdev m_logdev_targp
175 #define m_rtdev m_rtdev_targp
176 __uint8_t m_dircook_elog
; /* log d-cookie entry bits */
177 __uint8_t m_blkbit_log
; /* blocklog + NBBY */
178 __uint8_t m_blkbb_log
; /* blocklog - BBSHIFT */
179 __uint8_t m_sectbb_log
; /* sectorlog - BBSHIFT */
180 __uint8_t m_agno_log
; /* log #ag's */
181 __uint8_t m_agino_log
; /* #bits for agino in inum */
182 __uint16_t m_inode_cluster_size
;/* min inode buf size */
183 uint m_blockmask
; /* sb_blocksize-1 */
184 uint m_blockwsize
; /* sb_blocksize in words */
185 uint m_blockwmask
; /* blockwsize-1 */
186 uint m_alloc_mxr
[2]; /* XFS_ALLOC_BLOCK_MAXRECS */
187 uint m_alloc_mnr
[2]; /* XFS_ALLOC_BLOCK_MINRECS */
188 uint m_bmap_dmxr
[2]; /* XFS_BMAP_BLOCK_DMAXRECS */
189 uint m_bmap_dmnr
[2]; /* XFS_BMAP_BLOCK_DMINRECS */
190 uint m_inobt_mxr
[2]; /* XFS_INOBT_BLOCK_MAXRECS */
191 uint m_inobt_mnr
[2]; /* XFS_INOBT_BLOCK_MINRECS */
192 uint m_ag_maxlevels
; /* XFS_AG_MAXLEVELS */
193 uint m_bm_maxlevels
[2]; /* XFS_BM_MAXLEVELS */
194 uint m_in_maxlevels
; /* XFS_IN_MAXLEVELS */
195 struct radix_tree_root m_perag_tree
;
196 uint m_flags
; /* global mount flags */
197 uint m_qflags
; /* quota status flags */
198 uint m_attroffset
; /* inode attribute offset */
199 uint m_dir_node_ents
; /* #entries in a dir danode */
200 uint m_attr_node_ents
; /* #entries in attr danode */
201 int m_ialloc_inos
; /* inodes in inode allocation */
202 int m_ialloc_blks
; /* blocks in inode allocation */
203 int m_litino
; /* size of inode union area */
204 int m_inoalign_mask
;/* mask sb_inoalignmt if used */
205 struct xfs_trans_resv m_resv
; /* precomputed res values */
206 __uint64_t m_maxicount
; /* maximum inode count */
207 int m_dalign
; /* stripe unit */
208 int m_swidth
; /* stripe width */
209 int m_sinoalign
; /* stripe unit inode alignmnt */
210 int m_attr_magicpct
;/* 37% of the blocksize */
211 int m_dir_magicpct
; /* 37% of the dir blocksize */
212 const struct xfs_nameops
*m_dirnameops
; /* vector of dir name ops */
213 int m_dirblksize
; /* directory block sz--bytes */
214 int m_dirblkfsbs
; /* directory block sz--fsbs */
215 xfs_dablk_t m_dirdatablk
; /* blockno of dir data v2 */
216 xfs_dablk_t m_dirleafblk
; /* blockno of dir non-data v2 */
217 xfs_dablk_t m_dirfreeblk
; /* blockno of dirfreeindex v2 */
220 * anonymous struct to allow xfs_dquot_buf.c to compile.
221 * Pointer is always null in userspace, so code does not use it at all
230 * Per-ag incore structure, copies of information in agf and agi,
231 * to improve the performance of allocation group selection.
233 typedef struct xfs_perag
{
234 struct xfs_mount
*pag_mount
; /* owner filesystem */
235 xfs_agnumber_t pag_agno
; /* AG this structure belongs to */
236 atomic_t pag_ref
; /* perag reference count */
237 char pagf_init
; /* this agf's entry is initialized */
238 char pagi_init
; /* this agi's entry is initialized */
239 char pagf_metadata
; /* the agf is preferred to be metadata */
240 char pagi_inodeok
; /* The agi is ok for inodes */
241 __uint8_t pagf_levels
[XFS_BTNUM_AGF
];
242 /* # of levels in bno & cnt btree */
243 __uint32_t pagf_flcount
; /* count of blocks in freelist */
244 xfs_extlen_t pagf_freeblks
; /* total free blocks */
245 xfs_extlen_t pagf_longest
; /* longest free space */
246 __uint32_t pagf_btreeblks
; /* # of blocks held in AGF btrees */
247 xfs_agino_t pagi_freecount
; /* number of free inodes */
248 xfs_agino_t pagi_count
; /* number of allocated inodes */
251 * Inode allocation search lookup optimisation.
252 * If the pagino matches, the search for new inodes
253 * doesn't need to search the near ones again straight away
255 xfs_agino_t pagl_pagino
;
256 xfs_agino_t pagl_leftrec
;
257 xfs_agino_t pagl_rightrec
;
258 int pagb_count
; /* pagb slots in use */
261 #define LIBXFS_MOUNT_DEBUGGER 0x0001
262 #define LIBXFS_MOUNT_32BITINODES 0x0002
263 #define LIBXFS_MOUNT_32BITINOOPT 0x0004
264 #define LIBXFS_MOUNT_COMPAT_ATTR 0x0008
265 #define LIBXFS_MOUNT_ATTR2 0x0010
267 #define LIBXFS_BHASHSIZE(sbp) (1<<10)
269 extern xfs_mount_t
*libxfs_mount (xfs_mount_t
*, xfs_sb_t
*,
270 dev_t
, dev_t
, dev_t
, int);
271 extern void libxfs_umount (xfs_mount_t
*);
272 extern void libxfs_rtmount_destroy (xfs_mount_t
*);
275 * xfs/xfs_da_format.h needs struct xfs_mount to be defined
277 #include <xfs/xfs_da_format.h>
278 #include <xfs/xfs_da_btree.h>
279 #include <xfs/xfs_dir2.h>
282 * Simple I/O interface
287 xfs_daddr_t bm_bn
; /* block number for I/O */
288 int bm_len
; /* size of I/O */
291 #define DEFINE_SINGLE_BUF_MAP(map, blkno, numblk) \
292 struct xfs_buf_map (map) = { .bm_bn = (blkno), .bm_len = (numblk) };
295 void (*verify_read
)(struct xfs_buf
*);
296 void (*verify_write
)(struct xfs_buf
*);
299 typedef struct xfs_buf
{
300 struct cache_node b_node
;
301 unsigned int b_flags
;
304 unsigned int b_length
;
305 struct xfs_buftarg
*b_target
;
306 #define b_dev b_target->dev
307 pthread_mutex_t b_lock
;
309 unsigned int b_recur
;
315 const struct xfs_buf_ops
*b_ops
;
316 struct xfs_perag
*b_pag
;
317 struct xfs_buf_map
*b_map
;
319 #ifdef XFS_BUF_TRACING
320 struct list_head b_lock_list
;
327 enum xfs_buf_flags_t
{ /* b_flags bits */
328 LIBXFS_B_EXIT
= 0x0001, /* ==LIBXFS_EXIT_ON_FAILURE */
329 LIBXFS_B_DIRTY
= 0x0002, /* buffer has been modified */
330 LIBXFS_B_STALE
= 0x0004, /* buffer marked as invalid */
331 LIBXFS_B_UPTODATE
= 0x0008, /* buffer is sync'd to disk */
332 LIBXFS_B_DISCONTIG
= 0x0010, /* discontiguous buffer */
335 #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))
337 #define XFS_BUF_PTR(bp) ((char *)(bp)->b_addr)
338 #define xfs_buf_offset(bp, offset) (XFS_BUF_PTR(bp) + (offset))
339 #define XFS_BUF_ADDR(bp) ((bp)->b_bn)
340 #define XFS_BUF_SIZE(bp) ((bp)->b_bcount)
341 #define XFS_BUF_COUNT(bp) ((bp)->b_bcount)
342 #define XFS_BUF_TARGET(bp) ((bp)->b_dev)
343 #define XFS_BUF_SET_PTR(bp,p,cnt) ({ \
344 (bp)->b_addr = (char *)(p); \
345 XFS_BUF_SET_COUNT(bp,cnt); \
348 #define XFS_BUF_SET_ADDR(bp,blk) ((bp)->b_bn = (blk))
349 #define XFS_BUF_SET_COUNT(bp,cnt) ((bp)->b_bcount = (cnt))
351 #define XFS_BUF_FSPRIVATE(bp,type) ((type)(bp)->b_fspriv)
352 #define XFS_BUF_SET_FSPRIVATE(bp,val) (bp)->b_fspriv = (void *)(val)
353 #define XFS_BUF_FSPRIVATE2(bp,type) ((type)(bp)->b_fsprivate2)
354 #define XFS_BUF_SET_FSPRIVATE2(bp,val) (bp)->b_fsprivate2 = (void *)(val)
355 #define XFS_BUF_FSPRIVATE3(bp,type) ((type)(bp)->b_fsprivate3)
356 #define XFS_BUF_SET_FSPRIVATE3(bp,val) (bp)->b_fsprivate3 = (void *)(val)
358 #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \
360 (struct cache_node *)(bp), \
362 #define XFS_BUF_PRIORITY(bp) (cache_node_get_priority( \
363 (struct cache_node *)(bp)))
364 #define xfs_buf_set_ref(bp,ref) ((void) 0)
365 #define xfs_buf_ioerror(bp,err) (bp)->b_error = (err);
367 #define xfs_daddr_to_agno(mp,d) \
368 ((xfs_agnumber_t)(XFS_BB_TO_FSBT(mp, d) / (mp)->m_sb.sb_agblocks))
369 #define xfs_daddr_to_agbno(mp,d) \
370 ((xfs_agblock_t)(XFS_BB_TO_FSBT(mp, d) % (mp)->m_sb.sb_agblocks))
372 /* Buffer Cache Interfaces */
374 extern struct cache
*libxfs_bcache
;
375 extern struct cache_operations libxfs_bcache_operations
;
377 #define LIBXFS_GETBUF_TRYLOCK (1 << 0)
379 #ifdef XFS_BUF_TRACING
381 #define libxfs_readbuf(dev, daddr, len, flags, ops) \
382 libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \
383 (dev), (daddr), (len), (flags), (ops))
384 #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
385 libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \
386 (dev), (map), (nmaps), (flags), (ops))
387 #define libxfs_writebuf(buf, flags) \
388 libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \
390 #define libxfs_getbuf(dev, daddr, len) \
391 libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
392 (dev), (daddr), (len))
393 #define libxfs_getbuf_map(dev, map, nmaps) \
394 libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \
395 (dev), (map), (nmaps))
396 #define libxfs_getbuf_flags(dev, daddr, len, flags) \
397 libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \
398 (dev), (daddr), (len), (flags))
399 #define libxfs_putbuf(buf) \
400 libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
402 extern xfs_buf_t
*libxfs_trace_readbuf(const char *, const char *, int,
403 struct xfs_buftarg
*, xfs_daddr_t
, int, int,
404 const struct xfs_buf_ops
*);
405 extern xfs_buf_t
*libxfs_trace_readbuf_map(const char *, const char *, int,
406 struct xfs_buftarg
*, struct xfs_buf_map
*, int, int,
407 const struct xfs_buf_ops
*);
408 extern int libxfs_trace_writebuf(const char *, const char *, int,
410 extern xfs_buf_t
*libxfs_trace_getbuf(const char *, const char *, int,
411 struct xfs_buftarg
*, xfs_daddr_t
, int);
412 extern xfs_buf_t
*libxfs_trace_getbuf_map(const char *, const char *, int,
413 struct xfs_buftarg
*, struct xfs_buf_map
*, int);
414 extern xfs_buf_t
*libxfs_trace_getbuf_flags(const char *, const char *, int,
415 struct xfs_buftarg
*, xfs_daddr_t
, int, unsigned int);
416 extern void libxfs_trace_putbuf (const char *, const char *, int,
421 extern xfs_buf_t
*libxfs_readbuf(struct xfs_buftarg
*, xfs_daddr_t
, int, int,
422 const struct xfs_buf_ops
*);
423 extern xfs_buf_t
*libxfs_readbuf_map(struct xfs_buftarg
*, struct xfs_buf_map
*,
424 int, int, const struct xfs_buf_ops
*);
425 extern int libxfs_writebuf(xfs_buf_t
*, int);
426 extern xfs_buf_t
*libxfs_getbuf(struct xfs_buftarg
*, xfs_daddr_t
, int);
427 extern xfs_buf_t
*libxfs_getbuf_map(struct xfs_buftarg
*,
428 struct xfs_buf_map
*, int);
429 extern xfs_buf_t
*libxfs_getbuf_flags(struct xfs_buftarg
*, xfs_daddr_t
,
431 extern void libxfs_putbuf (xfs_buf_t
*);
435 extern xfs_buf_t
*libxfs_getsb(xfs_mount_t
*, int);
436 extern void libxfs_bcache_purge(void);
437 extern void libxfs_bcache_flush(void);
438 extern void libxfs_purgebuf(xfs_buf_t
*);
439 extern int libxfs_bcache_overflowed(void);
440 extern int libxfs_bcache_usage(void);
442 /* Buffer (Raw) Interfaces */
443 extern xfs_buf_t
*libxfs_getbufr(struct xfs_buftarg
*, xfs_daddr_t
, int);
444 extern void libxfs_putbufr(xfs_buf_t
*);
446 extern int libxfs_writebuf_int(xfs_buf_t
*, int);
447 extern int libxfs_writebufr(struct xfs_buf
*);
448 extern int libxfs_readbufr(struct xfs_buftarg
*, xfs_daddr_t
, xfs_buf_t
*, int, int);
449 extern int libxfs_readbufr_map(struct xfs_buftarg
*, struct xfs_buf
*,
450 struct xfs_buf_map
*, int, int);
452 extern int libxfs_bhash_size
;
454 #define LIBXFS_BREAD 0x1
455 #define LIBXFS_BWRITE 0x2
456 #define LIBXFS_BZERO 0x4
458 extern void libxfs_iomove (xfs_buf_t
*, uint
, int, void *, int);
461 * Transaction interface
464 typedef struct xfs_log_item
{
465 struct xfs_log_item_desc
*li_desc
; /* ptr to current desc*/
466 struct xfs_mount
*li_mountp
; /* ptr to fs mount */
467 uint li_type
; /* item type */
471 typedef struct xfs_inode_log_item
{
472 xfs_log_item_t ili_item
; /* common portion */
473 struct xfs_inode
*ili_inode
; /* inode pointer */
474 unsigned short ili_flags
; /* misc flags */
475 unsigned int ili_fields
; /* fields to be logged */
476 unsigned int ili_last_fields
; /* fields when flushed*/
477 xfs_inode_log_format_t ili_format
; /* logged structure */
479 } xfs_inode_log_item_t
;
481 typedef struct xfs_buf_log_item
{
482 xfs_log_item_t bli_item
; /* common item structure */
483 struct xfs_buf
*bli_buf
; /* real buffer pointer */
484 unsigned int bli_flags
; /* misc flags */
485 unsigned int bli_recur
; /* recursion count */
486 xfs_buf_log_format_t bli_format
; /* in-log header */
487 } xfs_buf_log_item_t
;
489 #define XFS_BLI_DIRTY (1<<0)
490 #define XFS_BLI_HOLD (1<<1)
491 #define XFS_BLI_STALE (1<<2)
492 #define XFS_BLI_INODE_ALLOC_BUF (1<<3)
494 typedef struct xfs_dq_logitem
{
495 xfs_log_item_t qli_item
; /* common portion */
496 struct xfs_dquot
*qli_dquot
; /* dquot ptr */
497 xfs_lsn_t qli_flush_lsn
; /* lsn at last flush */
498 xfs_dq_logformat_t qli_format
; /* logged structure */
501 typedef struct xfs_qoff_logitem
{
502 xfs_log_item_t qql_item
; /* common portion */
503 struct xfs_qoff_logitem
*qql_start_lip
; /* qoff-start logitem, if any */
504 xfs_qoff_logformat_t qql_format
; /* logged structure */
505 } xfs_qoff_logitem_t
;
507 typedef struct xfs_trans
{
508 unsigned int t_type
; /* transaction type */
509 unsigned int t_log_res
; /* amt of log space resvd */
510 unsigned int t_log_count
; /* count for perm log res */
511 xfs_mount_t
*t_mountp
; /* ptr to fs mount struct */
512 unsigned int t_flags
; /* misc flags */
513 long t_icount_delta
; /* superblock icount change */
514 long t_ifree_delta
; /* superblock ifree change */
515 long t_fdblocks_delta
; /* superblock fdblocks chg */
516 long t_frextents_delta
; /* superblock freextents chg */
517 struct list_head t_items
; /* first log item desc chunk */
520 extern void xfs_trans_init(struct xfs_mount
*);
521 extern int xfs_trans_roll(struct xfs_trans
**, struct xfs_inode
*);
523 extern xfs_trans_t
*libxfs_trans_alloc (xfs_mount_t
*, int);
524 extern xfs_trans_t
*libxfs_trans_dup (xfs_trans_t
*);
525 extern int libxfs_trans_reserve(struct xfs_trans
*, struct xfs_trans_res
*,
527 extern int libxfs_trans_commit (xfs_trans_t
*, uint
);
528 extern void libxfs_trans_cancel (xfs_trans_t
*, int);
529 extern xfs_buf_t
*libxfs_trans_getsb (xfs_trans_t
*, xfs_mount_t
*, int);
531 extern int libxfs_trans_iget (xfs_mount_t
*, xfs_trans_t
*, xfs_ino_t
,
532 uint
, uint
, struct xfs_inode
**);
533 extern void libxfs_trans_iput(xfs_trans_t
*, struct xfs_inode
*, uint
);
534 extern void libxfs_trans_ijoin (xfs_trans_t
*, struct xfs_inode
*, uint
);
535 extern void libxfs_trans_ihold (xfs_trans_t
*, struct xfs_inode
*);
536 extern void libxfs_trans_ijoin_ref(xfs_trans_t
*, struct xfs_inode
*, int);
537 extern void libxfs_trans_log_inode (xfs_trans_t
*, struct xfs_inode
*,
540 extern void libxfs_trans_brelse (xfs_trans_t
*, struct xfs_buf
*);
541 extern void libxfs_trans_binval (xfs_trans_t
*, struct xfs_buf
*);
542 extern void libxfs_trans_bjoin (xfs_trans_t
*, struct xfs_buf
*);
543 extern void libxfs_trans_bhold (xfs_trans_t
*, struct xfs_buf
*);
544 extern void libxfs_trans_log_buf (xfs_trans_t
*, struct xfs_buf
*,
547 extern xfs_buf_t *libxfs_trans_get_buf (xfs_trans_t *, dev_t,
548 xfs_daddr_t, int, uint);
549 extern int libxfs_trans_read_buf (xfs_mount_t *, xfs_trans_t *, dev_t,
550 xfs_daddr_t, int, uint, struct xfs_buf **);
553 struct xfs_buf
*libxfs_trans_get_buf_map(struct xfs_trans
*tp
,
554 struct xfs_buftarg
*btp
,
555 struct xfs_buf_map
*map
, int nmaps
,
558 static inline struct xfs_buf
*
559 libxfs_trans_get_buf(
560 struct xfs_trans
*tp
,
561 struct xfs_buftarg
*btp
,
566 DEFINE_SINGLE_BUF_MAP(map
, blkno
, numblks
);
567 return libxfs_trans_get_buf_map(tp
, btp
, &map
, 1, flags
);
570 int libxfs_trans_read_buf_map(struct xfs_mount
*mp
,
571 struct xfs_trans
*tp
,
572 struct xfs_buftarg
*btp
,
573 struct xfs_buf_map
*map
, int nmaps
,
574 uint flags
, struct xfs_buf
**bpp
,
575 const struct xfs_buf_ops
*ops
);
578 libxfs_trans_read_buf(
579 struct xfs_mount
*mp
,
580 struct xfs_trans
*tp
,
581 struct xfs_buftarg
*btp
,
585 struct xfs_buf
**bpp
,
586 const struct xfs_buf_ops
*ops
)
588 DEFINE_SINGLE_BUF_MAP(map
, blkno
, numblks
);
589 return libxfs_trans_read_buf_map(mp
, tp
, btp
, &map
, 1,
596 typedef struct xfs_inode
{
597 struct cache_node i_node
;
598 xfs_mount_t
*i_mount
; /* fs mount struct ptr */
599 xfs_ino_t i_ino
; /* inode number (agno/agino) */
600 struct xfs_imap i_imap
; /* location for xfs_imap() */
601 struct xfs_buftarg i_dev
; /* dev for this inode */
602 xfs_ifork_t
*i_afp
; /* attribute fork pointer */
603 xfs_ifork_t i_df
; /* data fork */
604 xfs_trans_t
*i_transp
; /* ptr to owning transaction */
605 xfs_inode_log_item_t
*i_itemp
; /* logging information */
606 unsigned int i_delayed_blks
; /* count of delay alloc blks */
607 xfs_icdinode_t i_d
; /* most of ondisk inode */
608 xfs_fsize_t i_size
; /* in-memory size */
611 #define LIBXFS_ATTR_ROOT 0x0002 /* use attrs in root namespace */
612 #define LIBXFS_ATTR_SECURE 0x0008 /* use attrs in security namespace */
613 #define LIBXFS_ATTR_CREATE 0x0010 /* create, but fail if attr exists */
614 #define LIBXFS_ATTR_REPLACE 0x0020 /* set, but fail if attr not exists */
617 * Project quota id helpers (previously projid was 16bit only and using two
618 * 16bit values to hold new 32bit projid was chosen to retain compatibility with
619 * "old" filesystems).
621 * Copied here from xfs_inode.h because it has to be defined after the struct
625 xfs_get_projid(struct xfs_icdinode
*id
)
627 return (prid_t
)id
->di_projid_hi
<< 16 | id
->di_projid_lo
;
631 xfs_set_projid(struct xfs_icdinode
*id
, prid_t projid
)
633 id
->di_projid_hi
= (__uint16_t
) (projid
>> 16);
634 id
->di_projid_lo
= (__uint16_t
) (projid
& 0xffff);
637 typedef struct cred
{
642 extern int libxfs_inode_alloc (xfs_trans_t
**, xfs_inode_t
*, mode_t
,
643 nlink_t
, xfs_dev_t
, struct cred
*,
644 struct fsxattr
*, xfs_inode_t
**);
645 extern void libxfs_trans_inode_alloc_buf (xfs_trans_t
*, xfs_buf_t
*);
647 extern void libxfs_trans_ichgtime(struct xfs_trans
*,
648 struct xfs_inode
*, int);
649 extern int libxfs_iflush_int (xfs_inode_t
*, xfs_buf_t
*);
651 /* Inode Cache Interfaces */
652 extern int libxfs_iget (xfs_mount_t
*, xfs_trans_t
*, xfs_ino_t
,
653 uint
, xfs_inode_t
**, xfs_daddr_t
);
654 extern void libxfs_iput (xfs_inode_t
*, uint
);
656 /* Shared utility routines */
657 extern unsigned int libxfs_log2_roundup(unsigned int i
);
659 extern int libxfs_alloc_file_space (xfs_inode_t
*, xfs_off_t
,
660 xfs_off_t
, int, int);
661 extern int libxfs_bmap_finish(xfs_trans_t
**, xfs_bmap_free_t
*, int *);
663 extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount
*, char *, ...);
664 extern void libxfs_fs_cmn_err(int, struct xfs_mount
*, char *, ...);
666 extern void cmn_err(int, char *, ...);
667 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
670 #define LIBXFS_BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
671 extern int libxfs_nproc(void);
672 extern unsigned long libxfs_physmem(void); /* in kilobytes */
674 #include <xfs/xfs_ialloc.h>
676 #include <xfs/xfs_attr_leaf.h>
677 #include <xfs/xfs_attr_remote.h>
678 #include <xfs/xfs_trans_space.h>
680 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
681 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
684 * public xfs kernel routines to be called as libxfs_*
688 int libxfs_alloc_fix_freelist(xfs_alloc_arg_t
*, int);
691 int libxfs_attr_get(struct xfs_inode
*, const unsigned char *,
692 unsigned char *, int *, int);
693 int libxfs_attr_set(struct xfs_inode
*, const unsigned char *,
694 unsigned char *, int, int);
695 int libxfs_attr_remove(struct xfs_inode
*, const unsigned char *, int);
698 xfs_bmbt_rec_host_t
*xfs_bmap_search_extents(xfs_inode_t
*, xfs_fileoff_t
,
699 int, int *, xfs_extnum_t
*, xfs_bmbt_irec_t
*,
701 void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t
*r
, xfs_bmbt_irec_t
*s
);
703 /* xfs_attr_leaf.h */
704 #define libxfs_attr_leaf_newentsize xfs_attr_leaf_newentsize
707 #define libxfs_highbit32 xfs_highbit32
708 #define libxfs_highbit64 xfs_highbit64
711 #define libxfs_bmap_cancel xfs_bmap_cancel
712 #define libxfs_bmap_last_offset xfs_bmap_last_offset
713 #define libxfs_bmapi_write xfs_bmapi_write
714 #define libxfs_bmapi_read xfs_bmapi_read
715 #define libxfs_bunmapi xfs_bunmapi
717 /* xfs_bmap_btree.h */
718 #define libxfs_bmbt_disk_get_all xfs_bmbt_disk_get_all
721 #define libxfs_da_brelse xfs_da_brelse
722 #define libxfs_da_hashname xfs_da_hashname
723 #define libxfs_da_shrink_inode xfs_da_shrink_inode
724 #define libxfs_da_read_buf xfs_da_read_buf
727 #define libxfs_dir_createname xfs_dir_createname
728 #define libxfs_dir_init xfs_dir_init
729 #define libxfs_dir_lookup xfs_dir_lookup
730 #define libxfs_dir_replace xfs_dir_replace
731 #define libxfs_dir2_isblock xfs_dir2_isblock
732 #define libxfs_dir2_isleaf xfs_dir2_isleaf
734 /* xfs_dir2_data.h */
735 #define libxfs_dir2_data_freescan xfs_dir2_data_freescan
736 #define libxfs_dir2_data_log_entry xfs_dir2_data_log_entry
737 #define libxfs_dir2_data_log_header xfs_dir2_data_log_header
738 #define libxfs_dir2_data_make_free xfs_dir2_data_make_free
739 #define libxfs_dir2_data_use_free xfs_dir2_data_use_free
740 #define libxfs_dir2_shrink_inode xfs_dir2_shrink_inode
743 #define libxfs_dinode_from_disk xfs_dinode_from_disk
744 #define libxfs_dinode_to_disk xfs_dinode_to_disk
745 void xfs_dinode_from_disk(struct xfs_icdinode
*,
746 struct xfs_dinode
*);
747 #define libxfs_dinode_calc_crc xfs_dinode_calc_crc
748 #define libxfs_idata_realloc xfs_idata_realloc
749 #define libxfs_idestroy_fork xfs_idestroy_fork
752 #define libxfs_mod_sb xfs_mod_sb
753 #define libxfs_sb_from_disk xfs_sb_from_disk
754 #define libxfs_sb_to_disk xfs_sb_to_disk
757 #define libxfs_symlink_blocks xfs_symlink_blocks
758 #define libxfs_symlink_hdr_ok xfs_symlink_hdr_ok
760 /* xfs_trans_resv.h */
761 #define libxfs_trans_resv_calc xfs_trans_resv_calc
764 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
768 extern uint32_t crc32_le(uint32_t crc
, unsigned char const *p
, size_t len
);
769 extern uint32_t crc32c_le(uint32_t crc
, unsigned char const *p
, size_t len
);
771 #define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l))
772 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
774 #include <xfs/xfs_cksum.h>
776 #define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args)
777 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
778 #define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
779 #define xfs_hex_dump(d,n) ((void) 0)
781 #endif /* __LIBXFS_H__ */