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