]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/linux.h
configure: don't check for fallocate
[thirdparty/xfsprogs-dev.git] / include / linux.h
CommitLineData
959ef981 1// SPDX-License-Identifier: LGPL-2.1
c0211f67 2/*
f302e9e4 3 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
c0211f67
NS
4 */
5#ifndef __XFS_LINUX_H__
6#define __XFS_LINUX_H__
7
135ce1ed
DW
8/*
9 * Reminder: anything added to this file will be compiled into downstream
10 * userspace projects!
11 */
12
c0211f67
NS
13#include <uuid/uuid.h>
14#include <sys/vfs.h>
15#include <sys/ioctl.h>
16#include <sys/param.h>
25d246df 17#include <sys/sysmacros.h>
66210ef2 18#include <sys/stat.h>
5d1b7f0f 19#include <inttypes.h>
c0211f67
NS
20#include <malloc.h>
21#include <getopt.h>
dcabd4e7 22#include <errno.h>
c0211f67 23#include <endian.h>
a2ceac1f 24#include <stdbool.h>
7c66b2fd 25#include <stdio.h>
3a882f0a 26#include <signal.h>
24842c5c 27#include <asm/types.h>
7141fc5b 28#include <mntent.h>
9d6023a8 29#include <fcntl.h>
9d6023a8 30#include <linux/falloc.h>
6529e656
DW
31#ifdef OVERRIDE_SYSTEM_FSXATTR
32# define fsxattr sys_fsxattr
33#endif
2be9e939 34#include <linux/fs.h> /* fsxattr defintion for new kernels */
6529e656
DW
35#ifdef OVERRIDE_SYSTEM_FSXATTR
36# undef fsxattr
37#endif
704e4cef
DW
38#include <unistd.h>
39#include <assert.h>
c0211f67
NS
40
41static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
42{
43 return ioctl(fd, cmd, p);
44}
45
fcd6fa7f
ES
46/*
47 * platform_test_xfs_*() implies that xfsctl will succeed on the file;
48 * on Linux, at least, special files don't get xfs file ops,
49 * so return 0 for those
50 */
51
c0211f67
NS
52static __inline__ int platform_test_xfs_fd(int fd)
53{
fcd6fa7f
ES
54 struct statfs statfsbuf;
55 struct stat statbuf;
56
57 if (fstatfs(fd, &statfsbuf) < 0)
58 return 0;
59 if (fstat(fd, &statbuf) < 0)
c0211f67 60 return 0;
fcd6fa7f
ES
61 if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
62 return 0;
63 return (statfsbuf.f_type == 0x58465342); /* XFSB */
c0211f67
NS
64}
65
66static __inline__ int platform_test_xfs_path(const char *path)
67{
fcd6fa7f
ES
68 struct statfs statfsbuf;
69 struct stat statbuf;
70
71 if (statfs(path, &statfsbuf) < 0)
72 return 0;
73 if (stat(path, &statbuf) < 0)
74 return 0;
75 if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
c0211f67 76 return 0;
fcd6fa7f 77 return (statfsbuf.f_type == 0x58465342); /* XFSB */
c0211f67
NS
78}
79
80static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
81{
82 return fstatfs(fd, buf);
83}
84
85static __inline__ void platform_getoptreset(void)
86{
87 extern int optind;
88 optind = 0;
89}
90
1552a820
NS
91static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
92{
93 return uuid_compare(*uu1, *uu2);
94}
95
4d32d744 96static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
1552a820 97{
4d32d744
NS
98 uuid_unparse(*uu, buffer);
99}
100
9c2b30c8 101static __inline__ int platform_uuid_parse(const char *buffer, uuid_t *uu)
4d32d744
NS
102{
103 return uuid_parse(buffer, *uu);
1552a820
NS
104}
105
106static __inline__ int platform_uuid_is_null(uuid_t *uu)
107{
108 return uuid_is_null(*uu);
109}
c0211f67 110
4d32d744
NS
111static __inline__ void platform_uuid_generate(uuid_t *uu)
112{
113 uuid_generate(*uu);
114}
115
116static __inline__ void platform_uuid_clear(uuid_t *uu)
117{
118 uuid_clear(*uu);
119}
120
121static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
122{
123 uuid_copy(*dst, *src);
124}
125
ad136b33
CH
126#ifndef BLKDISCARD
127#define BLKDISCARD _IO(0x12,119)
128#endif
129
130static __inline__ int
f96aff0c 131platform_discard_blocks(int fd, uint64_t start, uint64_t len)
ad136b33 132{
14f8b681 133 uint64_t range[2] = { start, len };
ad136b33
CH
134
135 if (ioctl(fd, BLKDISCARD, &range) < 0)
136 return errno;
137 return 0;
138}
139
c0211f67 140#define ENOATTR ENODATA /* Attribute not found */
1552a820 141#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
99c1ec96 142#define EFSBADCRC EBADMSG /* Bad CRC detected */
c0211f67 143
65b4f302 144typedef off_t xfs_off_t;
14f8b681
DW
145typedef uint64_t xfs_ino_t;
146typedef uint32_t xfs_dev_t;
147typedef int64_t xfs_daddr_t;
d8079fe0 148typedef __u32 xfs_nlink_t;
c0211f67 149
7141fc5b
JT
150/**
151 * Abstraction of mountpoints.
152 */
153struct mntent_cursor {
154 FILE *mtabp;
155};
156
157static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
158{
159 cursor->mtabp = setmntent(mtab, "r");
160 if (!cursor->mtabp) {
161 fprintf(stderr, "Error: cannot read %s\n", mtab);
162 return 1;
163 }
164 return 0;
165}
166
167static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
168{
169 return getmntent(cursor->mtabp);
170}
171
172static inline void platform_mntent_close(struct mntent_cursor * cursor)
173{
174 endmntent(cursor->mtabp);
175}
176
9d6023a8
ES
177#if defined(FALLOC_FL_ZERO_RANGE)
178static inline int
179platform_zero_range(
180 int fd,
181 xfs_off_t start,
182 size_t len)
183{
184 int ret;
185
186 ret = fallocate(fd, FALLOC_FL_ZERO_RANGE, start, len);
187 if (!ret)
188 return 0;
189 return -errno;
190}
191#else
192#define platform_zero_range(fd, s, l) (-EOPNOTSUPP)
193#endif
194
704e4cef
DW
195/*
196 * Use SIGKILL to simulate an immediate program crash, without a chance to run
197 * atexit handlers.
198 */
199static inline void
200platform_crash(void)
201{
202 kill(getpid(), SIGKILL);
203 assert(0);
204}
205
83f4b5ac
DC
206/*
207 * Check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves. These
208 * are a copy of the definitions moved to linux/uapi/fs.h in the 4.5 kernel,
209 * so this is purely for supporting builds against old kernel headers.
210 */
6529e656 211#if !defined FS_IOC_FSGETXATTR || defined OVERRIDE_SYSTEM_FSXATTR
83f4b5ac
DC
212struct fsxattr {
213 __u32 fsx_xflags; /* xflags field value (get/set) */
214 __u32 fsx_extsize; /* extsize field value (get/set)*/
215 __u32 fsx_nextents; /* nextents field value (get) */
216 __u32 fsx_projid; /* project identifier (get/set) */
1bc58d93
DW
217 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
218 unsigned char fsx_pad[8];
83f4b5ac 219};
6529e656 220#endif
83f4b5ac 221
6529e656 222#ifndef FS_IOC_FSGETXATTR
83f4b5ac
DC
223/*
224 * Flags for the fsx_xflags field
225 */
226#define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
227#define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
228#define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
229#define FS_XFLAG_APPEND 0x00000010 /* all writes append */
230#define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
231#define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
232#define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
233#define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
234#define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
235#define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
236#define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
237#define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
238#define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
239#define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7093f633 240#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
83f4b5ac
DC
241#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
242
243#define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr)
244#define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr)
245
246#endif
247
1bc58d93
DW
248#ifndef FS_XFLAG_COWEXTSIZE
249#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
250#endif
251
df9c7d8d 252/*
135ce1ed
DW
253 * Reminder: anything added to this file will be compiled into downstream
254 * userspace projects!
df9c7d8d 255 */
df9c7d8d 256
cb5b3ef4 257#endif /* __XFS_LINUX_H__ */