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>
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>
62 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
65 #ifndef XFS_SUPER_MAGIC
66 #define XFS_SUPER_MAGIC 0x58465342
69 #define xfs_isset(a,i) ((a)[(i)/(sizeof((a))*NBBY)] & (1<<((i)%(sizeof((a))*NBBY))))
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))
77 * Argument structure for libxfs_init().
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 */
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 */
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 */
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
126 struct xfs_mount
*bt_mount
;
130 extern void libxfs_buftarg_init(struct xfs_mount
*mp
, dev_t ddev
,
131 dev_t logdev
, dev_t rtdev
);
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
);
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 *);
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 *);
154 * Define a user-level mount structure with all we need
155 * in order to make use of the numerous XFS_* macros.
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 */
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
227 #define LIBXFS_IHASHSIZE(sbp) (1<<10)
228 #define LIBXFS_BHASHSIZE(sbp) (1<<10)
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
*);
237 * Simple I/O interface
242 xfs_daddr_t bm_bn
; /* block number for I/O */
243 int bm_len
; /* size of I/O */
246 #define DEFINE_SINGLE_BUF_MAP(map, blkno, numblk) \
247 struct xfs_buf_map (map) = { .bm_bn = (blkno), .bm_len = (numblk) };
250 void (*verify_read
)(struct xfs_buf
*);
251 void (*verify_write
)(struct xfs_buf
*);
254 typedef struct xfs_buf
{
255 struct cache_node b_node
;
256 unsigned int b_flags
;
259 unsigned int b_length
;
260 struct xfs_buftarg
*b_target
;
261 #define b_dev b_target->dev
262 pthread_mutex_t b_lock
;
264 unsigned int b_recur
;
270 const struct xfs_buf_ops
*b_ops
;
271 struct xfs_perag
*b_pag
;
272 struct xfs_buf_map
*b_map
;
274 #ifdef XFS_BUF_TRACING
275 struct list_head b_lock_list
;
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 */
290 #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))
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); \
303 #define XFS_BUF_SET_ADDR(bp,blk) ((bp)->b_bn = (blk))
304 #define XFS_BUF_SET_COUNT(bp,cnt) ((bp)->b_bcount = (cnt))
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)
313 #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \
315 (struct cache_node *)(bp), \
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);
322 /* Buffer Cache Interfaces */
324 extern struct cache
*libxfs_bcache
;
325 extern struct cache_operations libxfs_bcache_operations
;
327 #define LIBXFS_GETBUF_TRYLOCK (1 << 0)
329 #ifdef XFS_BUF_TRACING
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__, \
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))
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,
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,
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
,
381 extern void libxfs_putbuf (xfs_buf_t
*);
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);
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
*);
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);
399 extern int libxfs_bhash_size
;
400 extern int libxfs_ihash_size
;
402 #define LIBXFS_BREAD 0x1
403 #define LIBXFS_BWRITE 0x2
404 #define LIBXFS_BZERO 0x4
406 extern void libxfs_iomove (xfs_buf_t
*, uint
, int, void *, int);
410 * Transaction interface
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 */
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 */
428 } xfs_inode_log_item_t
;
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
;
438 #include <xfs/xfs_trans.h>
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 */
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);
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
*,
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
*,
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 **);
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
,
488 static inline struct xfs_buf
*
489 libxfs_trans_get_buf(
490 struct xfs_trans
*tp
,
491 struct xfs_buftarg
*btp
,
496 DEFINE_SINGLE_BUF_MAP(map
, blkno
, numblks
);
497 return libxfs_trans_get_buf_map(tp
, btp
, &map
, 1, flags
);
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
);
508 libxfs_trans_read_buf(
509 struct xfs_mount
*mp
,
510 struct xfs_trans
*tp
,
511 struct xfs_buftarg
*btp
,
515 struct xfs_buf
**bpp
,
516 const struct xfs_buf_ops
*ops
)
518 DEFINE_SINGLE_BUF_MAP(map
, blkno
, numblks
);
519 return libxfs_trans_read_buf_map(mp
, tp
, btp
, &map
, 1,
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 */
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 */
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).
551 * Copied here from xfs_inode.h because it has to be defined after the struct
555 xfs_get_projid(struct xfs_icdinode
*id
)
557 return (prid_t
)id
->di_projid_hi
<< 16 | id
->di_projid_lo
;
561 xfs_set_projid(struct xfs_icdinode
*id
, prid_t projid
)
563 id
->di_projid_hi
= (__uint16_t
) (projid
>> 16);
564 id
->di_projid_lo
= (__uint16_t
) (projid
& 0xffff);
567 typedef struct cred
{
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
*);
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
*);
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
);
589 #include <xfs/xfs_dir2_format.h>
591 /* Shared utility routines */
592 extern unsigned int libxfs_log2_roundup(unsigned int i
);
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 *);
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 *, ...);
601 extern void cmn_err(int, char *, ...);
602 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
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 */
609 #include <xfs/xfs_ialloc.h>
610 #include <xfs/xfs_rtalloc.h>
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>
619 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
620 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
623 * public xfs kernel routines to be called as libxfs_*
627 int libxfs_alloc_fix_freelist(xfs_alloc_arg_t
*, int);
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);
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
*,
640 void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t
*r
, xfs_bmbt_irec_t
*s
);
642 /* xfs_attr_leaf.h */
643 #define libxfs_attr_leaf_newentsize xfs_attr_leaf_newentsize
646 #define libxfs_highbit32 xfs_highbit32
647 #define libxfs_highbit64 xfs_highbit64
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
656 /* xfs_bmap_btree.h */
657 #define libxfs_bmbt_disk_get_all xfs_bmbt_disk_get_all
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
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
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
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
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
696 #define libxfs_symlink_blocks xfs_symlink_blocks
697 #define libxfs_symlink_hdr_ok xfs_symlink_hdr_ok
700 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
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
);
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))
710 #include <xfs/xfs_cksum.h>
712 #endif /* __LIBXFS_H__ */