1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
10 #include "libxfs_api_defs.h"
11 #include "platform_defs.h"
19 #include "libfrog/radix-tree.h"
22 #include "xfs_types.h"
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"
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))
37 /* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */
39 #include "xfs_cksum.h"
41 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
42 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
43 #define unlikely(x) (x)
44 #define timespec64 timespec
47 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
48 * every files via a similar include in the kernel xfs_linux.h.
50 #include "libxfs_io.h"
54 #include "xfs_mount.h"
55 #include "xfs_defer.h"
56 #include "xfs_errortag.h"
57 #include "xfs_da_format.h"
58 #include "xfs_da_btree.h"
59 #include "xfs_inode.h"
61 #include "xfs_dir2_priv.h"
62 #include "xfs_bmap_btree.h"
63 #include "xfs_alloc_btree.h"
64 #include "xfs_ialloc_btree.h"
65 #include "xfs_attr_sf.h"
66 #include "xfs_inode_fork.h"
67 #include "xfs_inode_buf.h"
68 #include "xfs_alloc.h"
69 #include "xfs_btree.h"
70 #include "xfs_btree_trace.h"
72 #include "xfs_trace.h"
73 #include "xfs_trans.h"
75 #include "xfs_rmap_btree.h"
77 #include "xfs_refcount_btree.h"
78 #include "xfs_refcount.h"
81 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
84 #ifndef XFS_SUPER_MAGIC
85 #define XFS_SUPER_MAGIC 0x58465342
88 #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY))))
91 * Argument structure for libxfs_init().
93 typedef struct libxfs_xinit
{
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 */
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 */
129 #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
130 #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
131 #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
132 #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
133 #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
135 extern char *progname
;
136 extern xfs_lsn_t libxfs_max_lsn
;
137 extern int libxfs_init (libxfs_init_t
*);
138 void libxfs_destroy(struct libxfs_xinit
*li
);
139 extern int libxfs_device_to_fd (dev_t
);
140 extern dev_t
libxfs_device_open (char *, int, int, int);
141 extern void libxfs_device_close (dev_t
);
142 extern int libxfs_device_alignment (void);
143 extern void libxfs_report(FILE *);
145 /* check or write log footer: specify device, log size in blocks & uuid */
146 typedef char *(libxfs_get_block_t
)(char *, int, void *);
149 * Helpers to clear the log to a particular log cycle.
151 #define XLOG_INIT_CYCLE 1
152 extern int libxfs_log_clear(struct xfs_buftarg
*, char *, xfs_daddr_t
,
153 uint
, uuid_t
*, int, int, int, int, bool);
154 extern int libxfs_log_header(char *, uuid_t
*, int, int, int, xfs_lsn_t
,
155 xfs_lsn_t
, libxfs_get_block_t
*, void *);
158 /* Shared utility routines */
160 extern int libxfs_alloc_file_space (struct xfs_inode
*, xfs_off_t
,
161 xfs_off_t
, int, int);
163 /* XXX: this is messy and needs fixing */
164 #ifndef __LIBXFS_INTERNAL_XFS_H__
165 extern void cmn_err(int, char *, ...);
166 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
169 #include "xfs_ialloc.h"
171 #include "xfs_attr_leaf.h"
172 #include "xfs_attr_remote.h"
173 #include "xfs_trans_space.h"
175 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
176 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
179 xfs_inobt_is_sparse_disk(
180 struct xfs_inobt_rec
*rp
,
186 holemask
= be16_to_cpu(rp
->ir_u
.sp
.ir_holemask
);
187 spshift
= offset
/ XFS_INODES_PER_HOLEMASK_BIT
;
188 if ((1 << spshift
) & holemask
)
195 libxfs_bmbt_disk_get_all(
196 struct xfs_bmbt_rec
*rec
,
197 struct xfs_bmbt_irec
*irec
)
199 uint64_t l0
= get_unaligned_be64(&rec
->l0
);
200 uint64_t l1
= get_unaligned_be64(&rec
->l1
);
202 irec
->br_startoff
= (l0
& xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN
)) >> 9;
203 irec
->br_startblock
= ((l0
& xfs_mask64lo(9)) << 43) | (l1
>> 21);
204 irec
->br_blockcount
= l1
& xfs_mask64lo(21);
205 if (l0
>> (64 - BMBT_EXNTFLAG_BITLEN
))
206 irec
->br_state
= XFS_EXT_UNWRITTEN
;
208 irec
->br_state
= XFS_EXT_NORM
;
211 /* XXX: this is clearly a bug - a shared header needs to export this */
213 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
214 bool libxfs_verify_rtbno(struct xfs_mount
*mp
, xfs_rtblock_t rtbno
);
216 #include "xfs_attr.h"
218 #endif /* __LIBXFS_H__ */