]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/freebsd.h
Revert "Merge branch 'xfsprogs-dev'"
[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
30 #include <sys/endian.h>
31 #define __BYTE_ORDER BYTE_ORDER
32 #define __BIG_ENDIAN BIG_ENDIAN
33 #define __LITTLE_ENDIAN LITTLE_ENDIAN
34
35 /* FreeBSD file API is 64-bit aware */
36 #define fstat64 fstat
37 #define ftruncate64 ftruncate
38 #define lseek64 lseek
39 #define stat64 stat
40 #define pwrite64 pwrite
41 #define pread64 pread
42 #define fdatasync fsync
43 #define memalign(a,sz) valloc(sz)
44
45 #define constpp char * const *
46
47 #define EFSCORRUPTED 990 /* Filesystem is corrupted */
48
49 typedef off_t xfs_off_t;
50 typedef off_t off64_t;
51 typedef __uint64_t xfs_ino_t;
52 typedef __uint32_t xfs_dev_t;
53 typedef __int64_t xfs_daddr_t;
54 typedef char* xfs_caddr_t;
55 typedef off_t loff_t;
56
57 #ifndef _UCHAR_T_DEFINED
58 typedef unsigned char uchar_t;
59 #define _UCHAR_T_DEFINED 1
60 #endif
61 typedef enum { B_FALSE,B_TRUE } boolean_t;
62
63 #define O_LARGEFILE 0
64
65 #define HAVE_FID 1
66
67 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
68 {
69 return ioctl(fd, cmd, p);
70 }
71
72 static __inline__ int platform_test_xfs_fd(int fd)
73 {
74 struct statfs buf;
75 if (fstatfs(fd, &buf) < 0)
76 return 0;
77 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
78 }
79
80 static __inline__ int platform_test_xfs_path(const char *path)
81 {
82 struct statfs buf;
83 if (statfs(path, &buf) < 0)
84 return 0;
85 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
86 }
87
88 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
89 {
90 return fstatfs(fd, buf);
91 }
92
93 static __inline__ void platform_getoptreset(void)
94 {
95 extern int optind;
96 optind = 0;
97 }
98
99 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
100 {
101 return uuid_compare(uu1, uu2, NULL);
102 }
103
104 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
105 {
106 uint32_t status;
107 char *s;
108 uuid_to_string(uu, &s, &status);
109 if (status == uuid_s_ok)
110 strcpy(buffer, s);
111 else buffer[0] = '\0';
112 free(s);
113 }
114
115 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
116 {
117 uint32_t status;
118 uuid_from_string(buffer, uu, &status);
119 return (status == uuid_s_ok);
120 }
121
122 static __inline__ int platform_uuid_is_null(uuid_t *uu)
123 {
124 return uuid_is_nil(uu, NULL);
125 }
126
127 static __inline__ void platform_uuid_generate(uuid_t *uu)
128 {
129 uuid_create(uu, NULL);
130 }
131
132 static __inline__ void platform_uuid_clear(uuid_t *uu)
133 {
134 uuid_create_nil(uu, NULL);
135 }
136
137 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
138 {
139 memcpy(dst, src, sizeof(uuid_t));
140 }
141
142 #endif /* __XFS_FREEBSD_H__ */