]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/platform_defs.h
1 // SPDX-License-Identifier: LGPL-2.1
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
6 #ifndef __XFS_PLATFORM_DEFS_H__
7 #define __XFS_PLATFORM_DEFS_H__
21 #include <sys/types.h>
22 #include <sys/param.h>
28 /* long and pointer must be either 32 bit or 64 bit */
29 #define BITS_PER_LONG (sizeof(long) * CHAR_BIT)
31 typedef unsigned short umode_t
;
33 /* Define if you want gettext (I18N) support */
36 # define _(x) gettext(x)
41 # define textdomain(d) do { } while (0)
42 # define bindtextdomain(d,dir) do { } while (0)
46 #define IRIX_DEV_BITSMAJOR 14
47 #define IRIX_DEV_BITSMINOR 18
48 #define IRIX_DEV_MAXMAJ 0x1ff
49 #define IRIX_DEV_MAXMIN 0x3ffff
50 #define IRIX_DEV_MAJOR(dev) ((int)(((unsigned)(dev) >> IRIX_DEV_BITSMINOR) \
52 #define IRIX_DEV_MINOR(dev) ((int)((dev) & IRIX_DEV_MAXMIN))
53 #define IRIX_MKDEV(major,minor) ((xfs_dev_t)(((major) << IRIX_DEV_BITSMINOR) \
54 | (minor&IRIX_DEV_MAXMIN)))
55 #define IRIX_DEV_TO_KDEVT(dev) makedev(IRIX_DEV_MAJOR(dev),IRIX_DEV_MINOR(dev))
58 #define min(a,b) (((a)<(b))?(a):(b))
59 #define max(a,b) (((a)>(b))?(a):(b))
61 #define max3(a,b,c) max(max(a, b), c)
63 /* If param.h doesn't provide it, i.e. for Android */
69 # define ASSERT(EX) assert(EX)
71 # define ASSERT(EX) ((void) 0)
74 extern int platform_nproc(void);
76 #define NSEC_PER_SEC (1000000000ULL)
77 #define NSEC_PER_USEC (1000ULL)
79 /* Simplified from version in include/linux/overflow.h */
82 * Compute a*b+c, returning SIZE_MAX on overflow. Internal helper for
83 * struct_size() below.
85 static inline size_t __ab_c_size(size_t a
, size_t b
, size_t c
)
90 #define __must_be_array(a) (0)
93 * struct_size() - Calculate size of structure with trailing array.
94 * @p: Pointer to the structure.
95 * @member: Name of the array member.
96 * @count: Number of elements in the array.
98 * Calculates size of memory needed for structure @p followed by an
99 * array of @count number of @member elements.
101 * Return: number of bytes needed or SIZE_MAX on overflow.
103 #define struct_size(p, member, count) \
105 sizeof(*(p)->member) + __must_be_array((p)->member), \
109 * struct_size_t() - Calculate size of structure with trailing flexible array
110 * @type: structure type name.
111 * @member: Name of the array member.
112 * @count: Number of elements in the array.
114 * Calculates size of memory needed for structure @type followed by an
115 * array of @count number of @member elements. Prefer using struct_size()
116 * when possible instead, to keep calculations associated with a specific
117 * instance variable of type @type.
119 * Return: number of bytes needed or SIZE_MAX on overflow.
121 #define struct_size_t(type, member, count) \
122 struct_size((type *)NULL, member, count)
125 * Add the pseudo keyword 'fallthrough' so case statement blocks
126 * must end with any of these keywords:
131 * return [expression];
133 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
135 #if defined __has_attribute
136 # if __has_attribute(__fallthrough__)
137 # define fallthrough __attribute__((__fallthrough__))
139 # define fallthrough do {} while (0) /* fallthrough */
142 # define fallthrough do {} while (0) /* fallthrough */
145 /* Only needed for the kernel. */
149 #define __return_address __builtin_return_address(0)
152 * Return the address of a label. Use barrier() so that the optimizer
153 * won't reorder code to refactor the error jumpouts into a single
154 * return, which throws off the reported address.
156 #define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
157 /* Optimization barrier */
159 /* The "volatile" is due to gcc bugs */
160 #define barrier() __asm__ __volatile__("": : :"memory")
163 /* Optimization barrier */
165 # define barrier() __memory_barrier()
168 #endif /* __XFS_PLATFORM_DEFS_H__ */