]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/freebsd.h
xfs: detect agfl count corruption and reset agfl
[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 fdatasync fsync
38#define memalign(a,sz) valloc(sz)
c0211f67 39
c0211f67 40#define EFSCORRUPTED 990 /* Filesystem is corrupted */
99c1ec96 41#define EFSBADCRC 991 /* Bad CRC detected */
c0211f67 42
24842c5c
CH
43typedef unsigned char __u8;
44typedef signed char __s8;
45typedef unsigned short __u16;
46typedef signed short __s16;
47typedef unsigned int __u32;
48typedef signed int __s32;
49typedef unsigned long long int __u64;
50typedef signed long long int __s64;
51
d8079fe0 52typedef off_t xfs_off_t;
14f8b681
DW
53typedef uint64_t xfs_ino_t;
54typedef uint32_t xfs_dev_t;
55typedef int64_t xfs_daddr_t;
d8079fe0
DW
56typedef __u32 xfs_nlink_t;
57
c0211f67
NS
58#define O_LARGEFILE 0
59
60#define HAVE_FID 1
c0211f67
NS
61
62static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
63{
64 return ioctl(fd, cmd, p);
65}
66
67static __inline__ int platform_test_xfs_fd(int fd)
68{
69 struct statfs buf;
70 if (fstatfs(fd, &buf) < 0)
71 return 0;
714bd9e5 72 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
c0211f67
NS
73}
74
75static __inline__ int platform_test_xfs_path(const char *path)
76{
77 struct statfs buf;
78 if (statfs(path, &buf) < 0)
79 return 0;
714bd9e5 80 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
c0211f67
NS
81}
82
83static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
84{
85 return fstatfs(fd, buf);
86}
87
88static __inline__ void platform_getoptreset(void)
89{
90 extern int optind;
91 optind = 0;
92}
93
1552a820 94static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
c0211f67 95{
1552a820 96 return uuid_compare(uu1, uu2, NULL);
c0211f67 97}
c0211f67 98
4d32d744 99static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
c0211f67
NS
100{
101 uint32_t status;
1552a820
NS
102 char *s;
103 uuid_to_string(uu, &s, &status);
c0211f67 104 if (status == uuid_s_ok)
4d32d744
NS
105 strcpy(buffer, s);
106 else buffer[0] = '\0';
1552a820 107 free(s);
c0211f67
NS
108}
109
1552a820 110static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
c0211f67
NS
111{
112 uint32_t status;
1552a820 113 uuid_from_string(buffer, uu, &status);
c0211f67
NS
114 return (status == uuid_s_ok);
115}
c0211f67 116
1552a820
NS
117static __inline__ int platform_uuid_is_null(uuid_t *uu)
118{
119 return uuid_is_nil(uu, NULL);
120}
121
122static __inline__ void platform_uuid_generate(uuid_t *uu)
123{
124 uuid_create(uu, NULL);
125}
126
127static __inline__ void platform_uuid_clear(uuid_t *uu)
128{
129 uuid_create_nil(uu, NULL);
130}
131
132static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
133{
134 memcpy(dst, src, sizeof(uuid_t));
135}
c0211f67 136
ad136b33 137static __inline__ int
f96aff0c 138platform_discard_blocks(int fd, uint64_t start, uint64_t len)
ad136b33
CH
139{
140 return 0;
141}
142
7141fc5b
JT
143/**
144 * Abstraction of mountpoints.
145 */
146struct mntent_cursor {
147 FILE *mtabp;
148};
149
150static 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
160static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
161{
162 return getmntent(cursor->mtabp);
163}
164
165static inline void platform_mntent_close(struct mntent_cursor * cursor)
166{
167 endmntent(cursor->mtabp);
168}
169
83f4b5ac
DC
170/* check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves */
171#ifndef HAVE_FSXATTR
172struct 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) */
1bc58d93
DW
177 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
178 unsigned char fsx_pad[8];
83f4b5ac
DC
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 */
7093f633 198#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
83f4b5ac
DC
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
1bc58d93
DW
206#ifndef FS_XFLAG_COWEXTSIZE
207#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
208#endif
7141fc5b 209
c0211f67 210#endif /* __XFS_FREEBSD_H__ */