]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/gnukfreebsd.h
xfs: automatic dfops buffer relogging
[thirdparty/xfsprogs-dev.git] / include / gnukfreebsd.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_KFREEBSD_H__
7 #define __XFS_KFREEBSD_H__
8
9 #include <uuid/uuid.h>
10 #include <sys/vfs.h>
11 #include <sys/ioctl.h>
12 #include <sys/sysmacros.h>
13 #include <malloc.h>
14 #include <getopt.h>
15 #include <endian.h>
16 #include <sys/stat.h>
17 #include <sys/param.h>
18 #include <sys/mount.h>
19 #include <ctype.h>
20 #include <libgen.h>
21 #include <paths.h>
22 #include <mntent.h>
23
24 #define EFSCORRUPTED 990 /* Filesystem is corrupted */
25 #define EFSBADCRC 991 /* Bad CRC detected */
26
27 typedef unsigned char __u8;
28 typedef signed char __s8;
29 typedef unsigned short __u16;
30 typedef signed short __s16;
31 typedef unsigned int __u32;
32 typedef signed int __s32;
33 typedef unsigned long long int __u64;
34 typedef signed long long int __s64;
35
36 typedef off_t xfs_off_t;
37 typedef uint64_t xfs_ino_t;
38 typedef uint32_t xfs_dev_t;
39 typedef int64_t xfs_daddr_t;
40 typedef __u32 xfs_nlink_t;
41
42 #define HAVE_FID 1
43
44 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
45 {
46 return ioctl(fd, cmd, p);
47 }
48
49 static __inline__ int platform_test_xfs_fd(int fd)
50 {
51 struct statfs buf;
52 if (fstatfs(fd, &buf) < 0)
53 return 0;
54 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
55 }
56
57 static __inline__ int platform_test_xfs_path(const char *path)
58 {
59 struct statfs buf;
60 if (statfs(path, &buf) < 0)
61 return 0;
62 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
63 }
64
65 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
66 {
67 return fstatfs(fd, buf);
68 }
69
70 static __inline__ void platform_getoptreset(void)
71 {
72 extern int optind;
73 optind = 0;
74 }
75
76 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
77 {
78 return uuid_compare(*uu1, *uu2);
79 }
80
81 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
82 {
83 uuid_unparse(*uu, buffer);
84 }
85
86 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
87 {
88 return uuid_parse(buffer, *uu);
89 }
90
91 static __inline__ int platform_uuid_is_null(uuid_t *uu)
92 {
93 return uuid_is_null(*uu);
94 }
95
96 static __inline__ void platform_uuid_generate(uuid_t *uu)
97 {
98 uuid_generate(*uu);
99 }
100
101 static __inline__ void platform_uuid_clear(uuid_t *uu)
102 {
103 uuid_clear(*uu);
104 }
105
106 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
107 {
108 uuid_copy(*dst, *src);
109 }
110
111 static __inline__ int
112 platform_discard_blocks(int fd, uint64_t start, uint64_t len)
113 {
114 return 0;
115 }
116
117 /**
118 * Abstraction of mountpoints.
119 */
120 struct mntent_cursor {
121 FILE *mtabp;
122 };
123
124 static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
125 {
126 cursor->mtabp = setmntent(mtab, "r");
127 if (!cursor->mtabp) {
128 fprintf(stderr, "Error: cannot read %s\n", mtab);
129 return 1;
130 }
131 return 0;
132 }
133
134 static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
135 {
136 return getmntent(cursor->mtabp);
137 }
138
139 static inline void platform_mntent_close(struct mntent_cursor * cursor)
140 {
141 endmntent(cursor->mtabp);
142 }
143
144 #endif /* __XFS_KFREEBSD_H__ */