]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/irix.h
xfs: introduce reflink utility functions
[thirdparty/xfsprogs-dev.git] / include / irix.h
CommitLineData
c0211f67 1/*
714bd9e5 2 * Copyright (c) 2000-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_IRIX_H__
19#define __XFS_IRIX_H__
20
eb0c6f87
TS
21#include <stdlib.h>
22#include <unistd.h>
c0211f67
NS
23#include <libgen.h>
24#include <values.h>
25#include <strings.h>
26#include <inttypes.h>
eb0c6f87
TS
27#include <limits.h>
28#include <fcntl.h>
c0211f67
NS
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>
5ecb3de2 39#include <sys/fs/xfs_itable.h>
7141fc5b 40#include <mntent.h>
c0211f67 41
c0211f67
NS
42#define __int8_t char
43#define __int16_t short
44#define __uint8_t unsigned char
45#define __uint16_t unsigned short
eb0c6f87 46
24842c5c
CH
47typedef unsigned char __u8;
48typedef signed char __s8;
49typedef unsigned short __u16;
50typedef signed short __s16;
51typedef unsigned int __u32;
52typedef signed int __s32;
53typedef unsigned long long int __u64;
54typedef signed long long int __s64;
55
d8079fe0
DW
56typedef off64_t xfs_off_t;
57typedef __int64_t xfs_ino_t;
58typedef __int32_t xfs_dev_t;
59typedef __int64_t xfs_daddr_t;
60typedef __u32 xfs_nlink_t;
61
eb0c6f87
TS
62#define xfs_flock64 flock64
63#define xfs_flock64_t struct flock64
64
99c1ec96
DC
65#define EFSBADCRC 991 /* Bad CRC detected */
66
eb0c6f87 67typedef struct xfs_error_injection {
8967ee43
TS
68 __int32_t fd;
69 __int32_t errtag;
eb0c6f87
TS
70} xfs_error_injection_t;
71
8967ee43 72/* --- xfs_fsop_*req - request data structures --- */
eb0c6f87
TS
73
74typedef struct xfs_fsop_bulkreq {
8967ee43
TS
75 ino64_t *lastip;
76 __int32_t icount;
77 xfs_bstat_t *ubuffer;
78 __int32_t *ocount;
eb0c6f87 79} xfs_fsop_bulkreq_t;
c0211f67 80
8967ee43
TS
81typedef 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
91typedef 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
96typedef struct xfs_attrlist_cursor {
97 __u32 opaque[4];
98} xfs_attrlist_cursor_t;
99
100typedef 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
258b00ea
TS
108typedef 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
8967ee43
TS
117typedef 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
126typedef 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
d3a8db8a
TS
132/* start doing packed stuctures here */
133#define HAVE_FORMAT32 1
134#pragma pack 1
135typedef 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
151typedef struct xfs_extent_32 {
152 __u64 ext_start;
153 __u32 ext_len;
154} xfs_extent_32_t;
155
156typedef 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
164typedef 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 */
8967ee43 174
c0211f67
NS
175#include <sys/endian.h>
176#define __BYTE_ORDER BYTE_ORDER
177#define __BIG_ENDIAN BIG_ENDIAN
178#define __LITTLE_ENDIAN LITTLE_ENDIAN
5ecb3de2
NS
179
180/* Map some gcc macros for the MipsPRO compiler */
181#ifndef __GNUC__
1552a820
NS
182#define __builtin_constant_p(x) (0)
183#define __FUNCTION__ "XFS"
5ecb3de2
NS
184#define __sgi__ __sgi
185#define __inline__ __inline
2a1888c5 186#define inline __inline
5ecb3de2 187#endif
c0211f67 188
8967ee43 189/*ARGSUSED*/
eb0c6f87 190static __inline__ int xfsctl(const char *path, int fd, int cmd, void *arg)
c0211f67 191{
eb0c6f87
TS
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) {
9527f2d5 204 case SGI_FS_INUMBERS:
eb0c6f87 205 case SGI_FS_BULKSTAT:
8967ee43 206 return syssgi(cmd, fd,
eb0c6f87
TS
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:
8967ee43 212 return syssgi(SGI_FS_BULKSTAT_SINGLE, fd,
eb0c6f87
TS
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);
8967ee43
TS
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));
258b00ea
TS
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);
8967ee43
TS
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);
eb0c6f87
TS
273 }
274 return fcntl(fd, cmd, arg);
c0211f67
NS
275}
276
277static __inline__ int platform_test_xfs_fd(int fd)
278{
279 struct statvfs sbuf;
280 if (fstatvfs(fd, &sbuf) < 0)
281 return 0;
714bd9e5 282 return strncmp(sbuf.f_basetype, "xfs", 4) == 0;
c0211f67
NS
283}
284
285static __inline__ int platform_test_xfs_path(const char *path)
286{
287 struct statvfs sbuf;
288 if (statvfs(path, &sbuf) < 0)
289 return 0;
714bd9e5 290 return strncmp(sbuf.f_basetype, "xfs", 4) == 0;
c0211f67
NS
291}
292
293static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
294{
295 return fstatfs(fd, buf, sizeof(struct statfs), 0);
296}
297
298static __inline__ void platform_getoptreset(void)
299{
300 getoptreset();
301}
302
1552a820
NS
303static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
304{
ca50065c 305 __uint32_t status;
1552a820
NS
306 return uuid_compare(uu1, uu2, &status);
307}
308
4d32d744 309static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
1552a820 310{
ca50065c 311 __uint32_t status;
1552a820
NS
312 char *s;
313 uuid_to_string(uu, &s, &status);
314 if (status == uuid_s_ok)
4d32d744
NS
315 strcpy(buffer, s);
316 else buffer[0] = '\0';
1552a820
NS
317 free(s);
318}
319
320static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
321{
ca50065c 322 __uint32_t status;
1552a820
NS
323 uuid_from_string(buffer, uu, &status);
324 return (status == uuid_s_ok);
325}
326
327static __inline__ int platform_uuid_is_null(uuid_t *uu)
328{
329 uint status;
330 return uuid_is_nil(uu, &status);
331}
332
333static __inline__ void platform_uuid_generate(uuid_t *uu)
334{
ca50065c 335 __uint32_t status;
1552a820
NS
336 uuid_create(uu, &status);
337}
338
339static __inline__ void platform_uuid_clear(uuid_t *uu)
340{
ca50065c 341 __uint32_t status;
1552a820
NS
342 uuid_create_nil(uu, &status);
343}
344
345static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
346{
347 memcpy(dst, src, sizeof(uuid_t));
348}
349
ad136b33 350static __inline__ int
f96aff0c 351platform_discard_blocks(int fd, uint64_t start, uint64_t len)
ad136b33
CH
352{
353 return 0;
354}
355
c0211f67
NS
356static __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
5ecb3de2 378#define __XFS_FS_H__ 1
c0211f67
NS
379
380#define XFS_IOC_DIOINFO F_DIOINFO
c0211f67
NS
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
8967ee43 385#define XFS_IOC_RESVSP F_RESVSP
c0211f67 386#define XFS_IOC_RESVSP64 F_RESVSP64
8967ee43 387#define XFS_IOC_UNRESVSP F_UNRESVSP
c0211f67
NS
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
8967ee43 394#define XFS_IOC_FSBULKSTAT SGI_FS_BULKSTAT
eb0c6f87 395#define XFS_IOC_FSBULKSTAT_SINGLE SGI_FS_BULKSTAT_SINGLE
9527f2d5 396#define XFS_IOC_FSINUMBERS SGI_FS_INUMBERS
8967ee43
TS
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
c0211f67
NS
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
eb0c6f87
TS
409#define XFS_IOC_ERROR_INJECTION SGI_XFS_INJECT_ERROR
410#define XFS_IOC_ERROR_CLEARALL SGI_XFS_CLEARALL_ERROR
c0211f67
NS
411#define XFS_IOC_FREEZE XFS_FS_FREEZE
412#define XFS_IOC_THAW XFS_FS_THAW
8967ee43
TS
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
c0211f67
NS
416#define XFS_IOC_FSGEOMETRY XFS_FS_GEOMETRY
417#define XFS_IOC_GOINGDOWN XFS_FS_GOINGDOWN
258b00ea
TS
418#define XFS_IOC_GETPARENTS SGI_XFS_GETPARENTS
419#define XFS_IOC_GETPARENTPATHS SGI_XFS_GETPARENTPATHS
c0211f67 420
cb5b3ef4
MV
421#define _AIOCB64_T_DEFINED 1
422
83f4b5ac
DC
423/* check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves */
424#ifndef HAVE_FSXATTR
425struct 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 unsigned char fsx_pad[12];
431};
432
433/*
434 * Flags for the fsx_xflags field
435 */
436#define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
437#define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
438#define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
439#define FS_XFLAG_APPEND 0x00000010 /* all writes append */
440#define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
441#define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
442#define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
443#define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
444#define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
445#define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
446#define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
447#define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
448#define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
449#define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7093f633 450#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
83f4b5ac
DC
451#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
452
453#define FS_IOC_FSGETXATTR F_FSGETXATTR
454#define FS_IOC_FSSETXATTR F_FSSETXATTR
455
456#endif
457
d3a8db8a 458
7141fc5b
JT
459/**
460 * Abstraction of mountpoints.
461 */
462struct mntent_cursor {
463 FILE *mtabp;
464};
465
466static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
467{
468 cursor->mtabp = setmntent(mtab, "r");
469 if (!cursor->mtabp) {
470 fprintf(stderr, "Error: cannot read %s\n", mtab);
471 return 1;
472 }
473 return 0;
474}
475
476static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
477{
478 return getmntent(cursor->mtabp);
479}
480
481static inline void platform_mntent_close(struct mntent_cursor * cursor)
482{
483 endmntent(cursor->mtabp);
484}
485
486
c0211f67 487#endif /* __XFS_IRIX_H__ */