]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/irix.h
Back out removal of HAVE_SWABMACROS for now - IRIX builds still need it atm.
[thirdparty/xfsprogs-dev.git] / include / irix.h
1 /*
2 * Copyright (c) 2000-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_IRIX_H__
19 #define __XFS_IRIX_H__
20
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <libgen.h>
24 #include <values.h>
25 #include <strings.h>
26 #include <inttypes.h>
27 #include <limits.h>
28 #include <fcntl.h>
29 #include <sys/stat.h>
30 #include <sys/uuid.h>
31 #include <sys/param.h>
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
34 #include <sys/statfs.h>
35 #include <sys/statvfs.h>
36 #include <sys/syssgi.h>
37 #include <sys/sysmacros.h>
38 #include <sys/fs/xfs_fsops.h>
39 #include <sys/fs/xfs_itable.h>
40
41 #define __int8_t char
42 #define __int16_t short
43 #define __uint8_t unsigned char
44 #define __uint16_t unsigned short
45 #define loff_t off64_t
46 typedef off64_t xfs_off_t;
47 typedef __int64_t xfs_ino_t;
48 typedef __int32_t xfs_dev_t;
49 typedef __int64_t xfs_daddr_t;
50 typedef char* xfs_caddr_t;
51
52 #define xfs_flock64 flock64
53 #define xfs_flock64_t struct flock64
54
55 typedef struct xfs_error_injection {
56 __int32_t fd;
57 __int32_t errtag;
58 } xfs_error_injection_t;
59
60 /* --- xfs_fsop_*req - request data structures --- */
61
62 typedef struct xfs_fsop_bulkreq {
63 ino64_t *lastip;
64 __int32_t icount;
65 xfs_bstat_t *ubuffer;
66 __int32_t *ocount;
67 } xfs_fsop_bulkreq_t;
68
69 typedef struct xfs_fsop_handlereq {
70 __u32 fd; /* fd for FD_TO_HANDLE */
71 void *path; /* user pathname */
72 __u32 oflags; /* open flags */
73 void *ihandle; /* user supplied handle */
74 __u32 ihandlen; /* user supplied length */
75 void *ohandle; /* user buffer for handle */
76 __u32 *ohandlen; /* user buffer length */
77 } xfs_fsop_handlereq_t;
78
79 typedef struct xfs_fsop_setdm_handlereq {
80 struct xfs_fsop_handlereq hreq; /* handle information */
81 struct fsdmidata *data; /* DMAPI data */
82 } xfs_fsop_setdm_handlereq_t;
83
84 typedef struct xfs_attrlist_cursor {
85 __u32 opaque[4];
86 } xfs_attrlist_cursor_t;
87
88 typedef struct xfs_fsop_attrlist_handlereq {
89 struct xfs_fsop_handlereq hreq; /* handle interface structure */
90 struct xfs_attrlist_cursor pos; /* opaque cookie, list offset */
91 __u32 flags; /* which namespace to use */
92 __u32 buflen; /* length of buffer supplied */
93 void *buffer; /* returned names */
94 } xfs_fsop_attrlist_handlereq_t;
95
96 typedef struct xfs_fsop_getparents_handlereq {
97 struct xfs_fsop_handlereq hreq; /* handle interface structure */
98 struct xfs_attrlist_cursor pos; /* opaque cookie, list offset */
99 __u32 buflen; /* length of buffer supplied */
100 void *buffer; /* returned data */
101 __u32 *ocount; /* return number of links */
102 __u32 *omore; /* return whether more to come */
103 } xfs_fsop_getparents_handlereq_t;
104
105 typedef struct xfs_attr_multiop {
106 __u32 am_opcode;
107 __s32 am_error;
108 void *am_attrname;
109 void *am_attrvalue;
110 __u32 am_length;
111 __u32 am_flags;
112 } xfs_attr_multiop_t;
113
114 typedef struct xfs_fsop_attrmulti_handlereq {
115 struct xfs_fsop_handlereq hreq; /* handle interface structure */
116 __u32 opcount;/* count of following multiop */
117 struct xfs_attr_multiop *ops; /* attr_multi data */
118 } xfs_fsop_attrmulti_handlereq_t;
119
120
121 #include <sys/endian.h>
122 #define __BYTE_ORDER BYTE_ORDER
123 #define __BIG_ENDIAN BIG_ENDIAN
124 #define __LITTLE_ENDIAN LITTLE_ENDIAN
125 #define __swab16(x) (x)
126 #define __swab32(x) (x)
127 #define __swab64(x) (x)
128
129 /* Map some gcc macros for the MipsPRO compiler */
130 #ifndef __GNUC__
131 #define INT_SWAP16(type,var) (var)
132 #define INT_SWAP32(type,var) (var)
133 #define INT_SWAP64(type,var) (var)
134 #define HAVE_SWABMACROS 1 /* no typeof available */
135 #define __builtin_constant_p(x) (0)
136 #define __FUNCTION__ "XFS"
137 #define __sgi__ __sgi
138 #define __inline__ __inline
139 #define inline __inline
140 #endif
141
142 #define constpp char * const *
143
144 /*ARGSUSED*/
145 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *arg)
146 {
147 if (cmd >= 0 && cmd < XFS_FSOPS_COUNT) {
148 /*
149 * We have a problem in that xfsctl takes 1 arg but
150 * some sgi xfs ops take an input arg and/or an output arg
151 * So have to special case the ops to decide if xfsctl arg
152 * is an input or an output argument.
153 */
154 if (cmd == XFS_FS_GOINGDOWN)
155 return syssgi(SGI_XFS_FSOPERATIONS, fd, cmd, arg, 0);
156 return syssgi(SGI_XFS_FSOPERATIONS, fd, cmd, 0, arg);
157 }
158 switch (cmd) {
159 case SGI_FS_INUMBERS:
160 case SGI_FS_BULKSTAT:
161 return syssgi(cmd, fd,
162 ((xfs_fsop_bulkreq_t*)arg)->lastip,
163 ((xfs_fsop_bulkreq_t*)arg)->icount,
164 ((xfs_fsop_bulkreq_t*)arg)->ubuffer,
165 ((xfs_fsop_bulkreq_t*)arg)->ocount);
166 case SGI_FS_BULKSTAT_SINGLE:
167 return syssgi(SGI_FS_BULKSTAT_SINGLE, fd,
168 ((xfs_fsop_bulkreq_t*)arg)->lastip,
169 ((xfs_fsop_bulkreq_t*)arg)->ubuffer);
170 case SGI_XFS_INJECT_ERROR:
171 return syssgi(SGI_XFS_INJECT_ERROR,
172 ((xfs_error_injection_t*)arg)->errtag,
173 fd);
174 case SGI_XFS_CLEARALL_ERROR:
175 return syssgi(SGI_XFS_CLEARALL_ERROR, fd);
176 case SGI_PATH_TO_HANDLE:
177 case SGI_PATH_TO_FSHANDLE:
178 return syssgi(cmd,
179 ((xfs_fsop_handlereq_t*)arg)->path,
180 ((xfs_fsop_handlereq_t*)arg)->ohandle,
181 ((xfs_fsop_handlereq_t*)arg)->ohandlen);
182 case SGI_FD_TO_HANDLE:
183 return syssgi(cmd,
184 ((xfs_fsop_handlereq_t*)arg)->fd,
185 ((xfs_fsop_handlereq_t*)arg)->ohandle,
186 ((xfs_fsop_handlereq_t*)arg)->ohandlen);
187 case SGI_OPEN_BY_HANDLE:
188 return syssgi(cmd,
189 ((xfs_fsop_handlereq_t*)arg)->ihandle,
190 ((xfs_fsop_handlereq_t*)arg)->ihandlen,
191 ((xfs_fsop_handlereq_t*)arg)->oflags);
192 case SGI_READLINK_BY_HANDLE:
193 return syssgi(cmd,
194 ((xfs_fsop_handlereq_t*)arg)->ihandle,
195 ((xfs_fsop_handlereq_t*)arg)->ihandlen,
196 ((xfs_fsop_handlereq_t*)arg)->ohandle,
197 ((xfs_fsop_handlereq_t*)arg)->ohandlen);
198 case SGI_ATTR_LIST_BY_HANDLE:
199 return syssgi(cmd,
200 ((xfs_fsop_attrlist_handlereq_t*)arg)->hreq.ihandle,
201 ((xfs_fsop_attrlist_handlereq_t*)arg)->hreq.ihandlen,
202 ((xfs_fsop_attrlist_handlereq_t*)arg)->buffer,
203 ((xfs_fsop_attrlist_handlereq_t*)arg)->buflen,
204 ((xfs_fsop_attrlist_handlereq_t*)arg)->flags,
205 &(((xfs_fsop_attrlist_handlereq_t*)arg)->pos));
206 case SGI_XFS_GETPARENTS:
207 case SGI_XFS_GETPARENTPATHS:
208 return syssgi(cmd,
209 ((xfs_fsop_getparents_handlereq_t*)arg)->hreq.ihandle,
210 ((xfs_fsop_getparents_handlereq_t*)arg)->hreq.ihandlen,
211 ((xfs_fsop_getparents_handlereq_t*)arg)->buffer,
212 ((xfs_fsop_getparents_handlereq_t*)arg)->buflen,
213 &(((xfs_fsop_getparents_handlereq_t*)arg)->pos),
214 ((xfs_fsop_getparents_handlereq_t*)arg)->ocount,
215 ((xfs_fsop_getparents_handlereq_t*)arg)->omore);
216 case SGI_ATTR_MULTI_BY_HANDLE:
217 return syssgi(cmd,
218 ((xfs_fsop_attrmulti_handlereq_t*)arg)->hreq.ihandle,
219 ((xfs_fsop_attrmulti_handlereq_t*)arg)->hreq.ihandlen,
220 ((xfs_fsop_attrmulti_handlereq_t*)arg)->ops,
221 ((xfs_fsop_attrmulti_handlereq_t*)arg)->opcount,
222 ((xfs_fsop_attrmulti_handlereq_t*)arg)->hreq.oflags);
223 case SGI_FSSETDM_BY_HANDLE:
224 return syssgi(cmd,
225 ((xfs_fsop_setdm_handlereq_t*)arg)->hreq.ihandle,
226 ((xfs_fsop_setdm_handlereq_t*)arg)->hreq.ihandlen,
227 ((xfs_fsop_setdm_handlereq_t*)arg)->data);
228 }
229 return fcntl(fd, cmd, arg);
230 }
231
232 static __inline__ int platform_test_xfs_fd(int fd)
233 {
234 struct statvfs sbuf;
235 if (fstatvfs(fd, &sbuf) < 0)
236 return 0;
237 return strncmp(sbuf.f_basetype, "xfs", 4) == 0;
238 }
239
240 static __inline__ int platform_test_xfs_path(const char *path)
241 {
242 struct statvfs sbuf;
243 if (statvfs(path, &sbuf) < 0)
244 return 0;
245 return strncmp(sbuf.f_basetype, "xfs", 4) == 0;
246 }
247
248 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
249 {
250 return fstatfs(fd, buf, sizeof(struct statfs), 0);
251 }
252
253 static __inline__ void platform_getoptreset(void)
254 {
255 getoptreset();
256 }
257
258 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
259 {
260 uint_t status;
261 return uuid_compare(uu1, uu2, &status);
262 }
263
264 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
265 {
266 uint_t status;
267 char *s;
268 uuid_to_string(uu, &s, &status);
269 if (status == uuid_s_ok)
270 strcpy(buffer, s);
271 else buffer[0] = '\0';
272 free(s);
273 }
274
275 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
276 {
277 uint_t status;
278 uuid_from_string(buffer, uu, &status);
279 return (status == uuid_s_ok);
280 }
281
282 static __inline__ int platform_uuid_is_null(uuid_t *uu)
283 {
284 uint status;
285 return uuid_is_nil(uu, &status);
286 }
287
288 static __inline__ void platform_uuid_generate(uuid_t *uu)
289 {
290 uint_t status;
291 uuid_create(uu, &status);
292 }
293
294 static __inline__ void platform_uuid_clear(uuid_t *uu)
295 {
296 uint_t status;
297 uuid_create_nil(uu, &status);
298 }
299
300 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
301 {
302 memcpy(dst, src, sizeof(uuid_t));
303 }
304
305 static __inline__ char * strsep(char **s, const char *ct)
306 {
307 char *sbegin = *s, *end;
308
309 if (!sbegin)
310 return NULL;
311 end = strpbrk(sbegin, ct);
312 if (end)
313 *end++ = '\0';
314 *s = end;
315 return sbegin;
316 }
317
318 #define HAVE_DIOATTR 1
319 #define HAVE_FSXATTR 1
320 #define HAVE_GETBMAP 1
321 #define HAVE_GETBMAPX 1
322 #define HAVE_FSDMIDATA 1
323 #define HAVE_FID 1
324 #define HAVE_IOCMACROS 1
325 #define HAVE_BBMACROS 1
326
327 #define __XFS_FS_H__ 1
328
329 #define XFS_IOC_DIOINFO F_DIOINFO
330 #define XFS_IOC_FSGETXATTR F_FSGETXATTR
331 #define XFS_IOC_FSSETXATTR F_FSSETXATTR
332 #define XFS_IOC_ALLOCSP64 F_ALLOCSP64
333 #define XFS_IOC_FREESP64 F_FREESP64
334 #define XFS_IOC_GETBMAP F_GETBMAP
335 #define XFS_IOC_FSSETDM F_FSSETDM
336 #define XFS_IOC_RESVSP F_RESVSP
337 #define XFS_IOC_RESVSP64 F_RESVSP64
338 #define XFS_IOC_UNRESVSP F_UNRESVSP
339 #define XFS_IOC_UNRESVSP64 F_UNRESVSP64
340 #define XFS_IOC_GETBMAPA F_GETBMAPA
341 #define XFS_IOC_FSGETXATTRA F_FSGETXATTRA
342 #define XFS_IOC_GETBMAPX F_GETBMAPX
343
344 #define XFS_IOC_FSGEOMETRY_V1 XFS_FS_GEOMETRY
345 #define XFS_IOC_FSBULKSTAT SGI_FS_BULKSTAT
346 #define XFS_IOC_FSBULKSTAT_SINGLE SGI_FS_BULKSTAT_SINGLE
347 #define XFS_IOC_FSINUMBERS SGI_FS_INUMBERS
348 #define XFS_IOC_PATH_TO_FSHANDLE SGI_PATH_TO_FSHANDLE
349 #define XFS_IOC_PATH_TO_HANDLE SGI_PATH_TO_HANDLE
350 #define XFS_IOC_FD_TO_HANDLE SGI_FD_TO_HANDLE
351 #define XFS_IOC_OPEN_BY_HANDLE SGI_OPEN_BY_HANDLE
352 #define XFS_IOC_READLINK_BY_HANDLE SGI_READLINK_BY_HANDLE
353 #define XFS_IOC_SWAPEXT /* TODO */
354 #define XFS_IOC_FSGROWFSDATA XFS_GROWFS_DATA
355 #define XFS_IOC_FSGROWFSLOG XFS_GROWFS_LOG
356 #define XFS_IOC_FSGROWFSRT XFS_GROWFS_RT
357 #define XFS_IOC_FSCOUNTS XFS_FS_COUNTS
358 #define XFS_IOC_SET_RESBLKS XFS_SET_RESBLKS
359 #define XFS_IOC_GET_RESBLKS XFS_GET_RESBLKS
360 #define XFS_IOC_ERROR_INJECTION SGI_XFS_INJECT_ERROR
361 #define XFS_IOC_ERROR_CLEARALL SGI_XFS_CLEARALL_ERROR
362 #define XFS_IOC_FREEZE XFS_FS_FREEZE
363 #define XFS_IOC_THAW XFS_FS_THAW
364 #define XFS_IOC_FSSETDM_BY_HANDLE SGI_FSSETDM_BY_HANDLE
365 #define XFS_IOC_ATTRLIST_BY_HANDLE SGI_ATTR_LIST_BY_HANDLE
366 #define XFS_IOC_ATTRMULTI_BY_HANDLE SGI_ATTR_MULTI_BY_HANDLE
367 #define XFS_IOC_FSGEOMETRY XFS_FS_GEOMETRY
368 #define XFS_IOC_GOINGDOWN XFS_FS_GOINGDOWN
369 #define XFS_IOC_GETPARENTS SGI_XFS_GETPARENTS
370 #define XFS_IOC_GETPARENTPATHS SGI_XFS_GETPARENTPATHS
371
372 #endif /* __XFS_IRIX_H__ */