]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/linux.h
xfs_scrub: initialize movon in xfs_scrub_connections
[thirdparty/xfsprogs-dev.git] / include / linux.h
CommitLineData
c0211f67 1/*
f302e9e4 2 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
c0211f67 3 *
f302e9e4
NS
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation.
c0211f67 7 *
f302e9e4
NS
8 * This program is distributed in the hope that it would be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
c0211f67 12 *
f302e9e4
NS
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write the Free Software Foundation,
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
c0211f67
NS
16 */
17#ifndef __XFS_LINUX_H__
18#define __XFS_LINUX_H__
19
20#include <uuid/uuid.h>
21#include <sys/vfs.h>
22#include <sys/ioctl.h>
23#include <sys/param.h>
25d246df 24#include <sys/sysmacros.h>
66210ef2 25#include <sys/stat.h>
5d1b7f0f 26#include <inttypes.h>
c0211f67
NS
27#include <malloc.h>
28#include <getopt.h>
dcabd4e7 29#include <errno.h>
c0211f67 30#include <endian.h>
a2ceac1f 31#include <stdbool.h>
7c66b2fd 32#include <stdio.h>
24842c5c 33#include <asm/types.h>
7141fc5b 34#include <mntent.h>
6529e656
DW
35#ifdef OVERRIDE_SYSTEM_FSXATTR
36# define fsxattr sys_fsxattr
37#endif
2be9e939 38#include <linux/fs.h> /* fsxattr defintion for new kernels */
6529e656
DW
39#ifdef OVERRIDE_SYSTEM_FSXATTR
40# undef fsxattr
41#endif
c0211f67
NS
42
43static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
44{
45 return ioctl(fd, cmd, p);
46}
47
fcd6fa7f
ES
48/*
49 * platform_test_xfs_*() implies that xfsctl will succeed on the file;
50 * on Linux, at least, special files don't get xfs file ops,
51 * so return 0 for those
52 */
53
c0211f67
NS
54static __inline__ int platform_test_xfs_fd(int fd)
55{
fcd6fa7f
ES
56 struct statfs statfsbuf;
57 struct stat statbuf;
58
59 if (fstatfs(fd, &statfsbuf) < 0)
60 return 0;
61 if (fstat(fd, &statbuf) < 0)
c0211f67 62 return 0;
fcd6fa7f
ES
63 if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
64 return 0;
65 return (statfsbuf.f_type == 0x58465342); /* XFSB */
c0211f67
NS
66}
67
68static __inline__ int platform_test_xfs_path(const char *path)
69{
fcd6fa7f
ES
70 struct statfs statfsbuf;
71 struct stat statbuf;
72
73 if (statfs(path, &statfsbuf) < 0)
74 return 0;
75 if (stat(path, &statbuf) < 0)
76 return 0;
77 if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
c0211f67 78 return 0;
fcd6fa7f 79 return (statfsbuf.f_type == 0x58465342); /* XFSB */
c0211f67
NS
80}
81
82static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
83{
84 return fstatfs(fd, buf);
85}
86
87static __inline__ void platform_getoptreset(void)
88{
89 extern int optind;
90 optind = 0;
91}
92
1552a820
NS
93static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
94{
95 return uuid_compare(*uu1, *uu2);
96}
97
4d32d744 98static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
1552a820 99{
4d32d744
NS
100 uuid_unparse(*uu, buffer);
101}
102
103static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
104{
105 return uuid_parse(buffer, *uu);
1552a820
NS
106}
107
108static __inline__ int platform_uuid_is_null(uuid_t *uu)
109{
110 return uuid_is_null(*uu);
111}
c0211f67 112
4d32d744
NS
113static __inline__ void platform_uuid_generate(uuid_t *uu)
114{
115 uuid_generate(*uu);
116}
117
118static __inline__ void platform_uuid_clear(uuid_t *uu)
119{
120 uuid_clear(*uu);
121}
122
123static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
124{
125 uuid_copy(*dst, *src);
126}
127
ad136b33
CH
128#ifndef BLKDISCARD
129#define BLKDISCARD _IO(0x12,119)
130#endif
131
132static __inline__ int
f96aff0c 133platform_discard_blocks(int fd, uint64_t start, uint64_t len)
ad136b33 134{
14f8b681 135 uint64_t range[2] = { start, len };
ad136b33
CH
136
137 if (ioctl(fd, BLKDISCARD, &range) < 0)
138 return errno;
139 return 0;
140}
141
c0211f67 142#define ENOATTR ENODATA /* Attribute not found */
1552a820 143#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
99c1ec96 144#define EFSBADCRC EBADMSG /* Bad CRC detected */
c0211f67 145
65b4f302 146typedef off_t xfs_off_t;
14f8b681
DW
147typedef uint64_t xfs_ino_t;
148typedef uint32_t xfs_dev_t;
149typedef int64_t xfs_daddr_t;
d8079fe0 150typedef __u32 xfs_nlink_t;
c0211f67 151
7141fc5b
JT
152/**
153 * Abstraction of mountpoints.
154 */
155struct mntent_cursor {
156 FILE *mtabp;
157};
158
159static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
160{
161 cursor->mtabp = setmntent(mtab, "r");
162 if (!cursor->mtabp) {
163 fprintf(stderr, "Error: cannot read %s\n", mtab);
164 return 1;
165 }
166 return 0;
167}
168
169static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
170{
171 return getmntent(cursor->mtabp);
172}
173
174static inline void platform_mntent_close(struct mntent_cursor * cursor)
175{
176 endmntent(cursor->mtabp);
177}
178
83f4b5ac
DC
179/*
180 * Check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves. These
181 * are a copy of the definitions moved to linux/uapi/fs.h in the 4.5 kernel,
182 * so this is purely for supporting builds against old kernel headers.
183 */
6529e656 184#if !defined FS_IOC_FSGETXATTR || defined OVERRIDE_SYSTEM_FSXATTR
83f4b5ac
DC
185struct fsxattr {
186 __u32 fsx_xflags; /* xflags field value (get/set) */
187 __u32 fsx_extsize; /* extsize field value (get/set)*/
188 __u32 fsx_nextents; /* nextents field value (get) */
189 __u32 fsx_projid; /* project identifier (get/set) */
1bc58d93
DW
190 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
191 unsigned char fsx_pad[8];
83f4b5ac 192};
6529e656 193#endif
83f4b5ac 194
6529e656 195#ifndef FS_IOC_FSGETXATTR
83f4b5ac
DC
196/*
197 * Flags for the fsx_xflags field
198 */
199#define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
200#define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
201#define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
202#define FS_XFLAG_APPEND 0x00000010 /* all writes append */
203#define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
204#define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
205#define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
206#define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
207#define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
208#define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
209#define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
210#define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
211#define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
212#define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7093f633 213#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
83f4b5ac
DC
214#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
215
216#define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr)
217#define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr)
218
219#endif
220
1bc58d93
DW
221#ifndef FS_XFLAG_COWEXTSIZE
222#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
223#endif
224
6644005b
DW
225#ifdef HAVE_GETFSMAP
226# include <linux/fsmap.h>
227#else
71956d72
DW
228/*
229 * Structure for FS_IOC_GETFSMAP.
230 *
231 * The memory layout for this call are the scalar values defined in
232 * struct fsmap_head, followed by two struct fsmap that describe
233 * the lower and upper bound of mappings to return, followed by an
234 * array of struct fsmap mappings.
235 *
236 * fmh_iflags control the output of the call, whereas fmh_oflags report
237 * on the overall record output. fmh_count should be set to the
238 * length of the fmh_recs array, and fmh_entries will be set to the
239 * number of entries filled out during each call. If fmh_count is
240 * zero, the number of reverse mappings will be returned in
241 * fmh_entries, though no mappings will be returned. fmh_reserved
242 * must be set to zero.
243 *
244 * The two elements in the fmh_keys array are used to constrain the
245 * output. The first element in the array should represent the
246 * lowest disk mapping ("low key") that the user wants to learn
247 * about. If this value is all zeroes, the filesystem will return
248 * the first entry it knows about. For a subsequent call, the
249 * contents of fsmap_head.fmh_recs[fsmap_head.fmh_count - 1] should be
250 * copied into fmh_keys[0] to have the kernel start where it left off.
251 *
252 * The second element in the fmh_keys array should represent the
253 * highest disk mapping ("high key") that the user wants to learn
254 * about. If this value is all ones, the filesystem will not stop
255 * until it runs out of mapping to return or runs out of space in
256 * fmh_recs.
257 *
258 * fmr_device can be either a 32-bit cookie representing a device, or
259 * a 32-bit dev_t if the FMH_OF_DEV_T flag is set. fmr_physical,
260 * fmr_offset, and fmr_length are expressed in units of bytes.
261 * fmr_owner is either an inode number, or a special value if
262 * FMR_OF_SPECIAL_OWNER is set in fmr_flags.
263 */
264struct fsmap {
265 __u32 fmr_device; /* device id */
266 __u32 fmr_flags; /* mapping flags */
267 __u64 fmr_physical; /* device offset of segment */
268 __u64 fmr_owner; /* owner id */
269 __u64 fmr_offset; /* file offset of segment */
270 __u64 fmr_length; /* length of segment */
271 __u64 fmr_reserved[3]; /* must be zero */
272};
273
274struct fsmap_head {
275 __u32 fmh_iflags; /* control flags */
276 __u32 fmh_oflags; /* output flags */
277 __u32 fmh_count; /* # of entries in array incl. input */
278 __u32 fmh_entries; /* # of entries filled in (output). */
279 __u64 fmh_reserved[6]; /* must be zero */
280
281 struct fsmap fmh_keys[2]; /* low and high keys for the mapping search */
282 struct fsmap fmh_recs[]; /* returned records */
283};
284
285/* Size of an fsmap_head with room for nr records. */
286static inline size_t
287fsmap_sizeof(
288 unsigned int nr)
289{
290 return sizeof(struct fsmap_head) + nr * sizeof(struct fsmap);
291}
292
293/* Start the next fsmap query at the end of the current query results. */
294static inline void
295fsmap_advance(
296 struct fsmap_head *head)
297{
298 head->fmh_keys[0] = head->fmh_recs[head->fmh_entries - 1];
299}
300
301/* fmh_iflags values - set by XFS_IOC_GETFSMAP caller in the header. */
302/* no flags defined yet */
303#define FMH_IF_VALID 0
304
305/* fmh_oflags values - returned in the header segment only. */
306#define FMH_OF_DEV_T 0x1 /* fmr_device values will be dev_t */
307
308/* fmr_flags values - returned for each non-header segment */
309#define FMR_OF_PREALLOC 0x1 /* segment = unwritten pre-allocation */
310#define FMR_OF_ATTR_FORK 0x2 /* segment = attribute fork */
311#define FMR_OF_EXTENT_MAP 0x4 /* segment = extent map */
312#define FMR_OF_SHARED 0x8 /* segment = shared with another file */
313#define FMR_OF_SPECIAL_OWNER 0x10 /* owner is a special value */
314#define FMR_OF_LAST 0x20 /* segment is the last in the FS */
315
316/* Each FS gets to define its own special owner codes. */
317#define FMR_OWNER(type, code) (((__u64)type << 32) | \
318 ((__u64)code & 0xFFFFFFFFULL))
319#define FMR_OWNER_TYPE(owner) ((__u32)((__u64)owner >> 32))
320#define FMR_OWNER_CODE(owner) ((__u32)(((__u64)owner & 0xFFFFFFFFULL)))
321#define FMR_OWN_FREE FMR_OWNER(0, 1) /* free space */
322#define FMR_OWN_UNKNOWN FMR_OWNER(0, 2) /* unknown owner */
323#define FMR_OWN_METADATA FMR_OWNER(0, 3) /* metadata */
324
325#define FS_IOC_GETFSMAP _IOWR('X', 59, struct fsmap_head)
326
327#define HAVE_GETFSMAP
328#endif /* HAVE_GETFSMAP */
329
dad79683
RZ
330#ifndef HAVE_MAP_SYNC
331#define MAP_SYNC 0
332#define MAP_SHARED_VALIDATE 0
333#else
334#include <asm-generic/mman.h>
335#include <asm-generic/mman-common.h>
336#endif /* HAVE_MAP_SYNC */
337
cb5b3ef4 338#endif /* __XFS_LINUX_H__ */