1 /*        $NetBSD: linux_types.h,v 1.34 2024/07/01 01:35:53 christos Exp $      */
2 
3 /*-
4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Frank van der Linden and Eric Haszlakiewicz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LINUX_TYPES_H
33 #define _LINUX_TYPES_H
34 
35 #if defined(__i386__)
36 #include <compat/linux/arch/i386/linux_types.h>
37 #elif defined(__alpha__)
38 #include <compat/linux/arch/alpha/linux_types.h>
39 #elif defined(__powerpc__)
40 #include <compat/linux/arch/powerpc/linux_types.h>
41 #elif defined(__aarch64__)
42 #include <compat/linux/arch/aarch64/linux_types.h>
43 #elif defined(__arm__)
44 #include <compat/linux/arch/arm/linux_types.h>
45 #elif defined(__m68k__)
46 #include <compat/linux/arch/m68k/linux_types.h>
47 #elif defined(__mips__)
48 #include <compat/linux/arch/mips/linux_types.h>
49 #elif defined(__amd64__)
50 #include <compat/linux/arch/amd64/linux_types.h>
51 #else
52 typedef unsigned long linux_clock_t;
53 typedef long linux_time_t;
54 typedef long linux_suseconds_t;
55 #endif
56 
57 typedef unsigned short linux_gid16_t;
58 typedef unsigned short linux_uid16_t;
59 typedef unsigned short linux_umode_t;
60 
61 typedef long linux_mqd_t;
62 
63 /*
64  * From Linux include/asm-.../posix_types.h
65  */
66 typedef struct {
67           int val[2];
68 } linux_fsid_t;
69 
70 /*
71  * Structure for uname(2)
72  */
73 struct linux_utsname {
74           char l_sysname[65];
75           char l_nodename[65];
76           char l_release[65];
77           char l_version[65];
78           char l_machine[65];
79           char l_domainname[65];
80 };
81 
82 extern char linux_sysname[];
83 extern char linux_release[];
84 extern char linux_version[];
85 extern char linux_machine[];
86 
87 struct linux_tms {
88           linux_clock_t ltms_utime;
89           linux_clock_t ltms_stime;
90           linux_clock_t ltms_cutime;
91           linux_clock_t ltms_cstime;
92 };
93 
94 struct linux_timeval {
95           linux_time_t tv_sec;
96           linux_suseconds_t tv_usec;
97 };
98 
99 struct linux_utimbuf {
100           linux_time_t l_actime;
101           linux_time_t l_modtime;
102 };
103 
104 struct linux___sysctl {
105           int          *name;
106           int           nlen;
107           void         *oldval;
108           size_t       *oldlenp;
109           void         *newval;
110           size_t        newlen;
111           unsigned long __unused0[4];
112 };
113 
114 #include <compat/linux/common/linux_siginfo.h>
115 
116 /*
117  * Generic statfs structure from Linux include/asm-generic/statfs.h
118  * Linux/x86_64 uses different (fully 64bit) struct statfs.
119  */
120 #ifdef LINUX_STATFS_64BIT
121 struct linux_statfs {
122           long                l_ftype;
123           long                l_fbsize;
124           long                l_fblocks;
125           long                l_fbfree;
126           long                l_fbavail;
127           long                l_ffiles;
128           long                l_fffree;
129           linux_fsid_t        l_ffsid;
130           long                l_fnamelen;
131           long                l_ffrsize;
132           long                l_fspare[5];
133 };
134 
135 struct linux_statfs64 {
136           long                l_ftype;
137           long                l_fbsize;
138           long                l_fblocks;
139           long                l_fbfree;
140           long                l_fbavail;
141           long                l_ffiles;
142           long                l_fffree;
143           linux_fsid_t        l_ffsid;
144           long                l_fnamelen;
145           long                l_ffrsize;
146           long                l_fspare[5];
147 };
148 #else /* !LINUX_STATFS_64BIT */
149 struct linux_statfs {
150           u_int32_t l_ftype;
151           u_int32_t l_fbsize;
152           u_int32_t l_fblocks;
153           u_int32_t l_fbfree;
154           u_int32_t l_fbavail;
155           u_int32_t l_ffiles;
156           u_int32_t l_fffree;
157           linux_fsid_t        l_ffsid;
158           u_int32_t l_fnamelen;
159           u_int32_t l_ffrsize;
160           u_int32_t l_fspare[5];
161 };
162 
163 struct linux_statfs64 {
164           u_int32_t l_ftype;
165           u_int32_t l_fbsize;
166           u_int64_t l_fblocks;
167           u_int64_t l_fbfree;
168           u_int64_t l_fbavail;
169           u_int64_t l_ffiles;
170           u_int64_t l_fffree;
171           linux_fsid_t        l_ffsid;
172           u_int32_t l_fnamelen;
173           u_int32_t l_ffrsize;
174           u_int32_t l_fspare[5];
175 };
176 #endif /* !LINUX_STATFS_64BIT */
177 
178 struct linux_statx_timestamp {
179           int64_t tv_sec;
180           uint32_t tv_nsec;
181           int32_t __reserved;
182 };
183 
184 #define STATX_TYPE            0x00000001
185 #define STATX_MODE            0x00000002
186 #define STATX_NLINK           0x00000004
187 #define STATX_UID             0x00000008
188 #define STATX_GID             0x00000010
189 #define STATX_ATIME           0x00000020
190 #define STATX_MTIME           0x00000040
191 #define STATX_CTIME           0x00000080
192 #define STATX_INO             0x00000100
193 #define STATX_SIZE            0x00000200
194 #define STATX_BLOCKS                    0x00000400
195 #define STATX_BASIC_STATS     0x000007ff
196 #define STATX_BTIME           0x00000800
197 #define STATX_MNT_ID                    0x00001000
198 #define STATX_ALL             0x00000fff
199 #define STATX__RESERVED                 0x80000000
200 
201 #define STATX_ATTR_COMPRESSED 0x00000004
202 #define STATX_ATTR_IMMUTABLE  0x00000010
203 #define STATX_ATTR_APPEND     0x00000020
204 #define STATX_ATTR_NODUMP     0x00000040
205 #define STATX_ATTR_ENCRYPTED  0x00000800
206 #define STATX_ATTR_AUTOMOUNT  0x00001000
207 #define STATX_ATTR_MOUNT_ROOT 0x00002000
208 #define STATX_ATTR_VERITY     0x00100000
209 #define STATX_ATTR_DAX                  0x00200000
210 
211 struct linux_statx {
212           uint32_t stx_mask;
213           uint32_t stx_blksize;
214           uint64_t stx_attributes;
215           uint32_t stx_nlink;
216           uint32_t stx_uid;
217           uint32_t stx_gid;
218           uint16_t stx_mode;
219           uint16_t __pad1;
220           uint64_t stx_ino;
221           uint64_t stx_size;
222           uint64_t stx_blocks;
223           uint64_t stx_attributes_mask;
224           struct linux_statx_timestamp stx_atime;
225           struct linux_statx_timestamp stx_btime;
226           struct linux_statx_timestamp stx_ctime;
227           struct linux_statx_timestamp stx_mtime;
228           uint32_t stx_rdev_major;
229           uint32_t stx_rdev_minor;
230           uint32_t stx_dev_major;
231           uint32_t stx_dev_minor;
232           uint64_t stx_mnt_id;
233           uint64_t __spare2;
234           uint64_t __spare3[12];
235 } __packed;
236 
237 #endif /* !_LINUX_TYPES_H */
238