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 "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 #include "xfs_cksum.h"
40 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
41 * every files via a similar include in the kernel xfs_linux.h.
43 #include "libxfs_io.h"
47 #include "xfs_mount.h"
48 #include "xfs_defer.h"
49 #include "xfs_errortag.h"
50 #include "xfs_da_format.h"
51 #include "xfs_da_btree.h"
53 #include "xfs_bmap_btree.h"
54 #include "xfs_alloc_btree.h"
55 #include "xfs_ialloc_btree.h"
56 #include "xfs_attr_sf.h"
57 #include "xfs_inode_fork.h"
58 #include "xfs_inode_buf.h"
59 #include "xfs_inode.h"
60 #include "xfs_alloc.h"
61 #include "xfs_btree.h"
62 #include "xfs_btree_trace.h"
64 #include "xfs_trace.h"
65 #include "xfs_trans.h"
66 #include "xfs_rmap_btree.h"
68 #include "xfs_refcount_btree.h"
69 #include "xfs_refcount.h"
72 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
75 #ifndef XFS_SUPER_MAGIC
76 #define XFS_SUPER_MAGIC 0x58465342
79 #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY))))
82 * Argument structure for libxfs_init().
84 typedef struct libxfs_xinit
{
85 /* input parameters */
86 char *volname
; /* pathname of volume */
87 char *dname
; /* pathname of data "subvolume" */
88 char *logname
; /* pathname of log "subvolume" */
89 char *rtname
; /* pathname of realtime "subvolume" */
90 int isreadonly
; /* filesystem is only read in applic */
91 int isdirect
; /* we can attempt to use direct I/O */
92 int disfile
; /* data "subvolume" is a regular file */
93 int dcreat
; /* try to create data subvolume */
94 int lisfile
; /* log "subvolume" is a regular file */
95 int lcreat
; /* try to create log subvolume */
96 int risfile
; /* realtime "subvolume" is a reg file */
97 int rcreat
; /* try to create realtime subvolume */
98 int setblksize
; /* attempt to set device blksize */
99 int usebuflock
; /* lock xfs_buf_t's - for MT usage */
101 dev_t ddev
; /* device for data subvolume */
102 dev_t logdev
; /* device for log subvolume */
103 dev_t rtdev
; /* device for realtime subvolume */
104 long long dsize
; /* size of data subvolume (BBs) */
105 long long logBBsize
; /* size of log subvolume (BBs) */
106 /* (blocks allocated for use as
107 * log is stored in mount structure) */
108 long long logBBstart
; /* start block of log subvolume (BBs) */
109 long long rtsize
; /* size of realtime subvolume (BBs) */
110 int dbsize
; /* data subvolume device blksize */
111 int lbsize
; /* log subvolume device blksize */
112 int rtbsize
; /* realtime subvolume device blksize */
113 int dfd
; /* data subvolume file descriptor */
114 int logfd
; /* log subvolume file descriptor */
115 int rtfd
; /* realtime subvolume file descriptor */
116 int icache_flags
; /* cache init flags */
117 int bcache_flags
; /* cache init flags */
120 #define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */
121 #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
122 #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
123 #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
124 #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
125 #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
127 extern char *progname
;
128 extern xfs_lsn_t libxfs_max_lsn
;
129 extern int libxfs_init (libxfs_init_t
*);
130 extern void libxfs_destroy (void);
131 extern int libxfs_device_to_fd (dev_t
);
132 extern dev_t
libxfs_device_open (char *, int, int, int);
133 extern void libxfs_device_close (dev_t
);
134 extern int libxfs_device_alignment (void);
135 extern void libxfs_report(FILE *);
136 extern void platform_findsizes(char *path
, int fd
, long long *sz
, int *bsz
);
137 extern int platform_nproc(void);
139 /* check or write log footer: specify device, log size in blocks & uuid */
140 typedef char *(libxfs_get_block_t
)(char *, int, void *);
143 * Helpers to clear the log to a particular log cycle.
145 #define XLOG_INIT_CYCLE 1
146 extern int libxfs_log_clear(struct xfs_buftarg
*, char *, xfs_daddr_t
,
147 uint
, uuid_t
*, int, int, int, int, bool);
148 extern int libxfs_log_header(char *, uuid_t
*, int, int, int, xfs_lsn_t
,
149 xfs_lsn_t
, libxfs_get_block_t
*, void *);
152 /* Shared utility routines */
154 extern int libxfs_alloc_file_space (struct xfs_inode
*, xfs_off_t
,
155 xfs_off_t
, int, int);
157 extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount
*, char *, ...);
158 extern void libxfs_fs_cmn_err(int, struct xfs_mount
*, char *, ...);
160 /* XXX: this is messy and needs fixing */
161 #ifndef __LIBXFS_INTERNAL_XFS_H__
162 extern void cmn_err(int, char *, ...);
163 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
167 extern int libxfs_nproc(void);
168 extern unsigned long libxfs_physmem(void); /* in kilobytes */
170 #include "xfs_ialloc.h"
172 #include "xfs_attr_leaf.h"
173 #include "xfs_attr_remote.h"
174 #include "xfs_trans_space.h"
176 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
177 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
180 xfs_inobt_is_sparse_disk(
181 struct xfs_inobt_rec
*rp
,
187 holemask
= be16_to_cpu(rp
->ir_u
.sp
.ir_holemask
);
188 spshift
= offset
/ XFS_INODES_PER_HOLEMASK_BIT
;
189 if ((1 << spshift
) & holemask
)
196 libxfs_bmbt_disk_get_all(
197 struct xfs_bmbt_rec
*rec
,
198 struct xfs_bmbt_irec
*irec
)
200 uint64_t l0
= get_unaligned_be64(&rec
->l0
);
201 uint64_t l1
= get_unaligned_be64(&rec
->l1
);
203 irec
->br_startoff
= (l0
& xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN
)) >> 9;
204 irec
->br_startblock
= ((l0
& xfs_mask64lo(9)) << 43) | (l1
>> 21);
205 irec
->br_blockcount
= l1
& xfs_mask64lo(21);
206 if (l0
>> (64 - BMBT_EXNTFLAG_BITLEN
))
207 irec
->br_state
= XFS_EXT_UNWRITTEN
;
209 irec
->br_state
= XFS_EXT_NORM
;
212 /* XXX: this is clearly a bug - a shared header needs to export this */
214 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
215 bool libxfs_verify_rtbno(struct xfs_mount
*mp
, xfs_rtblock_t rtbno
);
217 /* XXX: need parts of xfs_attr.h in userspace */
218 #define LIBXFS_ATTR_ROOT 0x0002 /* use attrs in root namespace */
219 #define LIBXFS_ATTR_SECURE 0x0008 /* use attrs in security namespace */
220 #define LIBXFS_ATTR_CREATE 0x0010 /* create, but fail if attr exists */
221 #define LIBXFS_ATTR_REPLACE 0x0020 /* set, but fail if attr not exists */
223 int xfs_attr_remove(struct xfs_inode
*dp
, const unsigned char *name
, int flags
);
224 int xfs_attr_set(struct xfs_inode
*dp
, const unsigned char *name
,
225 unsigned char *value
, int valuelen
, int flags
);
227 #endif /* __LIBXFS_H__ */