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