]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/libxfs.h
xfs: move growfs core to libxfs
[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"
f944d3d0 63#include "xfs_defer.h"
904d9719 64#include "xfs_errortag.h"
6b803e5a
CH
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"
631ac87a 81#include "xfs_rmap_btree.h"
794a5604 82#include "xfs_rmap.h"
e7be6330 83#include "xfs_refcount_btree.h"
db17bb0e 84#include "xfs_refcount.h"
cc085d77 85
1167ddc4
AE
86#ifndef ARRAY_SIZE
87#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
88#endif
2bd0ea18 89
b391b7cd
NS
90#ifndef XFS_SUPER_MAGIC
91#define XFS_SUPER_MAGIC 0x58465342
92#endif
93
de2f203d 94#define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY))))
a580302f 95
2bd0ea18
NS
96/*
97 * Argument structure for libxfs_init().
98 */
cf627f3c 99typedef struct libxfs_xinit {
dfc130f3
RC
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 */
b74a1f6a 106 int isdirect; /* we can attempt to use direct I/O */
d0572de5
BN
107 int disfile; /* data "subvolume" is a regular file */
108 int dcreat; /* try to create data subvolume */
dfc130f3
RC
109 int lisfile; /* log "subvolume" is a regular file */
110 int lcreat; /* try to create log subvolume */
d0572de5
BN
111 int risfile; /* realtime "subvolume" is a reg file */
112 int rcreat; /* try to create realtime subvolume */
74668075 113 int setblksize; /* attempt to set device blksize */
d0572de5 114 int usebuflock; /* lock xfs_buf_t's - for MT usage */
dfc130f3
RC
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) */
74668075
NS
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 */
dfc130f3
RC
128 int dfd; /* data subvolume file descriptor */
129 int logfd; /* log subvolume file descriptor */
130 int rtfd; /* realtime subvolume file descriptor */
ba9ecd40
DC
131 int icache_flags; /* cache init flags */
132 int bcache_flags; /* cache init flags */
2bd0ea18
NS
133} libxfs_init_t;
134
9440d84d
NS
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 */
7eb6693f
NS
138#define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */
139#define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */
b74a1f6a 140#define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */
2bd0ea18
NS
141
142extern char *progname;
7d77349c 143extern xfs_lsn_t libxfs_max_lsn;
2bd0ea18 144extern int libxfs_init (libxfs_init_t *);
f1b058f9 145extern void libxfs_destroy (void);
2bd0ea18 146extern int libxfs_device_to_fd (dev_t);
c5907b96 147extern dev_t libxfs_device_open (char *, int, int, int);
2bd0ea18 148extern void libxfs_device_close (dev_t);
b74a1f6a 149extern int libxfs_device_alignment (void);
b6281496 150extern void libxfs_report(FILE *);
fd5eda53 151extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz);
12b55baf 152extern int platform_nproc(void);
2bd0ea18
NS
153
154/* check or write log footer: specify device, log size in blocks & uuid */
d60ba955 155typedef char *(libxfs_get_block_t)(char *, int, void *);
989b74bc 156
0c12ba5f
BF
157/*
158 * Helpers to clear the log to a particular log cycle.
159 */
160#define XLOG_INIT_CYCLE 1
1c12a814 161extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t,
571a78a7 162 uint, uuid_t *, int, int, int, int, bool);
0c12ba5f
BF
163extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t,
164 xfs_lsn_t, libxfs_get_block_t *, void *);
989b74bc 165
75c8b434 166
5e656dbb 167/* Shared utility routines */
2bd0ea18 168
b626fb59 169extern int libxfs_alloc_file_space (struct xfs_inode *, xfs_off_t,
2bd0ea18
NS
170 xfs_off_t, int, int);
171
6f530e9a 172extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount *, char *, ...);
5e656dbb 173extern void libxfs_fs_cmn_err(int, struct xfs_mount *, char *, ...);
2bd0ea18 174
b626fb59
DC
175/* XXX: this is messy and needs fixing */
176#ifndef __LIBXFS_INTERNAL_XFS_H__
1552a820
NS
177extern void cmn_err(int, char *, ...);
178enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
b626fb59 179#endif
f302e9e4 180
cb5b3ef4 181
2556c98b
BN
182extern int libxfs_nproc(void);
183extern unsigned long libxfs_physmem(void); /* in kilobytes */
cb5b3ef4 184
6b803e5a 185#include "xfs_ialloc.h"
f302e9e4 186
6b803e5a
CH
187#include "xfs_attr_leaf.h"
188#include "xfs_attr_remote.h"
189#include "xfs_trans_space.h"
f302e9e4 190
5e656dbb
BN
191#define XFS_INOBT_IS_FREE_DISK(rp,i) \
192 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
56b2de80 193
c749bd55
BF
194static inline bool
195xfs_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
ff105f75
DC
210static inline void
211libxfs_bmbt_disk_get_all(
b37d753d 212 struct xfs_bmbt_rec *rec,
ff105f75
DC
213 struct xfs_bmbt_irec *irec)
214{
b37d753d
CH
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;
ff105f75 225}
5e656dbb 226
f616e2bf 227/* XXX: this is clearly a bug - a shared header needs to export this */
5e656dbb
BN
228/* xfs_rtalloc.c */
229int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
0cf6a3a9 230bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
5e656dbb 231
e515cca1
DC
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
238int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
239int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
240 unsigned char *value, int valuelen, int flags);
241
2bd0ea18 242#endif /* __LIBXFS_H__ */