]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/linux.h
eddc4ad9c899ba1b35d0c718039bad4be2dd060e
1 // SPDX-License-Identifier: LGPL-2.1
3 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
5 #ifndef __XFS_LINUX_H__
6 #define __XFS_LINUX_H__
9 * Reminder: anything added to this file will be compiled into downstream
13 #include <uuid/uuid.h>
15 #include <sys/ioctl.h>
16 #include <sys/param.h>
17 #include <sys/sysmacros.h>
27 #include <asm/types.h>
30 #if defined(HAVE_FALLOCATE)
31 #include <linux/falloc.h>
33 #ifdef OVERRIDE_SYSTEM_FSXATTR
34 # define fsxattr sys_fsxattr
36 #include <linux/fs.h> /* fsxattr defintion for new kernels */
37 #ifdef OVERRIDE_SYSTEM_FSXATTR
43 static __inline__
int xfsctl(const char *path
, int fd
, int cmd
, void *p
)
45 return ioctl(fd
, cmd
, p
);
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
54 static __inline__
int platform_test_xfs_fd(int fd
)
56 struct statfs statfsbuf
;
59 if (fstatfs(fd
, &statfsbuf
) < 0)
61 if (fstat(fd
, &statbuf
) < 0)
63 if (!S_ISREG(statbuf
.st_mode
) && !S_ISDIR(statbuf
.st_mode
))
65 return (statfsbuf
.f_type
== 0x58465342); /* XFSB */
68 static __inline__
int platform_test_xfs_path(const char *path
)
70 struct statfs statfsbuf
;
73 if (statfs(path
, &statfsbuf
) < 0)
75 if (stat(path
, &statbuf
) < 0)
77 if (!S_ISREG(statbuf
.st_mode
) && !S_ISDIR(statbuf
.st_mode
))
79 return (statfsbuf
.f_type
== 0x58465342); /* XFSB */
82 static __inline__
int platform_fstatfs(int fd
, struct statfs
*buf
)
84 return fstatfs(fd
, buf
);
87 static __inline__
void platform_getoptreset(void)
93 static __inline__
int platform_uuid_compare(uuid_t
*uu1
, uuid_t
*uu2
)
95 return uuid_compare(*uu1
, *uu2
);
98 static __inline__
void platform_uuid_unparse(uuid_t
*uu
, char *buffer
)
100 uuid_unparse(*uu
, buffer
);
103 static __inline__
int platform_uuid_parse(const char *buffer
, uuid_t
*uu
)
105 return uuid_parse(buffer
, *uu
);
108 static __inline__
int platform_uuid_is_null(uuid_t
*uu
)
110 return uuid_is_null(*uu
);
113 static __inline__
void platform_uuid_generate(uuid_t
*uu
)
118 static __inline__
void platform_uuid_clear(uuid_t
*uu
)
123 static __inline__
void platform_uuid_copy(uuid_t
*dst
, uuid_t
*src
)
125 uuid_copy(*dst
, *src
);
129 #define BLKDISCARD _IO(0x12,119)
132 static __inline__
int
133 platform_discard_blocks(int fd
, uint64_t start
, uint64_t len
)
135 uint64_t range
[2] = { start
, len
};
137 if (ioctl(fd
, BLKDISCARD
, &range
) < 0)
142 #define ENOATTR ENODATA /* Attribute not found */
143 #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
144 #define EFSBADCRC EBADMSG /* Bad CRC detected */
146 typedef off_t xfs_off_t
;
147 typedef uint64_t xfs_ino_t
;
148 typedef uint32_t xfs_dev_t
;
149 typedef int64_t xfs_daddr_t
;
150 typedef __u32 xfs_nlink_t
;
153 * Abstraction of mountpoints.
155 struct mntent_cursor
{
159 static inline int platform_mntent_open(struct mntent_cursor
* cursor
, char *mtab
)
161 cursor
->mtabp
= setmntent(mtab
, "r");
162 if (!cursor
->mtabp
) {
163 fprintf(stderr
, "Error: cannot read %s\n", mtab
);
169 static inline struct mntent
* platform_mntent_next(struct mntent_cursor
* cursor
)
171 return getmntent(cursor
->mtabp
);
174 static inline void platform_mntent_close(struct mntent_cursor
* cursor
)
176 endmntent(cursor
->mtabp
);
179 #if defined(FALLOC_FL_ZERO_RANGE)
188 ret
= fallocate(fd
, FALLOC_FL_ZERO_RANGE
, start
, len
);
194 #define platform_zero_range(fd, s, l) (-EOPNOTSUPP)
198 * Use SIGKILL to simulate an immediate program crash, without a chance to run
204 kill(getpid(), SIGKILL
);
209 * Check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves. These
210 * are a copy of the definitions moved to linux/uapi/fs.h in the 4.5 kernel,
211 * so this is purely for supporting builds against old kernel headers.
213 #if !defined FS_IOC_FSGETXATTR || defined OVERRIDE_SYSTEM_FSXATTR
215 __u32 fsx_xflags
; /* xflags field value (get/set) */
216 __u32 fsx_extsize
; /* extsize field value (get/set)*/
217 __u32 fsx_nextents
; /* nextents field value (get) */
218 __u32 fsx_projid
; /* project identifier (get/set) */
219 __u32 fsx_cowextsize
; /* cow extsize field value (get/set) */
220 unsigned char fsx_pad
[8];
224 #ifndef FS_IOC_FSGETXATTR
226 * Flags for the fsx_xflags field
228 #define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
229 #define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
230 #define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
231 #define FS_XFLAG_APPEND 0x00000010 /* all writes append */
232 #define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
233 #define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
234 #define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
235 #define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
236 #define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
237 #define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
238 #define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
239 #define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
240 #define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
241 #define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
242 #define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
243 #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
245 #define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr)
246 #define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr)
250 #ifndef FS_XFLAG_COWEXTSIZE
251 #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
255 * Reminder: anything added to this file will be compiled into downstream
256 * userspace projects!
259 #endif /* __XFS_LINUX_H__ */