]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/platform_defs.h.in
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / include / platform_defs.h.in
CommitLineData
2bd0ea18 1/*
93d9f139 2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
2bd0ea18
NS
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 *
32 * @configure_input@
33 */
34#ifndef __XFS_PLATFORM_DEFS_H__
35#define __XFS_PLATFORM_DEFS_H__
36
37#include <stdio.h>
6bef826c
NS
38#include <errno.h>
39#include <fcntl.h>
b26ade3f 40#include <stdarg.h>
2bd0ea18 41#include <assert.h>
2bd0ea18
NS
42#include <stddef.h>
43#include <stdlib.h>
44#include <string.h>
45#include <unistd.h>
2bd0ea18 46#include <sys/types.h>
93d9f139 47#include <uuid/uuid.h>
6bef826c 48
1707056a 49
6bef826c
NS
50#if defined(__linux__)
51
52#include <sys/vfs.h>
8eb24471 53#include <sys/ioctl.h>
6bef826c 54#include <sys/param.h>
6bef826c
NS
55#include <linux/types.h>
56#include <malloc.h>
57#include <getopt.h>
6bef826c 58#include <endian.h>
9440d84d 59#include "swab.h"
f91dde66 60
93d9f139
NS
61static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
62{
63 return ioctl(fd, cmd, p);
64}
65
66static __inline__ int platform_test_xfs_fd(int fd)
67{
68 struct statfs buf;
69 if (fstatfs(fd, &buf) < 0)
70 return 0;
71 return (buf.f_type == 0x58465342); /* XFSB */
72}
73
74static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
75{
76 return fstatfs(fd, buf);
77}
78
f91dde66
NS
79#ifndef O_DIRECT
80# if defined (__powerpc__)
81# define O_DIRECT 0400000
82# elif defined (__sparc__)
61ecf6c2
NS
83# define O_DIRECT 0x100000
84# endif
85#endif
86
f91dde66
NS
87#if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 1))
88# define constpp const char * const *
89#else
90# define constpp char * const *
91#endif
92
6bef826c
NS
93#define ENOATTR ENODATA /* Attribute not found */
94#define EFSCORRUPTED 990 /* Filesystem is corrupted */
6bef826c 95
2bd0ea18
NS
96typedef loff_t xfs_off_t;
97typedef __uint64_t xfs_ino_t;
98typedef __uint32_t xfs_dev_t;
99typedef __int64_t xfs_daddr_t;
100typedef char* xfs_caddr_t;
101
eebd842d 102#ifndef _UCHAR_T_DEFINED
43a8fc1e 103typedef unsigned char uchar_t;
eebd842d
MK
104#define _UCHAR_T_DEFINED 1
105#endif
6bef826c
NS
106typedef enum { B_FALSE,B_TRUE } boolean_t;
107
1707056a 108
4f1631ae 109#elif defined(__FreeBSD__)
1707056a 110
4f1631ae
RC
111#include <sys/stat.h>
112#include <libgen.h>
113#include <machine/endian.h>
114#include <sys/param.h>
115#include <paths.h>
116#include <ctype.h>
1707056a 117
4f1631ae
RC
118/* FreeBSD file API is 64-bit aware */
119#define fstat64 fstat
120#define ftruncate64 ftruncate
121#define lseek64 lseek
122#define stat64 stat
123#define pwrite64 pwrite
124#define pread64 pread
125#define memalign(a,size) valloc(size)
126
127typedef u_int8_t __u8;
128typedef int8_t __s8;
129typedef u_int16_t __u16;
130typedef int16_t __s16;
131typedef u_int32_t __u32;
132typedef int32_t __s32;
133typedef u_int64_t __u64;
134typedef int64_t __s64;
135
136#define constpp char * const *
137
138#define EFSCORRUPTED 990 /* Filesystem is corrupted */
139
140typedef off_t xfs_off_t;
141typedef __uint64_t xfs_ino_t;
142typedef __uint32_t xfs_dev_t;
143typedef __int64_t xfs_daddr_t;
144typedef char* xfs_caddr_t;
145
4f1631ae
RC
146#ifndef _UCHAR_T_DEFINED
147typedef unsigned char uchar_t;
148#define _UCHAR_T_DEFINED 1
149#endif
150typedef enum { B_FALSE,B_TRUE } boolean_t;
1707056a 151
4f1631ae 152#define HAVE_FID 1
1707056a 153#define HAVE_SWABMACROS 1
408df2f0
RC
154#define INT_SWAP16(type,var) ((typeof(type))(__bswap16((__u16)(var))))
155#define INT_SWAP32(type,var) ((typeof(type))(__bswap32((__u32)(var))))
156#define INT_SWAP64(type,var) ((typeof(type))(__bswap64((__u64)(var))))
1707056a 157
93d9f139
NS
158
159#elif defined(__APPLE__) /* Darwin */
160
161#include <libgen.h>
162#include <sys/vm.h>
163#include <sys/stat.h>
164#include <sys/ioctl.h>
165#include <sys/mount.h>
166
167#include <sys/syscall.h>
4f1631ae
RC
168# ifndef SYS_fsctl
169# define SYS_fsctl 242
170# endif
93d9f139
NS
171static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
172{
173 return syscall(SYS_fsctl, path, cmd, p, 0);
174}
175
176static __inline__ int platform_test_xfs_fd(int fd)
177{
178 struct statfs buf;
179 if (fstatfs(fd, &buf) < 0)
180 return 0;
181 return (strcmp(buf.f_fstypename, "xfs") == 0);
182}
183
184static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
185{
186 return fstatfs(fd, buf);
187}
188
189#define __int8_t int8_t
190#define __int16_t int16_t
191#define __int32_t int32_t
192#define __int32_t int32_t
193#define __int64_t int64_t
194#define __uint8_t u_int8_t
195#define __uint16_t u_int16_t
196#define __uint32_t u_int32_t
197#define __uint64_t u_int64_t
198#define __s8 int8_t
199#define __s16 int16_t
200#define __s32 int32_t
201#define __s64 int64_t
202#define __u8 u_int8_t
203#define __u16 u_int16_t
204#define __u32 u_int32_t
205#define __u64 u_int64_t
206#define loff_t off_t
207#define off64_t off_t
208
209typedef off_t xfs_off_t;
210typedef u_int64_t xfs_ino_t;
211typedef u_int32_t xfs_dev_t;
212typedef int64_t xfs_daddr_t;
213typedef char* xfs_caddr_t;
214
215typedef unsigned char uchar_t;
216#define stat64 stat
217#define fstat64 fstat
218#define lseek64 lseek
219#define pread64 pread
220#define pwrite64 pwrite
221#define ftruncate64 ftruncate
222#define fdatasync fsync
223#define memalign(a,sz) malloc(sz)
224
225#include <machine/endian.h>
226#define __BYTE_ORDER BYTE_ORDER
227#define __BIG_ENDIAN BIG_ENDIAN
228#define __LITTLE_ENDIAN LITTLE_ENDIAN
229#include "swab.h"
230
231#define O_LARGEFILE 0
dfc130f3 232#ifndef O_DIRECT
93d9f139
NS
233#define O_DIRECT 0
234#endif
235#ifndef O_SYNC
236#define O_SYNC 0
237#endif
238
239#define B_FALSE 0
240#define B_TRUE 1
241
242#define ENOATTR 989 /* Attribute not found */
243#define EFSCORRUPTED 990 /* Filesystem is corrupted */
244#define constpp char * const *
245
246#define HAVE_FID 1
247
248
249#elif defined(__sgi__) /* SGI IRIX */
250
251#include <libgen.h>
252#include <values.h>
253#include <strings.h>
254#include <inttypes.h>
255#include <sys/stat.h>
256#include <sys/param.h>
257#include <sys/ioctl.h>
258#include <sys/types.h>
259#include <sys/statfs.h>
260#include <sys/statvfs.h>
261#include <sys/sysmacros.h>
262
263#define __s8 char
264#define __s16 short
265#define __s32 __int32_t
266#define __s64 __int64_t
267#define __u8 unsigned char
268#define __u16 unsigned short
269#define __u32 __int32_t
270#define __u64 __int64_t
271#define __int8_t char
272#define __int16_t short
273#define __uint8_t unsigned char
274#define __uint16_t unsigned short
275#define loff_t off64_t
276typedef off64_t xfs_off_t;
277typedef __int64_t xfs_ino_t;
278typedef __int32_t xfs_dev_t;
279typedef __int64_t xfs_daddr_t;
280typedef char* xfs_caddr_t;
281
282#include <sys/endian.h>
283#define __BYTE_ORDER BYTE_ORDER
284#define __BIG_ENDIAN BIG_ENDIAN
285#define __LITTLE_ENDIAN LITTLE_ENDIAN
286#include "swab.h"
287
288#define INT_MAX INT32_MAX
289#define UINT_MAX UINT32_MAX
290#define PATH_MAX MAXPATHLEN
291#define constpp char * const *
292#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
293
294static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
295{
dfc130f3 296 fprintf(stderr, "%s: line %d syssgi/fcntl mapping not implemented\n",
93d9f139
NS
297 __FILE__, __LINE__);
298 errno = ENOSYS;
299 return -1;
300}
301
302static __inline__ int platform_test_xfs_fd(int fd)
303{
304 struct statvfs sbuf;
305 if (fstatvfs(fd, &sbuf) < 0)
306 return 0;
307 return (strcmp(sbuf.f_basetype, "xfs") == 0);
308}
309
310static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
311{
312 return fstatfs(fd, buf, sizeof(struct statfs), 0);
313}
314
315static __inline__ char * strsep(char **s, const char *ct)
316{
dfc130f3
RC
317 char *sbegin = *s, *end;
318
319 if (!sbegin)
320 return NULL;
321 end = strpbrk(sbegin, ct);
322 if (end)
323 *end++ = '\0';
324 *s = end;
325 return sbegin;
93d9f139
NS
326}
327
328#define HAVE_DIOATTR 1
329#define HAVE_FSXATTR 1
330#define HAVE_GETBMAP 1
331#define HAVE_GETBMAPX 1
332#define HAVE_FSDMIDATA 1
333#define HAVE_FID 1
334#define HAVE_BBMACROS 1
335
336
337#else
338# error unknown platform... have fun porting!
6bef826c
NS
339#endif
340
43a8fc1e 341
2bd0ea18 342/* long and pointer must be either 32 bit or 64 bit */
2bd0ea18 343#undef HAVE_32BIT_LONG
044fe078 344#undef HAVE_64BIT_LONG
2bd0ea18
NS
345#undef HAVE_32BIT_PTR
346#undef HAVE_64BIT_PTR
347
044fe078
NS
348#if defined(HAVE_32BIT_LONG)
349# define BITS_PER_LONG 32
350#elif defined(HAVE_64BIT_LONG)
351# define BITS_PER_LONG 64
352#else
353# error Unknown long size
354#endif
355
2bd0ea18
NS
356/* Check if __psint_t is set to something meaningful */
357#undef HAVE___PSINT_T
358#ifndef HAVE___PSINT_T
359# ifdef HAVE_32BIT_PTR
360typedef int __psint_t;
361# elif defined HAVE_64BIT_PTR
362# ifdef HAVE_64BIT_LONG
363typedef long __psint_t;
364# else
9440d84d
NS
365/* This is a very strange architecture, which has 64 bit pointers but */
366/* not 64 bit longs. So, just punt here and assume long long is OK. */
2bd0ea18
NS
367typedef long long __psint_t;
368# endif
369# else
370# error Unknown pointer size
371# endif
372#endif
373
374/* Check if __psunsigned_t is set to something meaningful */
375#undef HAVE___PSUNSIGNED_T
376#ifndef HAVE___PSUNSIGNED_T
377# ifdef HAVE_32BIT_PTR
378typedef unsigned int __psunsigned_t;
379# elif defined HAVE_64BIT_PTR
380# ifdef HAVE_64BIT_LONG
381typedef long __psunsigned_t;
382# else
9440d84d
NS
383/* This is a very strange architecture, which has 64 bit pointers but */
384/* not 64 bit longs. So, just punt here and assume long long is OK. */
2bd0ea18
NS
385typedef unsigned long long __psunsigned_t;
386# endif
387# else
388# error Unknown pointer size
389# endif
390#endif
391
9440d84d
NS
392/* Define if you want gettext (I18N) support */
393#undef ENABLE_GETTEXT
394#ifdef ENABLE_GETTEXT
395# include <libintl.h>
396# define _(x) gettext(x)
397#else
398# define _(x) (x)
399# define textdomain(d) do { } while (0)
400# define bindtextdomain(d,dir) do { } while (0)
401#endif
6ef2febc 402#include <locale.h>
9440d84d 403
2bd0ea18
NS
404#ifdef DEBUG
405# define ASSERT assert
406#else
407# define ASSERT(EX) ((void) 0)
408#endif
409
32181a02
NS
410#define IRIX_DEV_BITSMAJOR 14
411#define IRIX_DEV_BITSMINOR 18
412#define IRIX_DEV_MAXMAJ 0x1ff
413#define IRIX_DEV_MAXMIN 0x3ffff
414#define IRIX_DEV_MAJOR(dev) ((int)(((unsigned)(dev) >> IRIX_DEV_BITSMINOR) \
415 & IRIX_DEV_MAXMAJ))
416#define IRIX_DEV_MINOR(dev) ((int)((dev) & IRIX_DEV_MAXMIN))
417#define IRIX_MKDEV(major,minor) ((dev_t)(((major) << IRIX_DEV_BITSMINOR) \
418 | (minor&IRIX_DEV_MAXMIN)))
419#define IRIX_DEV_TO_KDEVT(dev) makedev(IRIX_DEV_MAJOR(dev),IRIX_DEV_MINOR(dev))
420
2bd0ea18 421#endif /* __XFS_PLATFORM_DEFS_H__ */