]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/irix.h
libxcmd: rename args_command to command_iterator
[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 #include <mntent.h>
41
42 #define __int8_t char
43 #define __int16_t short
44 #define __uint8_t unsigned char
45 #define __uint16_t unsigned short
46
47 typedef unsigned char __u8;
48 typedef signed char __s8;
49 typedef unsigned short __u16;
50 typedef signed short __s16;
51 typedef unsigned int __u32;
52 typedef signed int __s32;
53 typedef unsigned long long int __u64;
54 typedef signed long long int __s64;
55
56 typedef off_t xfs_off_t;
57 typedef __int64_t xfs_ino_t;
58 typedef __int32_t xfs_dev_t;
59 typedef __int64_t xfs_daddr_t;
60 typedef __u32 xfs_nlink_t;
61
62 #define xfs_flock64 flock64
63 #define xfs_flock64_t struct flock64
64
65 #define EFSBADCRC 991 /* Bad CRC detected */
66
67 typedef struct xfs_error_injection {
68 __int32_t fd;
69 __int32_t errtag;
70 } xfs_error_injection_t;
71
72 /* --- xfs_fsop_*req - request data structures --- */
73
74 typedef struct xfs_fsop_bulkreq {
75 ino64_t *lastip;
76 __int32_t icount;
77 xfs_bstat_t *ubuffer;
78 __int32_t *ocount;
79 } xfs_fsop_bulkreq_t;
80
81 typedef struct xfs_fsop_handlereq {
82 __u32 fd; /* fd for FD_TO_HANDLE */
83 void *path; /* user pathname */
84 __u32 oflags; /* open flags */
85 void *ihandle; /* user supplied handle */
86 __u32 ihandlen; /* user supplied length */
87 void *ohandle; /* user buffer for handle */
88 __u32 *ohandlen; /* user buffer length */
89 } xfs_fsop_handlereq_t;
90
91 typedef struct xfs_fsop_setdm_handlereq {
92 struct xfs_fsop_handlereq hreq; /* handle information */
93 struct fsdmidata *data; /* DMAPI data */
94 } xfs_fsop_setdm_handlereq_t;
95
96 typedef struct xfs_attrlist_cursor {
97 __u32 opaque[4];
98 } xfs_attrlist_cursor_t;
99
100 typedef struct xfs_fsop_attrlist_handlereq {
101 struct xfs_fsop_handlereq hreq; /* handle interface structure */
102 struct xfs_attrlist_cursor pos; /* opaque cookie, list offset */
103 __u32 flags; /* which namespace to use */
104 __u32 buflen; /* length of buffer supplied */
105 void *buffer; /* returned names */
106 } xfs_fsop_attrlist_handlereq_t;
107
108 typedef struct xfs_fsop_getparents_handlereq {
109 struct xfs_fsop_handlereq hreq; /* handle interface structure */
110 struct xfs_attrlist_cursor pos; /* opaque cookie, list offset */
111 __u32 buflen; /* length of buffer supplied */
112 void *buffer; /* returned data */
113 __u32 *ocount; /* return number of links */
114 __u32 *omore; /* return whether more to come */
115 } xfs_fsop_getparents_handlereq_t;
116
117 typedef struct xfs_attr_multiop {
118 __u32 am_opcode;
119 __s32 am_error;
120 void *am_attrname;
121 void *am_attrvalue;
122 __u32 am_length;
123 __u32 am_flags;
124 } xfs_attr_multiop_t;
125
126 typedef struct xfs_fsop_attrmulti_handlereq {
127 struct xfs_fsop_handlereq hreq; /* handle interface structure */
128 __u32 opcount;/* count of following multiop */
129 struct xfs_attr_multiop *ops; /* attr_multi data */
130 } xfs_fsop_attrmulti_handlereq_t;
131
132 /* start doing packed stuctures here */
133 #define HAVE_FORMAT32 1
134 #pragma pack 1
135 typedef struct xfs_inode_log_format_32 {
136 __u16 ilf_type; /* inode log item type */
137 __u16 ilf_size; /* size of this item */
138 __u32 ilf_fields; /* flags for fields logged */
139 __u16 ilf_asize; /* size of attr d/ext/root */
140 __u16 ilf_dsize; /* size of data/ext/root */
141 __u64 ilf_ino; /* inode number */
142 union {
143 __u32 ilfu_rdev; /* rdev value for dev inode*/
144 uuid_t ilfu_uuid; /* mount point value */
145 } ilf_u;
146 __s64 ilf_blkno; /* blkno of inode buffer */
147 __s32 ilf_len; /* len of inode buffer */
148 __s32 ilf_boffset; /* off of inode in buffer */
149 } xfs_inode_log_format_32_t;
150
151 typedef struct xfs_extent_32 {
152 __u64 ext_start;
153 __u32 ext_len;
154 } xfs_extent_32_t;
155
156 typedef struct xfs_efi_log_format_32 {
157 __u16 efi_type; /* efi log item type */
158 __u16 efi_size; /* size of this item */
159 __u32 efi_nextents; /* # extents to free */
160 __u64 efi_id; /* efi identifier */
161 xfs_extent_32_t efi_extents[1]; /* array of extents to free */
162 } xfs_efi_log_format_32_t;
163
164 typedef struct xfs_efd_log_format_32 {
165 __u16 efd_type; /* efd log item type */
166 __u16 efd_size; /* size of this item */
167 __u32 efd_nextents; /* # of extents freed */
168 __u64 efd_efi_id; /* id of corresponding efi */
169 xfs_extent_32_t efd_extents[1]; /* array of extents freed */
170 } xfs_efd_log_format_32_t;
171
172 #pragma pack 0
173 /* end of packed stuctures */
174
175 #include <sys/endian.h>
176 #define __BYTE_ORDER BYTE_ORDER
177 #define __BIG_ENDIAN BIG_ENDIAN
178 #define __LITTLE_ENDIAN LITTLE_ENDIAN
179
180 /* Map some gcc macros for the MipsPRO compiler */
181 #ifndef __GNUC__
182 #define __builtin_constant_p(x) (0)
183 #define __FUNCTION__ "XFS"
184 #define __sgi__ __sgi
185 #define __inline__ __inline
186 #define inline __inline
187 #endif
188
189 /*ARGSUSED*/
190 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *arg)
191 {
192 if (cmd >= 0 && cmd < XFS_FSOPS_COUNT) {
193 /*
194 * We have a problem in that xfsctl takes 1 arg but
195 * some sgi xfs ops take an input arg and/or an output arg
196 * So have to special case the ops to decide if xfsctl arg
197 * is an input or an output argument.
198 */
199 if (cmd == XFS_FS_GOINGDOWN)
200 return syssgi(SGI_XFS_FSOPERATIONS, fd, cmd, arg, 0);
201 return syssgi(SGI_XFS_FSOPERATIONS, fd, cmd, 0, arg);
202 }
203 switch (cmd) {
204 case SGI_FS_INUMBERS:
205 case SGI_FS_BULKSTAT:
206 return syssgi(cmd, fd,
207 ((xfs_fsop_bulkreq_t*)arg)->lastip,
208 ((xfs_fsop_bulkreq_t*)arg)->icount,
209 ((xfs_fsop_bulkreq_t*)arg)->ubuffer,
210 ((xfs_fsop_bulkreq_t*)arg)->ocount);
211 case SGI_FS_BULKSTAT_SINGLE:
212 return syssgi(SGI_FS_BULKSTAT_SINGLE, fd,
213 ((xfs_fsop_bulkreq_t*)arg)->lastip,
214 ((xfs_fsop_bulkreq_t*)arg)->ubuffer);
215 case SGI_XFS_INJECT_ERROR:
216 return syssgi(SGI_XFS_INJECT_ERROR,
217 ((xfs_error_injection_t*)arg)->errtag,
218 fd);
219 case SGI_XFS_CLEARALL_ERROR:
220 return syssgi(SGI_XFS_CLEARALL_ERROR, fd);
221 case SGI_PATH_TO_HANDLE:
222 case SGI_PATH_TO_FSHANDLE:
223 return syssgi(cmd,
224 ((xfs_fsop_handlereq_t*)arg)->path,
225 ((xfs_fsop_handlereq_t*)arg)->ohandle,
226 ((xfs_fsop_handlereq_t*)arg)->ohandlen);
227 case SGI_FD_TO_HANDLE:
228 return syssgi(cmd,
229 ((xfs_fsop_handlereq_t*)arg)->fd,
230 ((xfs_fsop_handlereq_t*)arg)->ohandle,
231 ((xfs_fsop_handlereq_t*)arg)->ohandlen);
232 case SGI_OPEN_BY_HANDLE:
233 return syssgi(cmd,
234 ((xfs_fsop_handlereq_t*)arg)->ihandle,
235 ((xfs_fsop_handlereq_t*)arg)->ihandlen,
236 ((xfs_fsop_handlereq_t*)arg)->oflags);
237 case SGI_READLINK_BY_HANDLE:
238 return syssgi(cmd,
239 ((xfs_fsop_handlereq_t*)arg)->ihandle,
240 ((xfs_fsop_handlereq_t*)arg)->ihandlen,
241 ((xfs_fsop_handlereq_t*)arg)->ohandle,
242 ((xfs_fsop_handlereq_t*)arg)->ohandlen);
243 case SGI_ATTR_LIST_BY_HANDLE:
244 return syssgi(cmd,
245 ((xfs_fsop_attrlist_handlereq_t*)arg)->hreq.ihandle,
246 ((xfs_fsop_attrlist_handlereq_t*)arg)->hreq.ihandlen,
247 ((xfs_fsop_attrlist_handlereq_t*)arg)->buffer,
248 ((xfs_fsop_attrlist_handlereq_t*)arg)->buflen,
249 ((xfs_fsop_attrlist_handlereq_t*)arg)->flags,
250 &(((xfs_fsop_attrlist_handlereq_t*)arg)->pos));
251 case SGI_XFS_GETPARENTS:
252 case SGI_XFS_GETPARENTPATHS:
253 return syssgi(cmd,
254 ((xfs_fsop_getparents_handlereq_t*)arg)->hreq.ihandle,
255 ((xfs_fsop_getparents_handlereq_t*)arg)->hreq.ihandlen,
256 ((xfs_fsop_getparents_handlereq_t*)arg)->buffer,
257 ((xfs_fsop_getparents_handlereq_t*)arg)->buflen,
258 &(((xfs_fsop_getparents_handlereq_t*)arg)->pos),
259 ((xfs_fsop_getparents_handlereq_t*)arg)->ocount,
260 ((xfs_fsop_getparents_handlereq_t*)arg)->omore);
261 case SGI_ATTR_MULTI_BY_HANDLE:
262 return syssgi(cmd,
263 ((xfs_fsop_attrmulti_handlereq_t*)arg)->hreq.ihandle,
264 ((xfs_fsop_attrmulti_handlereq_t*)arg)->hreq.ihandlen,
265 ((xfs_fsop_attrmulti_handlereq_t*)arg)->ops,
266 ((xfs_fsop_attrmulti_handlereq_t*)arg)->opcount,
267 ((xfs_fsop_attrmulti_handlereq_t*)arg)->hreq.oflags);
268 case SGI_FSSETDM_BY_HANDLE:
269 return syssgi(cmd,
270 ((xfs_fsop_setdm_handlereq_t*)arg)->hreq.ihandle,
271 ((xfs_fsop_setdm_handlereq_t*)arg)->hreq.ihandlen,
272 ((xfs_fsop_setdm_handlereq_t*)arg)->data);
273 }
274 return fcntl(fd, cmd, arg);
275 }
276
277 static __inline__ int platform_test_xfs_fd(int fd)
278 {
279 struct statvfs sbuf;
280 if (fstatvfs(fd, &sbuf) < 0)
281 return 0;
282 return strncmp(sbuf.f_basetype, "xfs", 4) == 0;
283 }
284
285 static __inline__ int platform_test_xfs_path(const char *path)
286 {
287 struct statvfs sbuf;
288 if (statvfs(path, &sbuf) < 0)
289 return 0;
290 return strncmp(sbuf.f_basetype, "xfs", 4) == 0;
291 }
292
293 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
294 {
295 return fstatfs(fd, buf, sizeof(struct statfs), 0);
296 }
297
298 static __inline__ void platform_getoptreset(void)
299 {
300 getoptreset();
301 }
302
303 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
304 {
305 __uint32_t status;
306 return uuid_compare(uu1, uu2, &status);
307 }
308
309 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
310 {
311 __uint32_t status;
312 char *s;
313 uuid_to_string(uu, &s, &status);
314 if (status == uuid_s_ok)
315 strcpy(buffer, s);
316 else buffer[0] = '\0';
317 free(s);
318 }
319
320 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
321 {
322 __uint32_t status;
323 uuid_from_string(buffer, uu, &status);
324 return (status == uuid_s_ok);
325 }
326
327 static __inline__ int platform_uuid_is_null(uuid_t *uu)
328 {
329 uint status;
330 return uuid_is_nil(uu, &status);
331 }
332
333 static __inline__ void platform_uuid_generate(uuid_t *uu)
334 {
335 __uint32_t status;
336 uuid_create(uu, &status);
337 }
338
339 static __inline__ void platform_uuid_clear(uuid_t *uu)
340 {
341 __uint32_t status;
342 uuid_create_nil(uu, &status);
343 }
344
345 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
346 {
347 memcpy(dst, src, sizeof(uuid_t));
348 }
349
350 static __inline__ int
351 platform_discard_blocks(int fd, uint64_t start, uint64_t len)
352 {
353 return 0;
354 }
355
356 static __inline__ char * strsep(char **s, const char *ct)
357 {
358 char *sbegin = *s, *end;
359
360 if (!sbegin)
361 return NULL;
362 end = strpbrk(sbegin, ct);
363 if (end)
364 *end++ = '\0';
365 *s = end;
366 return sbegin;
367 }
368
369 #define HAVE_DIOATTR 1
370 #define HAVE_FSXATTR 1
371 #define HAVE_GETBMAP 1
372 #define HAVE_GETBMAPX 1
373 #define HAVE_FSDMIDATA 1
374 #define HAVE_FID 1
375 #define HAVE_IOCMACROS 1
376 #define HAVE_BBMACROS 1
377
378 #define __XFS_FS_H__ 1
379
380 #define XFS_IOC_DIOINFO F_DIOINFO
381 #define XFS_IOC_ALLOCSP64 F_ALLOCSP64
382 #define XFS_IOC_FREESP64 F_FREESP64
383 #define XFS_IOC_GETBMAP F_GETBMAP
384 #define XFS_IOC_FSSETDM F_FSSETDM
385 #define XFS_IOC_RESVSP F_RESVSP
386 #define XFS_IOC_RESVSP64 F_RESVSP64
387 #define XFS_IOC_UNRESVSP F_UNRESVSP
388 #define XFS_IOC_UNRESVSP64 F_UNRESVSP64
389 #define XFS_IOC_GETBMAPA F_GETBMAPA
390 #define XFS_IOC_FSGETXATTRA F_FSGETXATTRA
391 #define XFS_IOC_GETBMAPX F_GETBMAPX
392
393 #define XFS_IOC_FSGEOMETRY_V1 XFS_FS_GEOMETRY
394 #define XFS_IOC_FSBULKSTAT SGI_FS_BULKSTAT
395 #define XFS_IOC_FSBULKSTAT_SINGLE SGI_FS_BULKSTAT_SINGLE
396 #define XFS_IOC_FSINUMBERS SGI_FS_INUMBERS
397 #define XFS_IOC_PATH_TO_FSHANDLE SGI_PATH_TO_FSHANDLE
398 #define XFS_IOC_PATH_TO_HANDLE SGI_PATH_TO_HANDLE
399 #define XFS_IOC_FD_TO_HANDLE SGI_FD_TO_HANDLE
400 #define XFS_IOC_OPEN_BY_HANDLE SGI_OPEN_BY_HANDLE
401 #define XFS_IOC_READLINK_BY_HANDLE SGI_READLINK_BY_HANDLE
402 #define XFS_IOC_SWAPEXT /* TODO */
403 #define XFS_IOC_FSGROWFSDATA XFS_GROWFS_DATA
404 #define XFS_IOC_FSGROWFSLOG XFS_GROWFS_LOG
405 #define XFS_IOC_FSGROWFSRT XFS_GROWFS_RT
406 #define XFS_IOC_FSCOUNTS XFS_FS_COUNTS
407 #define XFS_IOC_SET_RESBLKS XFS_SET_RESBLKS
408 #define XFS_IOC_GET_RESBLKS XFS_GET_RESBLKS
409 #define XFS_IOC_ERROR_INJECTION SGI_XFS_INJECT_ERROR
410 #define XFS_IOC_ERROR_CLEARALL SGI_XFS_CLEARALL_ERROR
411 #define XFS_IOC_FREEZE XFS_FS_FREEZE
412 #define XFS_IOC_THAW XFS_FS_THAW
413 #define XFS_IOC_FSSETDM_BY_HANDLE SGI_FSSETDM_BY_HANDLE
414 #define XFS_IOC_ATTRLIST_BY_HANDLE SGI_ATTR_LIST_BY_HANDLE
415 #define XFS_IOC_ATTRMULTI_BY_HANDLE SGI_ATTR_MULTI_BY_HANDLE
416 #define XFS_IOC_FSGEOMETRY XFS_FS_GEOMETRY
417 #define XFS_IOC_GOINGDOWN XFS_FS_GOINGDOWN
418 #define XFS_IOC_GETPARENTS SGI_XFS_GETPARENTS
419 #define XFS_IOC_GETPARENTPATHS SGI_XFS_GETPARENTPATHS
420
421 #define _AIOCB64_T_DEFINED 1
422
423 /* check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves */
424 #ifndef HAVE_FSXATTR
425 struct fsxattr {
426 __u32 fsx_xflags; /* xflags field value (get/set) */
427 __u32 fsx_extsize; /* extsize field value (get/set)*/
428 __u32 fsx_nextents; /* nextents field value (get) */
429 __u32 fsx_projid; /* project identifier (get/set) */
430 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
431 unsigned char fsx_pad[8];
432 };
433
434 /*
435 * Flags for the fsx_xflags field
436 */
437 #define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
438 #define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
439 #define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
440 #define FS_XFLAG_APPEND 0x00000010 /* all writes append */
441 #define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
442 #define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
443 #define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
444 #define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
445 #define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
446 #define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
447 #define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
448 #define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
449 #define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
450 #define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
451 #define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
452 #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
453
454 #define FS_IOC_FSGETXATTR F_FSGETXATTR
455 #define FS_IOC_FSSETXATTR F_FSSETXATTR
456
457 #endif
458
459 #ifndef FS_XFLAG_COWEXTSIZE
460 #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
461 #endif
462
463 /**
464 * Abstraction of mountpoints.
465 */
466 struct mntent_cursor {
467 FILE *mtabp;
468 };
469
470 static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
471 {
472 cursor->mtabp = setmntent(mtab, "r");
473 if (!cursor->mtabp) {
474 fprintf(stderr, "Error: cannot read %s\n", mtab);
475 return 1;
476 }
477 return 0;
478 }
479
480 static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
481 {
482 return getmntent(cursor->mtabp);
483 }
484
485 static inline void platform_mntent_close(struct mntent_cursor * cursor)
486 {
487 endmntent(cursor->mtabp);
488 }
489
490
491 #endif /* __XFS_IRIX_H__ */