]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/linux.h
libxfs: fix xfs_trans_alloc_empty namespace
[thirdparty/xfsprogs-dev.git] / include / linux.h
1 /*
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
12 *
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
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>
24 #include <sys/sysmacros.h>
25 #include <sys/stat.h>
26 #include <inttypes.h>
27 #include <malloc.h>
28 #include <getopt.h>
29 #include <errno.h>
30 #include <endian.h>
31 #include <stdbool.h>
32 #include <stdio.h>
33 #include <asm/types.h>
34 #include <mntent.h>
35 #ifdef OVERRIDE_SYSTEM_FSXATTR
36 # define fsxattr sys_fsxattr
37 #endif
38 #include <linux/fs.h> /* fsxattr defintion for new kernels */
39 #ifdef OVERRIDE_SYSTEM_FSXATTR
40 # undef fsxattr
41 #endif
42
43 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
44 {
45 return ioctl(fd, cmd, p);
46 }
47
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
54 static __inline__ int platform_test_xfs_fd(int fd)
55 {
56 struct statfs statfsbuf;
57 struct stat statbuf;
58
59 if (fstatfs(fd, &statfsbuf) < 0)
60 return 0;
61 if (fstat(fd, &statbuf) < 0)
62 return 0;
63 if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
64 return 0;
65 return (statfsbuf.f_type == 0x58465342); /* XFSB */
66 }
67
68 static __inline__ int platform_test_xfs_path(const char *path)
69 {
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))
78 return 0;
79 return (statfsbuf.f_type == 0x58465342); /* XFSB */
80 }
81
82 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
83 {
84 return fstatfs(fd, buf);
85 }
86
87 static __inline__ void platform_getoptreset(void)
88 {
89 extern int optind;
90 optind = 0;
91 }
92
93 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
94 {
95 return uuid_compare(*uu1, *uu2);
96 }
97
98 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
99 {
100 uuid_unparse(*uu, buffer);
101 }
102
103 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
104 {
105 return uuid_parse(buffer, *uu);
106 }
107
108 static __inline__ int platform_uuid_is_null(uuid_t *uu)
109 {
110 return uuid_is_null(*uu);
111 }
112
113 static __inline__ void platform_uuid_generate(uuid_t *uu)
114 {
115 uuid_generate(*uu);
116 }
117
118 static __inline__ void platform_uuid_clear(uuid_t *uu)
119 {
120 uuid_clear(*uu);
121 }
122
123 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
124 {
125 uuid_copy(*dst, *src);
126 }
127
128 #ifndef BLKDISCARD
129 #define BLKDISCARD _IO(0x12,119)
130 #endif
131
132 static __inline__ int
133 platform_discard_blocks(int fd, uint64_t start, uint64_t len)
134 {
135 __uint64_t range[2] = { start, len };
136
137 if (ioctl(fd, BLKDISCARD, &range) < 0)
138 return errno;
139 return 0;
140 }
141
142 #define ENOATTR ENODATA /* Attribute not found */
143 #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
144 #define EFSBADCRC EBADMSG /* Bad CRC detected */
145
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;
151
152 /**
153 * Abstraction of mountpoints.
154 */
155 struct mntent_cursor {
156 FILE *mtabp;
157 };
158
159 static 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
169 static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
170 {
171 return getmntent(cursor->mtabp);
172 }
173
174 static inline void platform_mntent_close(struct mntent_cursor * cursor)
175 {
176 endmntent(cursor->mtabp);
177 }
178
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 */
184 #if !defined FS_IOC_FSGETXATTR || defined OVERRIDE_SYSTEM_FSXATTR
185 struct 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) */
190 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
191 unsigned char fsx_pad[8];
192 };
193 #endif
194
195 #ifndef FS_IOC_FSGETXATTR
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 */
213 #define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
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
221 #ifndef FS_XFLAG_COWEXTSIZE
222 #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
223 #endif
224
225 #endif /* __XFS_LINUX_H__ */