]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/libxfs.h
xfs: introduce BMAPI_ZERO for allocating zeroed extents
[thirdparty/xfsprogs-dev.git] / include / libxfs.h
CommitLineData
2bd0ea18 1/*
f302e9e4
NS
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
2bd0ea18 4 *
f302e9e4
NS
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
2bd0ea18
NS
7 * published by the Free Software Foundation.
8 *
f302e9e4
NS
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.
2bd0ea18 13 *
f302e9e4
NS
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
2bd0ea18 17 */
5e656dbb 18
2bd0ea18
NS
19#ifndef __LIBXFS_H__
20#define __LIBXFS_H__
21
6b803e5a
CH
22#include "libxfs_api_defs.h"
23#include "platform_defs.h"
dcabd4e7 24#include "xfs.h"
2bd0ea18 25
6b803e5a
CH
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"
f1b058f9 33
6b803e5a
CH
34#include "xfs_types.h"
35#include "xfs_fs.h"
36#include "xfs_arch.h"
2d4bfb91 37
6b803e5a
CH
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"
2d4bfb91 43
b626fb59
DC
44
45/* CRC stuff, buffer API dependent on it */
46extern uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len);
47extern 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
6b803e5a 52#include "xfs_cksum.h"
b626fb59
DC
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 */
6b803e5a
CH
58#include "libxfs_io.h"
59
60#include "xfs_bit.h"
61#include "xfs_sb.h"
62#include "xfs_mount.h"
63#include "xfs_da_format.h"
64#include "xfs_da_btree.h"
65#include "xfs_dir2.h"
66#include "xfs_bmap_btree.h"
67#include "xfs_alloc_btree.h"
68#include "xfs_ialloc_btree.h"
69#include "xfs_attr_sf.h"
70#include "xfs_inode_fork.h"
71#include "xfs_inode_buf.h"
72#include "xfs_inode.h"
73#include "xfs_alloc.h"
74#include "xfs_btree.h"
75#include "xfs_btree_trace.h"
76#include "xfs_bmap.h"
77#include "xfs_trace.h"
78#include "xfs_trans.h"
cc085d77 79
1167ddc4
AE
80#ifndef ARRAY_SIZE
81#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
82#endif
2bd0ea18 83
b391b7cd
NS
84#ifndef XFS_SUPER_MAGIC
85#define XFS_SUPER_MAGIC 0x58465342
86#endif
87
a580302f
ES
88#define xfs_isset(a,i) ((a)[(i)/(sizeof((a))*NBBY)] & (1<<((i)%(sizeof((a))*NBBY))))
89
2bd0ea18
NS
90/*
91 * Argument structure for libxfs_init().
92 */
93typedef struct {
dfc130f3
RC
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 */
b74a1f6a 100 int isdirect; /* we can attempt to use direct I/O */
d0572de5
BN
101 int disfile; /* data "subvolume" is a regular file */
102 int dcreat; /* try to create data subvolume */
dfc130f3
RC
103 int lisfile; /* log "subvolume" is a regular file */
104 int lcreat; /* try to create log subvolume */
d0572de5
BN
105 int risfile; /* realtime "subvolume" is a reg file */
106 int rcreat; /* try to create realtime subvolume */
74668075 107 int setblksize; /* attempt to set device blksize */
d0572de5 108 int usebuflock; /* lock xfs_buf_t's - for MT usage */
dfc130f3
RC
109 /* output results */
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) */
74668075
NS
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 */
dfc130f3
RC
122 int dfd; /* data subvolume file descriptor */
123 int logfd; /* log subvolume file descriptor */
124 int rtfd; /* realtime subvolume file descriptor */
ba9ecd40
DC
125 int icache_flags; /* cache init flags */
126 int bcache_flags; /* cache init flags */
2bd0ea18
NS
127} libxfs_init_t;
128
9440d84d
NS
129#define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */
130#define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */
131#define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */
7eb6693f
NS
132#define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
133#define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
b74a1f6a 134#define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
2bd0ea18
NS
135
136extern char *progname;
7d77349c 137extern xfs_lsn_t libxfs_max_lsn;
2bd0ea18 138extern int libxfs_init (libxfs_init_t *);
f1b058f9 139extern void libxfs_destroy (void);
2bd0ea18 140extern int libxfs_device_to_fd (dev_t);
c5907b96 141extern dev_t libxfs_device_open (char *, int, int, int);
2bd0ea18 142extern void libxfs_device_close (dev_t);
b74a1f6a 143extern int libxfs_device_alignment (void);
b6281496 144extern void libxfs_report(FILE *);
fd5eda53 145extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz);
12b55baf 146extern int platform_nproc(void);
2bd0ea18
NS
147
148/* check or write log footer: specify device, log size in blocks & uuid */
d60ba955 149typedef char *(libxfs_get_block_t)(char *, int, void *);
989b74bc 150
0c12ba5f
BF
151/*
152 * Helpers to clear the log to a particular log cycle.
153 */
154#define XLOG_INIT_CYCLE 1
1c12a814 155extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t,
571a78a7 156 uint, uuid_t *, int, int, int, int, bool);
0c12ba5f
BF
157extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t,
158 xfs_lsn_t, libxfs_get_block_t *, void *);
989b74bc 159
75c8b434 160
5e656dbb
BN
161/* Shared utility routines */
162extern unsigned int libxfs_log2_roundup(unsigned int i);
2bd0ea18 163
b626fb59 164extern int libxfs_alloc_file_space (struct xfs_inode *, xfs_off_t,
2bd0ea18 165 xfs_off_t, int, int);
5e656dbb 166extern int libxfs_bmap_finish(xfs_trans_t **, xfs_bmap_free_t *, int *);
2bd0ea18 167
5e656dbb
BN
168extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount *, char *, ...);
169extern void libxfs_fs_cmn_err(int, struct xfs_mount *, char *, ...);
2bd0ea18 170
b626fb59
DC
171/* XXX: this is messy and needs fixing */
172#ifndef __LIBXFS_INTERNAL_XFS_H__
1552a820
NS
173extern void cmn_err(int, char *, ...);
174enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
b626fb59 175#endif
f302e9e4 176
cb5b3ef4 177
2556c98b
BN
178extern int libxfs_nproc(void);
179extern unsigned long libxfs_physmem(void); /* in kilobytes */
cb5b3ef4 180
6b803e5a 181#include "xfs_ialloc.h"
f302e9e4 182
6b803e5a
CH
183#include "xfs_attr_leaf.h"
184#include "xfs_attr_remote.h"
185#include "xfs_trans_space.h"
f302e9e4 186
5e656dbb
BN
187#define XFS_INOBT_IS_FREE_DISK(rp,i) \
188 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
56b2de80 189
c749bd55
BF
190static inline bool
191xfs_inobt_is_sparse_disk(
192 struct xfs_inobt_rec *rp,
193 int offset)
194{
195 int spshift;
196 uint16_t holemask;
197
198 holemask = be16_to_cpu(rp->ir_u.sp.ir_holemask);
199 spshift = offset / XFS_INODES_PER_HOLEMASK_BIT;
200 if ((1 << spshift) & holemask)
201 return true;
202
203 return false;
204}
205
ff105f75
DC
206static inline void
207libxfs_bmbt_disk_get_all(
208 struct xfs_bmbt_rec *rp,
209 struct xfs_bmbt_irec *irec)
210{
211 struct xfs_bmbt_rec_host hrec;
212
fb36a55d
ES
213 hrec.l0 = get_unaligned_be64(&rp->l0);
214 hrec.l1 = get_unaligned_be64(&rp->l1);
ff105f75
DC
215 libxfs_bmbt_get_all(&hrec, irec);
216}
5e656dbb 217
f616e2bf 218/* XXX: this is clearly a bug - a shared header needs to export this */
5e656dbb
BN
219/* xfs_rtalloc.c */
220int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
221
e515cca1
DC
222/* XXX: need parts of xfs_attr.h in userspace */
223#define LIBXFS_ATTR_ROOT 0x0002 /* use attrs in root namespace */
224#define LIBXFS_ATTR_SECURE 0x0008 /* use attrs in security namespace */
225#define LIBXFS_ATTR_CREATE 0x0010 /* create, but fail if attr exists */
226#define LIBXFS_ATTR_REPLACE 0x0020 /* set, but fail if attr not exists */
227
228int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
229int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
230 unsigned char *value, int valuelen, int flags);
231
2bd0ea18 232#endif /* __LIBXFS_H__ */