]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/freebsd.h
Merge back recent changes from xfs kernel headers.
[thirdparty/xfsprogs-dev.git] / include / freebsd.h
1 /*
2 * Copyright (c) 2004-2005 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
30 #include <machine/endian.h>
31
32 /* FreeBSD file API is 64-bit aware */
33 #define fstat64 fstat
34 #define ftruncate64 ftruncate
35 #define lseek64 lseek
36 #define stat64 stat
37 #define pwrite64 pwrite
38 #define pread64 pread
39 #define fdatasync fsync
40 #define memalign(a,size) valloc(size)
41
42 typedef u_int8_t __u8;
43 typedef int8_t __s8;
44 typedef u_int16_t __u16;
45 typedef int16_t __s16;
46 typedef u_int32_t __u32;
47 typedef int32_t __s32;
48 typedef u_int64_t __u64;
49 typedef int64_t __s64;
50
51 #define constpp char * const *
52
53 #define EFSCORRUPTED 990 /* Filesystem is corrupted */
54
55 typedef off_t xfs_off_t;
56 typedef off_t off64_t;
57 typedef __uint64_t xfs_ino_t;
58 typedef __uint32_t xfs_dev_t;
59 typedef __int64_t xfs_daddr_t;
60 typedef char* xfs_caddr_t;
61 typedef off_t loff_t;
62
63 #ifndef _UCHAR_T_DEFINED
64 typedef unsigned char uchar_t;
65 #define _UCHAR_T_DEFINED 1
66 #endif
67 typedef enum { B_FALSE,B_TRUE } boolean_t;
68
69 #define O_LARGEFILE 0
70
71 #define HAVE_FID 1
72 #define HAVE_SWABMACROS 1
73 #define INT_SWAP16(type,var) ((typeof(type))(__bswap16((__u16)(var))))
74 #define INT_SWAP32(type,var) ((typeof(type))(__bswap32((__u32)(var))))
75 #define INT_SWAP64(type,var) ((typeof(type))(__bswap64((__u64)(var))))
76
77 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
78 {
79 return ioctl(fd, cmd, p);
80 }
81
82 static __inline__ int platform_test_xfs_fd(int fd)
83 {
84 struct statfs buf;
85 if (fstatfs(fd, &buf) < 0)
86 return 0;
87 return strcpy(buf.f_fstypename, "xfs") == 0;
88 }
89
90 static __inline__ int platform_test_xfs_path(const char *path)
91 {
92 struct statfs buf;
93 if (statfs(path, &buf) < 0)
94 return 0;
95 return strcpy(buf.f_fstypename, "xfs") == 0;
96 }
97
98 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
99 {
100 return fstatfs(fd, buf);
101 }
102
103 static __inline__ void platform_getoptreset(void)
104 {
105 extern int optind;
106 optind = 0;
107 }
108
109 /*
110 * Implement Linux libuuid functions in terms of DEC DCE's uuid
111 * functions from FreeBSD libc.
112 */
113
114 static __inline__ int gnu_uuid_compare(uuid_t a, uuid_t b)
115 {
116 return uuid_compare(&a, &b, NULL);
117 }
118 #define uuid_compare gnu_uuid_compare
119
120 static __inline__ int uuid_is_null(uuid_t uid)
121 {
122 return uuid_is_nil(&uid, NULL);
123 }
124
125 static __inline__ void uuid_unparse(uuid_t uid, char *buf)
126 {
127 uint32_t status;
128 char *str;
129 uuid_to_string(&uid, &str, &status);
130 if (status == uuid_s_ok)
131 strcpy(buf, str);
132 else *buf = '\0';
133 free(str);
134 }
135
136 static __inline__ int gnu_uuid_parse(const char *buf, uuid_t *uid)
137 {
138 uint32_t status;
139 uuid_from_string(buf, uid, &status);
140 return (status == uuid_s_ok);
141 }
142 #define uuid_parse(s,u) gnu_uuid_parse((s), &(u))
143
144 #define uuid_generate(uid) uuid_create(&(uid), NULL)
145 #define uuid_clear(uid) uuid_create_nil(&(uid), NULL)
146 #define uuid_copy(dst, src) memcpy(&(dst), &(src), sizeof(uuid_t))
147
148 #endif /* __XFS_FREEBSD_H__ */