]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/freebsd.h
xfs: refactor xfs_trans_roll
[thirdparty/xfsprogs-dev.git] / include / freebsd.h
1 /*
2 * Copyright (c) 2004-2006 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation.
8 *
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 Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser 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
17 */
18 #ifndef __XFS_FREEBSD_H__
19 #define __XFS_FREEBSD_H__
20
21 #include <sys/stat.h>
22 #include <sys/param.h>
23 #include <sys/ioccom.h>
24 #include <sys/mount.h>
25 #include <ctype.h>
26 #include <libgen.h>
27 #include <paths.h>
28 #include <uuid.h>
29 #include <mntent.h>
30
31 #include <sys/endian.h>
32 #define __BYTE_ORDER BYTE_ORDER
33 #define __BIG_ENDIAN BIG_ENDIAN
34 #define __LITTLE_ENDIAN LITTLE_ENDIAN
35
36 /* FreeBSD file API is 64-bit aware */
37 #define fdatasync fsync
38 #define memalign(a,sz) valloc(sz)
39
40 #define EFSCORRUPTED 990 /* Filesystem is corrupted */
41 #define EFSBADCRC 991 /* Bad CRC detected */
42
43 typedef unsigned char __u8;
44 typedef signed char __s8;
45 typedef unsigned short __u16;
46 typedef signed short __s16;
47 typedef unsigned int __u32;
48 typedef signed int __s32;
49 typedef unsigned long long int __u64;
50 typedef signed long long int __s64;
51
52 typedef off_t xfs_off_t;
53 typedef uint64_t xfs_ino_t;
54 typedef uint32_t xfs_dev_t;
55 typedef int64_t xfs_daddr_t;
56 typedef __u32 xfs_nlink_t;
57
58 #define O_LARGEFILE 0
59
60 #define HAVE_FID 1
61
62 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
63 {
64 return ioctl(fd, cmd, p);
65 }
66
67 static __inline__ int platform_test_xfs_fd(int fd)
68 {
69 struct statfs buf;
70 if (fstatfs(fd, &buf) < 0)
71 return 0;
72 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
73 }
74
75 static __inline__ int platform_test_xfs_path(const char *path)
76 {
77 struct statfs buf;
78 if (statfs(path, &buf) < 0)
79 return 0;
80 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
81 }
82
83 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
84 {
85 return fstatfs(fd, buf);
86 }
87
88 static __inline__ void platform_getoptreset(void)
89 {
90 extern int optind;
91 optind = 0;
92 }
93
94 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
95 {
96 return uuid_compare(uu1, uu2, NULL);
97 }
98
99 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
100 {
101 uint32_t status;
102 char *s;
103 uuid_to_string(uu, &s, &status);
104 if (status == uuid_s_ok)
105 strcpy(buffer, s);
106 else buffer[0] = '\0';
107 free(s);
108 }
109
110 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
111 {
112 uint32_t status;
113 uuid_from_string(buffer, uu, &status);
114 return (status == uuid_s_ok);
115 }
116
117 static __inline__ int platform_uuid_is_null(uuid_t *uu)
118 {
119 return uuid_is_nil(uu, NULL);
120 }
121
122 static __inline__ void platform_uuid_generate(uuid_t *uu)
123 {
124 uuid_create(uu, NULL);
125 }
126
127 static __inline__ void platform_uuid_clear(uuid_t *uu)
128 {
129 uuid_create_nil(uu, NULL);
130 }
131
132 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
133 {
134 memcpy(dst, src, sizeof(uuid_t));
135 }
136
137 static __inline__ int
138 platform_discard_blocks(int fd, uint64_t start, uint64_t len)
139 {
140 return 0;
141 }
142
143 /**
144 * Abstraction of mountpoints.
145 */
146 struct mntent_cursor {
147 FILE *mtabp;
148 };
149
150 static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
151 {
152 cursor->mtabp = setmntent(mtab, "r");
153 if (!cursor->mtabp) {
154 fprintf(stderr, "Error: cannot read %s\n", mtab);
155 return 1;
156 }
157 return 0;
158 }
159
160 static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
161 {
162 return getmntent(cursor->mtabp);
163 }
164
165 static inline void platform_mntent_close(struct mntent_cursor * cursor)
166 {
167 endmntent(cursor->mtabp);
168 }
169
170 /* check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves */
171 #ifndef HAVE_FSXATTR
172 struct fsxattr {
173 __u32 fsx_xflags; /* xflags field value (get/set) */
174 __u32 fsx_extsize; /* extsize field value (get/set)*/
175 __u32 fsx_nextents; /* nextents field value (get) */
176 __u32 fsx_projid; /* project identifier (get/set) */
177 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
178 unsigned char fsx_pad[8];
179 };
180
181 /*
182 * Flags for the fsx_xflags field
183 */
184 #define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
185 #define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
186 #define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
187 #define FS_XFLAG_APPEND 0x00000010 /* all writes append */
188 #define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
189 #define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
190 #define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
191 #define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
192 #define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
193 #define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
194 #define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
195 #define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
196 #define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
197 #define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
198 #define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
199 #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
200
201 #define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr)
202 #define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr)
203
204 #endif
205
206 #ifndef FS_XFLAG_COWEXTSIZE
207 #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
208 #endif
209
210 #endif /* __XFS_FREEBSD_H__ */