]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/libxfs.h
xfs_repair: invalidate dirty dir buffers when we zap a directory
[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 #include "libxfs_api_defs.h"
23 #include "platform_defs.h"
24 #include "xfs.h"
25
26 #include "list.h"
27 #include "hlist.h"
28 #include "cache.h"
29 #include "bitops.h"
30 #include "kmem.h"
31 #include "radix-tree.h"
32 #include "atomic.h"
33
34 #include "xfs_types.h"
35 #include "xfs_fs.h"
36 #include "xfs_arch.h"
37
38 #include "xfs_shared.h"
39 #include "xfs_format.h"
40 #include "xfs_log_format.h"
41 #include "xfs_quota_defs.h"
42 #include "xfs_trans_resv.h"
43
44
45 /* CRC stuff, buffer API dependent on it */
46 extern uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len);
47 extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
48
49 #define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l))
50 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
51
52 #include "xfs_cksum.h"
53
54 /*
55 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
56 * every files via a similar include in the kernel xfs_linux.h.
57 */
58 #include "libxfs_io.h"
59
60 #include "xfs_bit.h"
61 #include "xfs_sb.h"
62 #include "xfs_mount.h"
63 #include "xfs_defer.h"
64 #include "xfs_errortag.h"
65 #include "xfs_da_format.h"
66 #include "xfs_da_btree.h"
67 #include "xfs_dir2.h"
68 #include "xfs_bmap_btree.h"
69 #include "xfs_alloc_btree.h"
70 #include "xfs_ialloc_btree.h"
71 #include "xfs_attr_sf.h"
72 #include "xfs_inode_fork.h"
73 #include "xfs_inode_buf.h"
74 #include "xfs_inode.h"
75 #include "xfs_alloc.h"
76 #include "xfs_btree.h"
77 #include "xfs_btree_trace.h"
78 #include "xfs_bmap.h"
79 #include "xfs_trace.h"
80 #include "xfs_trans.h"
81 #include "xfs_rmap_btree.h"
82 #include "xfs_rmap.h"
83 #include "xfs_refcount_btree.h"
84 #include "xfs_refcount.h"
85
86 #ifndef ARRAY_SIZE
87 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
88 #endif
89
90 #ifndef XFS_SUPER_MAGIC
91 #define XFS_SUPER_MAGIC 0x58465342
92 #endif
93
94 #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY))))
95
96 /*
97 * Argument structure for libxfs_init().
98 */
99 typedef struct libxfs_xinit {
100 /* input parameters */
101 char *volname; /* pathname of volume */
102 char *dname; /* pathname of data "subvolume" */
103 char *logname; /* pathname of log "subvolume" */
104 char *rtname; /* pathname of realtime "subvolume" */
105 int isreadonly; /* filesystem is only read in applic */
106 int isdirect; /* we can attempt to use direct I/O */
107 int disfile; /* data "subvolume" is a regular file */
108 int dcreat; /* try to create data subvolume */
109 int lisfile; /* log "subvolume" is a regular file */
110 int lcreat; /* try to create log subvolume */
111 int risfile; /* realtime "subvolume" is a reg file */
112 int rcreat; /* try to create realtime subvolume */
113 int setblksize; /* attempt to set device blksize */
114 int usebuflock; /* lock xfs_buf_t's - for MT usage */
115 /* output results */
116 dev_t ddev; /* device for data subvolume */
117 dev_t logdev; /* device for log subvolume */
118 dev_t rtdev; /* device for realtime subvolume */
119 long long dsize; /* size of data subvolume (BBs) */
120 long long logBBsize; /* size of log subvolume (BBs) */
121 /* (blocks allocated for use as
122 * log is stored in mount structure) */
123 long long logBBstart; /* start block of log subvolume (BBs) */
124 long long rtsize; /* size of realtime subvolume (BBs) */
125 int dbsize; /* data subvolume device blksize */
126 int lbsize; /* log subvolume device blksize */
127 int rtbsize; /* realtime subvolume device blksize */
128 int dfd; /* data subvolume file descriptor */
129 int logfd; /* log subvolume file descriptor */
130 int rtfd; /* realtime subvolume file descriptor */
131 int icache_flags; /* cache init flags */
132 int bcache_flags; /* cache init flags */
133 } libxfs_init_t;
134
135 #define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */
136 #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
137 #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
138 #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
139 #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
140 #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
141
142 extern char *progname;
143 extern xfs_lsn_t libxfs_max_lsn;
144 extern int libxfs_init (libxfs_init_t *);
145 extern void libxfs_destroy (void);
146 extern int libxfs_device_to_fd (dev_t);
147 extern dev_t libxfs_device_open (char *, int, int, int);
148 extern void libxfs_device_close (dev_t);
149 extern int libxfs_device_alignment (void);
150 extern void libxfs_report(FILE *);
151 extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz);
152 extern int platform_nproc(void);
153
154 /* check or write log footer: specify device, log size in blocks & uuid */
155 typedef char *(libxfs_get_block_t)(char *, int, void *);
156
157 /*
158 * Helpers to clear the log to a particular log cycle.
159 */
160 #define XLOG_INIT_CYCLE 1
161 extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t,
162 uint, uuid_t *, int, int, int, int, bool);
163 extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t,
164 xfs_lsn_t, libxfs_get_block_t *, void *);
165
166
167 /* Shared utility routines */
168
169 extern int libxfs_alloc_file_space (struct xfs_inode *, xfs_off_t,
170 xfs_off_t, int, int);
171
172 extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount *, char *, ...);
173 extern void libxfs_fs_cmn_err(int, struct xfs_mount *, char *, ...);
174
175 /* XXX: this is messy and needs fixing */
176 #ifndef __LIBXFS_INTERNAL_XFS_H__
177 extern void cmn_err(int, char *, ...);
178 enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
179 #endif
180
181
182 extern int libxfs_nproc(void);
183 extern unsigned long libxfs_physmem(void); /* in kilobytes */
184
185 #include "xfs_ialloc.h"
186
187 #include "xfs_attr_leaf.h"
188 #include "xfs_attr_remote.h"
189 #include "xfs_trans_space.h"
190
191 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
192 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
193
194 static inline bool
195 xfs_inobt_is_sparse_disk(
196 struct xfs_inobt_rec *rp,
197 int offset)
198 {
199 int spshift;
200 uint16_t holemask;
201
202 holemask = be16_to_cpu(rp->ir_u.sp.ir_holemask);
203 spshift = offset / XFS_INODES_PER_HOLEMASK_BIT;
204 if ((1 << spshift) & holemask)
205 return true;
206
207 return false;
208 }
209
210 static inline void
211 libxfs_bmbt_disk_get_all(
212 struct xfs_bmbt_rec *rec,
213 struct xfs_bmbt_irec *irec)
214 {
215 uint64_t l0 = get_unaligned_be64(&rec->l0);
216 uint64_t l1 = get_unaligned_be64(&rec->l1);
217
218 irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
219 irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21);
220 irec->br_blockcount = l1 & xfs_mask64lo(21);
221 if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN))
222 irec->br_state = XFS_EXT_UNWRITTEN;
223 else
224 irec->br_state = XFS_EXT_NORM;
225 }
226
227 /* XXX: this is clearly a bug - a shared header needs to export this */
228 /* xfs_rtalloc.c */
229 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
230 bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
231
232 /* XXX: need parts of xfs_attr.h in userspace */
233 #define LIBXFS_ATTR_ROOT 0x0002 /* use attrs in root namespace */
234 #define LIBXFS_ATTR_SECURE 0x0008 /* use attrs in security namespace */
235 #define LIBXFS_ATTR_CREATE 0x0010 /* create, but fail if attr exists */
236 #define LIBXFS_ATTR_REPLACE 0x0020 /* set, but fail if attr not exists */
237
238 int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
239 int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
240 unsigned char *value, int valuelen, int flags);
241
242 #endif /* __LIBXFS_H__ */