xref: /freebsd/sys/compat/linux/linux_file.h (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2007 Roman Divacky
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _LINUX_FILE_H_
30 #define	_LINUX_FILE_H_
31 
32 #define	LINUX_AT_FDCWD			-100
33 #define	LINUX_AT_SYMLINK_NOFOLLOW	0x100
34 #define	LINUX_AT_EACCESS		0x200
35 #define	LINUX_AT_REMOVEDIR		0x200
36 #define	LINUX_AT_SYMLINK_FOLLOW		0x400
37 #define	LINUX_AT_NO_AUTOMOUNT		0x800
38 		/*
39 		 * Specific to Linux AT_NO_AUTOMOUNT flag tells the kernel to
40 		 * not automount the terminal component of pathname if it is a
41 		 * directory that is an automount point. As FreeBSD does not
42 		 * have such facility (automount), we can simply ignore this flag.
43 		 */
44 #define	LINUX_AT_EMPTY_PATH		0x1000
45 
46 /*
47  * posix_fadvise advice
48  */
49 #define	LINUX_POSIX_FADV_NORMAL		0
50 #define	LINUX_POSIX_FADV_RANDOM		1
51 #define	LINUX_POSIX_FADV_SEQUENTIAL	2
52 #define	LINUX_POSIX_FADV_WILLNEED	3
53 #define	LINUX_POSIX_FADV_DONTNEED	4
54 #define	LINUX_POSIX_FADV_NOREUSE	5
55 
56 /*
57  * mount flags
58  */
59 #define	LINUX_MS_RDONLY		0x0001
60 #define	LINUX_MS_NOSUID		0x0002
61 #define	LINUX_MS_NODEV		0x0004
62 #define	LINUX_MS_NOEXEC		0x0008
63 #define	LINUX_MS_REMOUNT	0x0020
64 
65 /*
66  * umount2 flags
67  */
68 #define	LINUX_MNT_FORCE		0x0001
69 
70 /*
71  * common open/fcntl flags
72  */
73 #define	LINUX_O_RDONLY		000000000
74 #define	LINUX_O_WRONLY		000000001
75 #define	LINUX_O_RDWR		000000002
76 #define	LINUX_O_ACCMODE		000000003
77 #define	LINUX_O_CREAT		000000100
78 #define	LINUX_O_EXCL		000000200
79 #define	LINUX_O_NOCTTY		000000400
80 #define	LINUX_O_TRUNC		000001000
81 #define	LINUX_O_APPEND		000002000
82 #define	LINUX_O_NONBLOCK	000004000
83 #define	LINUX_O_NDELAY		LINUX_O_NONBLOCK
84 #define	LINUX_O_SYNC		000010000
85 #define	LINUX_O_ASYNC		000020000
86 #ifndef LINUX_O_DIRECT
87 #define	LINUX_O_DIRECT		000040000	/* Direct disk access hint */
88 #endif
89 #ifndef LINUX_O_LARGEFILE
90 #define	LINUX_O_LARGEFILE	000100000
91 #endif
92 #ifndef LINUX_O_DIRECTORY
93 #define	LINUX_O_DIRECTORY	000200000	/* Must be a directory */
94 #endif
95 #ifndef LINUX_O_NOFOLLOW
96 #define	LINUX_O_NOFOLLOW	000400000	/* Do not follow links */
97 #endif
98 #define	LINUX_O_NOATIME		001000000
99 #define	LINUX_O_CLOEXEC		002000000
100 #define	LINUX_O_PATH		010000000
101 
102 #define	LINUX_F_DUPFD		0
103 #define	LINUX_F_GETFD		1
104 #define	LINUX_F_SETFD		2
105 #define	LINUX_F_GETFL		3
106 #define	LINUX_F_SETFL		4
107 #ifndef LINUX_F_GETLK
108 #define	LINUX_F_GETLK		5
109 #define	LINUX_F_SETLK		6
110 #define	LINUX_F_SETLKW		7
111 #endif
112 #ifndef LINUX_F_SETOWN
113 #define	LINUX_F_SETOWN		8
114 #define	LINUX_F_GETOWN		9
115 #endif
116 #ifndef LINUX_F_SETSIG
117 #define	LINUX_F_SETSIG		10
118 #define	LINUX_F_GETSIG		11
119 #endif
120 #ifndef LINUX_F_SETOWN_EX
121 #define	LINUX_F_SETOWN_EX	15
122 #define	LINUX_F_GETOWN_EX	16
123 #define	LINUX_F_GETOWNER_UIDS	17
124 #endif
125 
126 #define	LINUX_F_SPECIFIC_BASE	1024
127 
128 #define	LINUX_F_SETLEASE	(LINUX_F_SPECIFIC_BASE + 0)
129 #define	LINUX_F_GETLEASE	(LINUX_F_SPECIFIC_BASE + 1)
130 #define	LINUX_F_CANCELLK	(LINUX_F_SPECIFIC_BASE + 5)
131 #define	LINUX_F_DUPFD_CLOEXEC	(LINUX_F_SPECIFIC_BASE + 6)
132 #define	LINUX_F_NOTIFY		(LINUX_F_SPECIFIC_BASE + 2)
133 #define	LINUX_F_SETPIPE_SZ	(LINUX_F_SPECIFIC_BASE + 7)
134 #define	LINUX_F_GETPIPE_SZ	(LINUX_F_SPECIFIC_BASE + 8)
135 
136 #define	LINUX_F_ADD_SEALS	(LINUX_F_SPECIFIC_BASE + 9)
137 #define	LINUX_F_GET_SEALS	(LINUX_F_SPECIFIC_BASE + 10)
138 
139 #define	LINUX_F_GETLKP		36
140 #define	LINUX_F_SETLKP		37
141 #define	LINUX_F_SETLKPW		38
142 
143 #define	LINUX_F_OWNER_TID	0
144 #define	LINUX_F_OWNER_PID	1
145 #define	LINUX_F_OWNER_PGRP	2
146 
147 #ifndef LINUX_F_RDLCK
148 #define	LINUX_F_RDLCK		0
149 #define	LINUX_F_WRLCK		1
150 #define	LINUX_F_UNLCK		2
151 #endif
152 
153 /*
154  * renameat2 flags
155  */
156 #define	LINUX_RENAME_NOREPLACE	0x00000001
157 #define	LINUX_RENAME_EXCHANGE	0x00000002
158 #define	LINUX_RENAME_WHITEOUT	0x00000004
159 
160 /*
161  * sync_file_range flags
162  */
163 #define	LINUX_SYNC_FILE_RANGE_WAIT_BEFORE	1
164 #define	LINUX_SYNC_FILE_RANGE_WRITE		2
165 #define	LINUX_SYNC_FILE_RANGE_WAIT_AFTER	4
166 
167 #define	LINUX_F_SEAL_SEAL	0x0001
168 #define	LINUX_F_SEAL_SHRINK	0x0002
169 #define	LINUX_F_SEAL_GROW	0x0004
170 #define	LINUX_F_SEAL_WRITE	0x0008
171 
172 #define	LINUX_MFD_CLOEXEC	0x0001
173 #define	LINUX_MFD_ALLOW_SEALING	0x0002
174 #define	LINUX_MFD_HUGETLB	0x0004
175 
176 #define	LINUX_HUGETLB_FLAG_ENCODE_SHIFT	26
177 #define	LINUX_HUGETLB_FLAG_ENCODE_MASK	0x3f
178 
179 #define LINUX_HUGETLB_FLAG_ENCODE_64KB	(16 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
180 #define LINUX_HUGETLB_FLAG_ENCODE_512KB	(19 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
181 #define LINUX_HUGETLB_FLAG_ENCODE_1MB	(20 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
182 #define LINUX_HUGETLB_FLAG_ENCODE_2MB	(21 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
183 #define LINUX_HUGETLB_FLAG_ENCODE_8MB	(23 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
184 #define LINUX_HUGETLB_FLAG_ENCODE_16MB	(24 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
185 #define LINUX_HUGETLB_FLAG_ENCODE_32MB	(25 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
186 #define LINUX_HUGETLB_FLAG_ENCODE_256MB	(28 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
187 #define LINUX_HUGETLB_FLAG_ENCODE_512MB	(29 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
188 #define LINUX_HUGETLB_FLAG_ENCODE_1GB	(30 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
189 #define LINUX_HUGETLB_FLAG_ENCODE_2GB	(31 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
190 #define LINUX_HUGETLB_FLAG_ENCODE_16GB	(34U << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
191 
192 #if defined(_KERNEL)
193 struct l_file_handle {
194 	l_uint handle_bytes;
195 	l_int handle_type;
196 	unsigned char f_handle[0];
197 };
198 
199 int	linux_enobufs2eagain(struct thread *, int, int);
200 #endif
201 
202 /*
203  * Look at linux_close_range() for an explanation.
204  *
205  * #define	LINUX_CLOSE_RANGE_UNSHARE	(1U << 1)
206  */
207 #define	LINUX_CLOSE_RANGE_CLOEXEC	(1U << 2)
208 
209 #endif	/* !_LINUX_FILE_H_ */
210