xref: /linux-6.15/include/linux/types.h (revision 6482f554)
1 #ifndef _LINUX_TYPES_H
2 #define _LINUX_TYPES_H
3 
4 #include <asm/types.h>
5 
6 #ifndef __ASSEMBLY__
7 #ifdef	__KERNEL__
8 
9 #define DECLARE_BITMAP(name,bits) \
10 	unsigned long name[BITS_TO_LONGS(bits)]
11 #else
12 #ifndef __EXPORTED_HEADERS__
13 #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders"
14 #endif /* __EXPORTED_HEADERS__ */
15 #endif
16 
17 #include <linux/posix_types.h>
18 
19 #ifdef __KERNEL__
20 
21 typedef __u32 __kernel_dev_t;
22 
23 typedef __kernel_fd_set		fd_set;
24 typedef __kernel_dev_t		dev_t;
25 typedef __kernel_ino_t		ino_t;
26 typedef __kernel_mode_t		mode_t;
27 typedef __kernel_nlink_t	nlink_t;
28 typedef __kernel_off_t		off_t;
29 typedef __kernel_pid_t		pid_t;
30 typedef __kernel_daddr_t	daddr_t;
31 typedef __kernel_key_t		key_t;
32 typedef __kernel_suseconds_t	suseconds_t;
33 typedef __kernel_timer_t	timer_t;
34 typedef __kernel_clockid_t	clockid_t;
35 typedef __kernel_mqd_t		mqd_t;
36 
37 typedef _Bool			bool;
38 
39 typedef __kernel_uid32_t	uid_t;
40 typedef __kernel_gid32_t	gid_t;
41 typedef __kernel_uid16_t        uid16_t;
42 typedef __kernel_gid16_t        gid16_t;
43 
44 typedef unsigned long		uintptr_t;
45 
46 #ifdef CONFIG_UID16
47 /* This is defined by include/asm-{arch}/posix_types.h */
48 typedef __kernel_old_uid_t	old_uid_t;
49 typedef __kernel_old_gid_t	old_gid_t;
50 #endif /* CONFIG_UID16 */
51 
52 #if defined(__GNUC__)
53 typedef __kernel_loff_t		loff_t;
54 #endif
55 
56 /*
57  * The following typedefs are also protected by individual ifdefs for
58  * historical reasons:
59  */
60 #ifndef _SIZE_T
61 #define _SIZE_T
62 typedef __kernel_size_t		size_t;
63 #endif
64 
65 #ifndef _SSIZE_T
66 #define _SSIZE_T
67 typedef __kernel_ssize_t	ssize_t;
68 #endif
69 
70 #ifndef _PTRDIFF_T
71 #define _PTRDIFF_T
72 typedef __kernel_ptrdiff_t	ptrdiff_t;
73 #endif
74 
75 #ifndef _TIME_T
76 #define _TIME_T
77 typedef __kernel_time_t		time_t;
78 #endif
79 
80 #ifndef _CLOCK_T
81 #define _CLOCK_T
82 typedef __kernel_clock_t	clock_t;
83 #endif
84 
85 #ifndef _CADDR_T
86 #define _CADDR_T
87 typedef __kernel_caddr_t	caddr_t;
88 #endif
89 
90 /* bsd */
91 typedef unsigned char		u_char;
92 typedef unsigned short		u_short;
93 typedef unsigned int		u_int;
94 typedef unsigned long		u_long;
95 
96 /* sysv */
97 typedef unsigned char		unchar;
98 typedef unsigned short		ushort;
99 typedef unsigned int		uint;
100 typedef unsigned long		ulong;
101 
102 #ifndef __BIT_TYPES_DEFINED__
103 #define __BIT_TYPES_DEFINED__
104 
105 typedef		__u8		u_int8_t;
106 typedef		__s8		int8_t;
107 typedef		__u16		u_int16_t;
108 typedef		__s16		int16_t;
109 typedef		__u32		u_int32_t;
110 typedef		__s32		int32_t;
111 
112 #endif /* !(__BIT_TYPES_DEFINED__) */
113 
114 typedef		__u8		uint8_t;
115 typedef		__u16		uint16_t;
116 typedef		__u32		uint32_t;
117 
118 #if defined(__GNUC__)
119 typedef		__u64		uint64_t;
120 typedef		__u64		u_int64_t;
121 typedef		__s64		int64_t;
122 #endif
123 
124 /* this is a special 64bit data type that is 8-byte aligned */
125 #define aligned_u64 __u64 __attribute__((aligned(8)))
126 #define aligned_be64 __be64 __attribute__((aligned(8)))
127 #define aligned_le64 __le64 __attribute__((aligned(8)))
128 
129 /**
130  * The type used for indexing onto a disc or disc partition.
131  *
132  * Linux always considers sectors to be 512 bytes long independently
133  * of the devices real block size.
134  *
135  * blkcnt_t is the type of the inode's block count.
136  */
137 #ifdef CONFIG_LBDAF
138 typedef u64 sector_t;
139 typedef u64 blkcnt_t;
140 #else
141 typedef unsigned long sector_t;
142 typedef unsigned long blkcnt_t;
143 #endif
144 
145 /*
146  * The type of an index into the pagecache.  Use a #define so asm/types.h
147  * can override it.
148  */
149 #ifndef pgoff_t
150 #define pgoff_t unsigned long
151 #endif
152 
153 #endif /* __KERNEL__ */
154 
155 /*
156  * Below are truly Linux-specific types that should never collide with
157  * any application/library that wants linux/types.h.
158  */
159 
160 #ifdef __CHECKER__
161 #define __bitwise__ __attribute__((bitwise))
162 #else
163 #define __bitwise__
164 #endif
165 #ifdef __CHECK_ENDIAN__
166 #define __bitwise __bitwise__
167 #else
168 #define __bitwise
169 #endif
170 
171 typedef __u16 __bitwise __le16;
172 typedef __u16 __bitwise __be16;
173 typedef __u32 __bitwise __le32;
174 typedef __u32 __bitwise __be32;
175 typedef __u64 __bitwise __le64;
176 typedef __u64 __bitwise __be64;
177 
178 typedef __u16 __bitwise __sum16;
179 typedef __u32 __bitwise __wsum;
180 
181 #ifdef __KERNEL__
182 typedef unsigned __bitwise__ gfp_t;
183 typedef unsigned __bitwise__ fmode_t;
184 
185 #ifdef CONFIG_PHYS_ADDR_T_64BIT
186 typedef u64 phys_addr_t;
187 #else
188 typedef u32 phys_addr_t;
189 #endif
190 
191 typedef phys_addr_t resource_size_t;
192 
193 typedef struct {
194 	int counter;
195 } atomic_t;
196 
197 #ifdef CONFIG_64BIT
198 typedef struct {
199 	long counter;
200 } atomic64_t;
201 #endif
202 
203 struct list_head {
204 	struct list_head *next, *prev;
205 };
206 
207 struct hlist_head {
208 	struct hlist_node *first;
209 };
210 
211 struct hlist_node {
212 	struct hlist_node *next, **pprev;
213 };
214 
215 struct ustat {
216 	__kernel_daddr_t	f_tfree;
217 	__kernel_ino_t		f_tinode;
218 	char			f_fname[6];
219 	char			f_fpack[6];
220 };
221 
222 #endif	/* __KERNEL__ */
223 #endif /*  __ASSEMBLY__ */
224 #endif /* _LINUX_TYPES_H */
225