xref: /f-stack/freebsd/sys/file.h (revision 22ce4aff)
1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*22ce4affSfengbojiang  *
4a9643ea8Slogwang  * Copyright (c) 1982, 1986, 1989, 1993
5a9643ea8Slogwang  *	The Regents of the University of California.  All rights reserved.
6a9643ea8Slogwang  *
7a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
8a9643ea8Slogwang  * modification, are permitted provided that the following conditions
9a9643ea8Slogwang  * are met:
10a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
11a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
12a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
13a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
14a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
15*22ce4affSfengbojiang  * 3. Neither the name of the University nor the names of its contributors
16a9643ea8Slogwang  *    may be used to endorse or promote products derived from this software
17a9643ea8Slogwang  *    without specific prior written permission.
18a9643ea8Slogwang  *
19a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29a9643ea8Slogwang  * SUCH DAMAGE.
30a9643ea8Slogwang  *
31a9643ea8Slogwang  *	@(#)file.h	8.3 (Berkeley) 1/9/95
32a9643ea8Slogwang  * $FreeBSD$
33a9643ea8Slogwang  */
34a9643ea8Slogwang 
35a9643ea8Slogwang #ifndef _SYS_FILE_H_
36a9643ea8Slogwang #define	_SYS_FILE_H_
37a9643ea8Slogwang 
38a9643ea8Slogwang #ifndef _KERNEL
39a9643ea8Slogwang #include <sys/types.h> /* XXX */
40a9643ea8Slogwang #include <sys/fcntl.h>
41a9643ea8Slogwang #include <sys/unistd.h>
42a9643ea8Slogwang #else
43a9643ea8Slogwang #include <sys/queue.h>
44a9643ea8Slogwang #include <sys/refcount.h>
45a9643ea8Slogwang #include <sys/_lock.h>
46a9643ea8Slogwang #include <sys/_mutex.h>
47a9643ea8Slogwang #include <vm/vm.h>
48a9643ea8Slogwang 
49a9643ea8Slogwang struct filedesc;
50a9643ea8Slogwang struct stat;
51a9643ea8Slogwang struct thread;
52a9643ea8Slogwang struct uio;
53a9643ea8Slogwang struct knote;
54a9643ea8Slogwang struct vnode;
55*22ce4affSfengbojiang struct nameidata;
56a9643ea8Slogwang 
57a9643ea8Slogwang #endif /* _KERNEL */
58a9643ea8Slogwang 
59*22ce4affSfengbojiang #define	DTYPE_NONE	0	/* not yet initialized */
60a9643ea8Slogwang #define	DTYPE_VNODE	1	/* file */
61a9643ea8Slogwang #define	DTYPE_SOCKET	2	/* communications endpoint */
62a9643ea8Slogwang #define	DTYPE_PIPE	3	/* pipe */
63a9643ea8Slogwang #define	DTYPE_FIFO	4	/* fifo (named pipe) */
64a9643ea8Slogwang #define	DTYPE_KQUEUE	5	/* event queue */
65a9643ea8Slogwang #define	DTYPE_CRYPTO	6	/* crypto */
66a9643ea8Slogwang #define	DTYPE_MQUEUE	7	/* posix message queue */
67a9643ea8Slogwang #define	DTYPE_SHM	8	/* swap-backed shared memory */
68a9643ea8Slogwang #define	DTYPE_SEM	9	/* posix semaphore */
69a9643ea8Slogwang #define	DTYPE_PTS	10	/* pseudo teletype master device */
70a9643ea8Slogwang #define	DTYPE_DEV	11	/* Device specific fd type */
71a9643ea8Slogwang #define	DTYPE_PROCDESC	12	/* process descriptor */
72*22ce4affSfengbojiang #define	DTYPE_EVENTFD	13	/* eventfd */
73*22ce4affSfengbojiang #define	DTYPE_LINUXTFD	14	/* emulation timerfd type */
74a9643ea8Slogwang 
75a9643ea8Slogwang #ifdef _KERNEL
76a9643ea8Slogwang 
77a9643ea8Slogwang struct file;
78a9643ea8Slogwang struct filecaps;
79a9643ea8Slogwang struct kaiocb;
80a9643ea8Slogwang struct kinfo_file;
81a9643ea8Slogwang struct ucred;
82a9643ea8Slogwang 
83a9643ea8Slogwang #define	FOF_OFFSET	0x01	/* Use the offset in uio argument */
84a9643ea8Slogwang #define	FOF_NOLOCK	0x02	/* Do not take FOFFSET_LOCK */
85*22ce4affSfengbojiang #define	FOF_NEXTOFF_R	0x04	/* Also update f_nextoff[UIO_READ] */
86*22ce4affSfengbojiang #define	FOF_NEXTOFF_W	0x08	/* Also update f_nextoff[UIO_WRITE] */
87a9643ea8Slogwang #define	FOF_NOUPDATE	0x10	/* Do not update f_offset */
88a9643ea8Slogwang off_t foffset_lock(struct file *fp, int flags);
89a9643ea8Slogwang void foffset_lock_uio(struct file *fp, struct uio *uio, int flags);
90a9643ea8Slogwang void foffset_unlock(struct file *fp, off_t val, int flags);
91a9643ea8Slogwang void foffset_unlock_uio(struct file *fp, struct uio *uio, int flags);
92a9643ea8Slogwang 
93a9643ea8Slogwang static inline off_t
foffset_get(struct file * fp)94a9643ea8Slogwang foffset_get(struct file *fp)
95a9643ea8Slogwang {
96a9643ea8Slogwang 
97a9643ea8Slogwang 	return (foffset_lock(fp, FOF_NOLOCK));
98a9643ea8Slogwang }
99a9643ea8Slogwang 
100a9643ea8Slogwang typedef int fo_rdwr_t(struct file *fp, struct uio *uio,
101a9643ea8Slogwang 		    struct ucred *active_cred, int flags,
102a9643ea8Slogwang 		    struct thread *td);
103a9643ea8Slogwang typedef	int fo_truncate_t(struct file *fp, off_t length,
104a9643ea8Slogwang 		    struct ucred *active_cred, struct thread *td);
105a9643ea8Slogwang typedef	int fo_ioctl_t(struct file *fp, u_long com, void *data,
106a9643ea8Slogwang 		    struct ucred *active_cred, struct thread *td);
107a9643ea8Slogwang typedef	int fo_poll_t(struct file *fp, int events,
108a9643ea8Slogwang 		    struct ucred *active_cred, struct thread *td);
109a9643ea8Slogwang typedef	int fo_kqfilter_t(struct file *fp, struct knote *kn);
110a9643ea8Slogwang typedef	int fo_stat_t(struct file *fp, struct stat *sb,
111a9643ea8Slogwang 		    struct ucred *active_cred, struct thread *td);
112a9643ea8Slogwang typedef	int fo_close_t(struct file *fp, struct thread *td);
113a9643ea8Slogwang typedef	int fo_chmod_t(struct file *fp, mode_t mode,
114a9643ea8Slogwang 		    struct ucred *active_cred, struct thread *td);
115a9643ea8Slogwang typedef	int fo_chown_t(struct file *fp, uid_t uid, gid_t gid,
116a9643ea8Slogwang 		    struct ucred *active_cred, struct thread *td);
117a9643ea8Slogwang typedef int fo_sendfile_t(struct file *fp, int sockfd, struct uio *hdr_uio,
118a9643ea8Slogwang 		    struct uio *trl_uio, off_t offset, size_t nbytes,
119a9643ea8Slogwang 		    off_t *sent, int flags, struct thread *td);
120a9643ea8Slogwang typedef int fo_seek_t(struct file *fp, off_t offset, int whence,
121a9643ea8Slogwang 		    struct thread *td);
122a9643ea8Slogwang typedef int fo_fill_kinfo_t(struct file *fp, struct kinfo_file *kif,
123a9643ea8Slogwang 		    struct filedesc *fdp);
124a9643ea8Slogwang typedef int fo_mmap_t(struct file *fp, vm_map_t map, vm_offset_t *addr,
125a9643ea8Slogwang 		    vm_size_t size, vm_prot_t prot, vm_prot_t cap_maxprot,
126a9643ea8Slogwang 		    int flags, vm_ooffset_t foff, struct thread *td);
127a9643ea8Slogwang typedef int fo_aio_queue_t(struct file *fp, struct kaiocb *job);
128*22ce4affSfengbojiang typedef int fo_add_seals_t(struct file *fp, int flags);
129*22ce4affSfengbojiang typedef int fo_get_seals_t(struct file *fp, int *flags);
130*22ce4affSfengbojiang typedef int fo_fallocate_t(struct file *fp, off_t offset, off_t len,
131*22ce4affSfengbojiang 		    struct thread *td);
132a9643ea8Slogwang typedef	int fo_flags_t;
133a9643ea8Slogwang 
134a9643ea8Slogwang struct fileops {
135a9643ea8Slogwang 	fo_rdwr_t	*fo_read;
136a9643ea8Slogwang 	fo_rdwr_t	*fo_write;
137a9643ea8Slogwang 	fo_truncate_t	*fo_truncate;
138a9643ea8Slogwang 	fo_ioctl_t	*fo_ioctl;
139a9643ea8Slogwang 	fo_poll_t	*fo_poll;
140a9643ea8Slogwang 	fo_kqfilter_t	*fo_kqfilter;
141a9643ea8Slogwang 	fo_stat_t	*fo_stat;
142a9643ea8Slogwang 	fo_close_t	*fo_close;
143a9643ea8Slogwang 	fo_chmod_t	*fo_chmod;
144a9643ea8Slogwang 	fo_chown_t	*fo_chown;
145a9643ea8Slogwang 	fo_sendfile_t	*fo_sendfile;
146a9643ea8Slogwang 	fo_seek_t	*fo_seek;
147a9643ea8Slogwang 	fo_fill_kinfo_t	*fo_fill_kinfo;
148a9643ea8Slogwang 	fo_mmap_t	*fo_mmap;
149a9643ea8Slogwang 	fo_aio_queue_t	*fo_aio_queue;
150*22ce4affSfengbojiang 	fo_add_seals_t	*fo_add_seals;
151*22ce4affSfengbojiang 	fo_get_seals_t	*fo_get_seals;
152*22ce4affSfengbojiang 	fo_fallocate_t	*fo_fallocate;
153a9643ea8Slogwang 	fo_flags_t	fo_flags;	/* DFLAG_* below */
154a9643ea8Slogwang };
155a9643ea8Slogwang 
156a9643ea8Slogwang #define DFLAG_PASSABLE	0x01	/* may be passed via unix sockets. */
157a9643ea8Slogwang #define DFLAG_SEEKABLE	0x02	/* seekable / nonsequential */
158a9643ea8Slogwang #endif /* _KERNEL */
159a9643ea8Slogwang 
160a9643ea8Slogwang #if defined(_KERNEL) || defined(_WANT_FILE)
161a9643ea8Slogwang /*
162a9643ea8Slogwang  * Kernel descriptor table.
163a9643ea8Slogwang  * One entry for each open kernel vnode and socket.
164a9643ea8Slogwang  *
165a9643ea8Slogwang  * Below is the list of locks that protects members in struct file.
166a9643ea8Slogwang  *
167a9643ea8Slogwang  * (a) f_vnode lock required (shared allows both reads and writes)
168*22ce4affSfengbojiang  * (f) updated with atomics and blocking on sleepq
169a9643ea8Slogwang  * (d) cdevpriv_mtx
170a9643ea8Slogwang  * none	not locked
171a9643ea8Slogwang  */
172a9643ea8Slogwang 
173a9643ea8Slogwang struct fadvise_info {
174a9643ea8Slogwang 	int		fa_advice;	/* (f) FADV_* type. */
175a9643ea8Slogwang 	off_t		fa_start;	/* (f) Region start. */
176a9643ea8Slogwang 	off_t		fa_end;		/* (f) Region end. */
177a9643ea8Slogwang };
178a9643ea8Slogwang 
179a9643ea8Slogwang struct file {
180a9643ea8Slogwang 	volatile u_int	f_flag;		/* see fcntl.h */
181a9643ea8Slogwang 	volatile u_int 	f_count;	/* reference count */
182*22ce4affSfengbojiang 	void		*f_data;	/* file descriptor specific data */
183*22ce4affSfengbojiang 	struct fileops	*f_ops;		/* File operations */
184*22ce4affSfengbojiang 	struct vnode 	*f_vnode;	/* NULL or applicable vnode */
185*22ce4affSfengbojiang 	struct ucred	*f_cred;	/* associated credentials. */
186*22ce4affSfengbojiang 	short		f_type;		/* descriptor type */
187*22ce4affSfengbojiang 	short		f_vnread_flags; /* (f) Sleep lock for f_offset */
188a9643ea8Slogwang 	/*
189a9643ea8Slogwang 	 *  DTYPE_VNODE specific fields.
190a9643ea8Slogwang 	 */
191*22ce4affSfengbojiang 	union {
192*22ce4affSfengbojiang 		int16_t	f_seqcount[2];	/* (a) Count of seq. reads and writes. */
193*22ce4affSfengbojiang 		int	f_pipegen;
194*22ce4affSfengbojiang 	};
195*22ce4affSfengbojiang 	off_t		f_nextoff[2];	/* next expected read/write offset. */
196a9643ea8Slogwang 	union {
197a9643ea8Slogwang 		struct cdev_privdata *fvn_cdevpriv;
198a9643ea8Slogwang 					/* (d) Private data for the cdev. */
199a9643ea8Slogwang 		struct fadvise_info *fvn_advice;
200a9643ea8Slogwang 	} f_vnun;
201a9643ea8Slogwang 	/*
202a9643ea8Slogwang 	 *  DFLAG_SEEKABLE specific fields
203a9643ea8Slogwang 	 */
204a9643ea8Slogwang 	off_t		f_offset;
205a9643ea8Slogwang };
206a9643ea8Slogwang 
207a9643ea8Slogwang #define	f_cdevpriv	f_vnun.fvn_cdevpriv
208a9643ea8Slogwang #define	f_advice	f_vnun.fvn_advice
209a9643ea8Slogwang 
210a9643ea8Slogwang #define	FOFFSET_LOCKED       0x1
211a9643ea8Slogwang #define	FOFFSET_LOCK_WAITING 0x2
212a9643ea8Slogwang 
213a9643ea8Slogwang #endif /* _KERNEL || _WANT_FILE */
214a9643ea8Slogwang 
215a9643ea8Slogwang /*
216a9643ea8Slogwang  * Userland version of struct file, for sysctl
217a9643ea8Slogwang  */
218a9643ea8Slogwang struct xfile {
219*22ce4affSfengbojiang 	ksize_t	xf_size;	/* size of struct xfile */
220a9643ea8Slogwang 	pid_t	xf_pid;		/* owning process */
221a9643ea8Slogwang 	uid_t	xf_uid;		/* effective uid of owning process */
222a9643ea8Slogwang 	int	xf_fd;		/* descriptor number */
223*22ce4affSfengbojiang 	int	_xf_int_pad1;
224*22ce4affSfengbojiang 	kvaddr_t xf_file;	/* address of struct file */
225a9643ea8Slogwang 	short	xf_type;	/* descriptor type */
226*22ce4affSfengbojiang 	short	_xf_short_pad1;
227a9643ea8Slogwang 	int	xf_count;	/* reference count */
228a9643ea8Slogwang 	int	xf_msgcount;	/* references from message queue */
229*22ce4affSfengbojiang 	int	_xf_int_pad2;
230a9643ea8Slogwang 	off_t	xf_offset;	/* file offset */
231*22ce4affSfengbojiang 	kvaddr_t xf_data;	/* file descriptor specific data */
232*22ce4affSfengbojiang 	kvaddr_t xf_vnode;	/* vnode pointer */
233a9643ea8Slogwang 	u_int	xf_flag;	/* flags (see fcntl.h) */
234*22ce4affSfengbojiang 	int	_xf_int_pad3;
235*22ce4affSfengbojiang 	int64_t	_xf_int64_pad[6];
236a9643ea8Slogwang };
237a9643ea8Slogwang 
238a9643ea8Slogwang #ifdef _KERNEL
239a9643ea8Slogwang 
240a9643ea8Slogwang extern struct fileops vnops;
241a9643ea8Slogwang extern struct fileops badfileops;
242a9643ea8Slogwang extern struct fileops socketops;
243a9643ea8Slogwang extern int maxfiles;		/* kernel limit on number of open files */
244a9643ea8Slogwang extern int maxfilesperproc;	/* per process limit on number of open files */
245a9643ea8Slogwang 
246a9643ea8Slogwang int fget(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp);
247a9643ea8Slogwang int fget_mmap(struct thread *td, int fd, cap_rights_t *rightsp,
248*22ce4affSfengbojiang     vm_prot_t *maxprotp, struct file **fpp);
249a9643ea8Slogwang int fget_read(struct thread *td, int fd, cap_rights_t *rightsp,
250a9643ea8Slogwang     struct file **fpp);
251a9643ea8Slogwang int fget_write(struct thread *td, int fd, cap_rights_t *rightsp,
252a9643ea8Slogwang     struct file **fpp);
253a9643ea8Slogwang int fget_fcntl(struct thread *td, int fd, cap_rights_t *rightsp,
254a9643ea8Slogwang     int needfcntl, struct file **fpp);
255a9643ea8Slogwang int _fdrop(struct file *fp, struct thread *td);
256a9643ea8Slogwang 
257a9643ea8Slogwang fo_rdwr_t	invfo_rdwr;
258a9643ea8Slogwang fo_truncate_t	invfo_truncate;
259a9643ea8Slogwang fo_ioctl_t	invfo_ioctl;
260a9643ea8Slogwang fo_poll_t	invfo_poll;
261a9643ea8Slogwang fo_kqfilter_t	invfo_kqfilter;
262a9643ea8Slogwang fo_chmod_t	invfo_chmod;
263a9643ea8Slogwang fo_chown_t	invfo_chown;
264a9643ea8Slogwang fo_sendfile_t	invfo_sendfile;
265a9643ea8Slogwang 
266a9643ea8Slogwang fo_sendfile_t	vn_sendfile;
267a9643ea8Slogwang fo_seek_t	vn_seek;
268a9643ea8Slogwang fo_fill_kinfo_t	vn_fill_kinfo;
269a9643ea8Slogwang int vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif);
270a9643ea8Slogwang 
271a9643ea8Slogwang void finit(struct file *, u_int, short, void *, struct fileops *);
272*22ce4affSfengbojiang void finit_vnode(struct file *, u_int, void *, struct fileops *);
273a9643ea8Slogwang int fgetvp(struct thread *td, int fd, cap_rights_t *rightsp,
274a9643ea8Slogwang     struct vnode **vpp);
275a9643ea8Slogwang int fgetvp_exec(struct thread *td, int fd, cap_rights_t *rightsp,
276a9643ea8Slogwang     struct vnode **vpp);
277a9643ea8Slogwang int fgetvp_rights(struct thread *td, int fd, cap_rights_t *needrightsp,
278a9643ea8Slogwang     struct filecaps *havecaps, struct vnode **vpp);
279a9643ea8Slogwang int fgetvp_read(struct thread *td, int fd, cap_rights_t *rightsp,
280a9643ea8Slogwang     struct vnode **vpp);
281a9643ea8Slogwang int fgetvp_write(struct thread *td, int fd, cap_rights_t *rightsp,
282a9643ea8Slogwang     struct vnode **vpp);
283*22ce4affSfengbojiang int fgetvp_lookup_smr(int fd, struct nameidata *ndp, struct vnode **vpp, bool *fsearch);
284a9643ea8Slogwang 
285*22ce4affSfengbojiang static __inline __result_use_check bool
fhold(struct file * fp)286*22ce4affSfengbojiang fhold(struct file *fp)
287a9643ea8Slogwang {
288*22ce4affSfengbojiang 	return (refcount_acquire_checked(&fp->f_count));
289a9643ea8Slogwang }
290a9643ea8Slogwang 
291*22ce4affSfengbojiang #define	fdrop(fp, td)		({				\
292*22ce4affSfengbojiang 	struct file *_fp;					\
293*22ce4affSfengbojiang 	int _error;						\
294*22ce4affSfengbojiang 								\
295*22ce4affSfengbojiang 	_error = 0;						\
296*22ce4affSfengbojiang 	_fp = (fp);						\
297*22ce4affSfengbojiang 	if (__predict_false(refcount_release(&_fp->f_count)))	\
298*22ce4affSfengbojiang 		_error = _fdrop(_fp, td);			\
299*22ce4affSfengbojiang 	_error;							\
300*22ce4affSfengbojiang })
301*22ce4affSfengbojiang 
302*22ce4affSfengbojiang #define	fdrop_close(fp, td)		({			\
303*22ce4affSfengbojiang 	struct file *_fp;					\
304*22ce4affSfengbojiang 	int _error;						\
305*22ce4affSfengbojiang 								\
306*22ce4affSfengbojiang 	_error = 0;						\
307*22ce4affSfengbojiang 	_fp = (fp);						\
308*22ce4affSfengbojiang 	if (__predict_true(refcount_release(&_fp->f_count)))	\
309*22ce4affSfengbojiang 		_error = _fdrop(_fp, td);			\
310*22ce4affSfengbojiang 	_error;							\
311*22ce4affSfengbojiang })
312a9643ea8Slogwang 
313a9643ea8Slogwang static __inline fo_rdwr_t	fo_read;
314a9643ea8Slogwang static __inline fo_rdwr_t	fo_write;
315a9643ea8Slogwang static __inline fo_truncate_t	fo_truncate;
316a9643ea8Slogwang static __inline fo_ioctl_t	fo_ioctl;
317a9643ea8Slogwang static __inline fo_poll_t	fo_poll;
318a9643ea8Slogwang static __inline fo_kqfilter_t	fo_kqfilter;
319a9643ea8Slogwang static __inline fo_stat_t	fo_stat;
320a9643ea8Slogwang static __inline fo_close_t	fo_close;
321a9643ea8Slogwang static __inline fo_chmod_t	fo_chmod;
322a9643ea8Slogwang static __inline fo_chown_t	fo_chown;
323a9643ea8Slogwang static __inline fo_sendfile_t	fo_sendfile;
324a9643ea8Slogwang 
325a9643ea8Slogwang static __inline int
fo_read(struct file * fp,struct uio * uio,struct ucred * active_cred,int flags,struct thread * td)326a9643ea8Slogwang fo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
327a9643ea8Slogwang     int flags, struct thread *td)
328a9643ea8Slogwang {
329a9643ea8Slogwang 
330a9643ea8Slogwang 	return ((*fp->f_ops->fo_read)(fp, uio, active_cred, flags, td));
331a9643ea8Slogwang }
332a9643ea8Slogwang 
333a9643ea8Slogwang static __inline int
fo_write(struct file * fp,struct uio * uio,struct ucred * active_cred,int flags,struct thread * td)334a9643ea8Slogwang fo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
335a9643ea8Slogwang     int flags, struct thread *td)
336a9643ea8Slogwang {
337a9643ea8Slogwang 
338a9643ea8Slogwang 	return ((*fp->f_ops->fo_write)(fp, uio, active_cred, flags, td));
339a9643ea8Slogwang }
340a9643ea8Slogwang 
341a9643ea8Slogwang static __inline int
fo_truncate(struct file * fp,off_t length,struct ucred * active_cred,struct thread * td)342a9643ea8Slogwang fo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
343a9643ea8Slogwang     struct thread *td)
344a9643ea8Slogwang {
345a9643ea8Slogwang 
346a9643ea8Slogwang 	return ((*fp->f_ops->fo_truncate)(fp, length, active_cred, td));
347a9643ea8Slogwang }
348a9643ea8Slogwang 
349a9643ea8Slogwang static __inline int
fo_ioctl(struct file * fp,u_long com,void * data,struct ucred * active_cred,struct thread * td)350a9643ea8Slogwang fo_ioctl(struct file *fp, u_long com, void *data, struct ucred *active_cred,
351a9643ea8Slogwang     struct thread *td)
352a9643ea8Slogwang {
353a9643ea8Slogwang 
354a9643ea8Slogwang 	return ((*fp->f_ops->fo_ioctl)(fp, com, data, active_cred, td));
355a9643ea8Slogwang }
356a9643ea8Slogwang 
357a9643ea8Slogwang static __inline int
fo_poll(struct file * fp,int events,struct ucred * active_cred,struct thread * td)358a9643ea8Slogwang fo_poll(struct file *fp, int events, struct ucred *active_cred,
359a9643ea8Slogwang     struct thread *td)
360a9643ea8Slogwang {
361a9643ea8Slogwang 
362a9643ea8Slogwang 	return ((*fp->f_ops->fo_poll)(fp, events, active_cred, td));
363a9643ea8Slogwang }
364a9643ea8Slogwang 
365a9643ea8Slogwang static __inline int
fo_stat(struct file * fp,struct stat * sb,struct ucred * active_cred,struct thread * td)366a9643ea8Slogwang fo_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
367a9643ea8Slogwang     struct thread *td)
368a9643ea8Slogwang {
369a9643ea8Slogwang 
370a9643ea8Slogwang 	return ((*fp->f_ops->fo_stat)(fp, sb, active_cred, td));
371a9643ea8Slogwang }
372a9643ea8Slogwang 
373a9643ea8Slogwang static __inline int
fo_close(struct file * fp,struct thread * td)374a9643ea8Slogwang fo_close(struct file *fp, struct thread *td)
375a9643ea8Slogwang {
376a9643ea8Slogwang 
377a9643ea8Slogwang 	return ((*fp->f_ops->fo_close)(fp, td));
378a9643ea8Slogwang }
379a9643ea8Slogwang 
380a9643ea8Slogwang static __inline int
fo_kqfilter(struct file * fp,struct knote * kn)381a9643ea8Slogwang fo_kqfilter(struct file *fp, struct knote *kn)
382a9643ea8Slogwang {
383a9643ea8Slogwang 
384a9643ea8Slogwang 	return ((*fp->f_ops->fo_kqfilter)(fp, kn));
385a9643ea8Slogwang }
386a9643ea8Slogwang 
387a9643ea8Slogwang static __inline int
fo_chmod(struct file * fp,mode_t mode,struct ucred * active_cred,struct thread * td)388a9643ea8Slogwang fo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
389a9643ea8Slogwang     struct thread *td)
390a9643ea8Slogwang {
391a9643ea8Slogwang 
392a9643ea8Slogwang 	return ((*fp->f_ops->fo_chmod)(fp, mode, active_cred, td));
393a9643ea8Slogwang }
394a9643ea8Slogwang 
395a9643ea8Slogwang static __inline int
fo_chown(struct file * fp,uid_t uid,gid_t gid,struct ucred * active_cred,struct thread * td)396a9643ea8Slogwang fo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
397a9643ea8Slogwang     struct thread *td)
398a9643ea8Slogwang {
399a9643ea8Slogwang 
400a9643ea8Slogwang 	return ((*fp->f_ops->fo_chown)(fp, uid, gid, active_cred, td));
401a9643ea8Slogwang }
402a9643ea8Slogwang 
403a9643ea8Slogwang static __inline int
fo_sendfile(struct file * fp,int sockfd,struct uio * hdr_uio,struct uio * trl_uio,off_t offset,size_t nbytes,off_t * sent,int flags,struct thread * td)404a9643ea8Slogwang fo_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio,
405a9643ea8Slogwang     struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags,
406a9643ea8Slogwang     struct thread *td)
407a9643ea8Slogwang {
408a9643ea8Slogwang 
409a9643ea8Slogwang 	return ((*fp->f_ops->fo_sendfile)(fp, sockfd, hdr_uio, trl_uio, offset,
410a9643ea8Slogwang 	    nbytes, sent, flags, td));
411a9643ea8Slogwang }
412a9643ea8Slogwang 
413a9643ea8Slogwang static __inline int
fo_seek(struct file * fp,off_t offset,int whence,struct thread * td)414a9643ea8Slogwang fo_seek(struct file *fp, off_t offset, int whence, struct thread *td)
415a9643ea8Slogwang {
416a9643ea8Slogwang 
417a9643ea8Slogwang 	return ((*fp->f_ops->fo_seek)(fp, offset, whence, td));
418a9643ea8Slogwang }
419a9643ea8Slogwang 
420a9643ea8Slogwang static __inline int
fo_fill_kinfo(struct file * fp,struct kinfo_file * kif,struct filedesc * fdp)421a9643ea8Slogwang fo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
422a9643ea8Slogwang {
423a9643ea8Slogwang 
424a9643ea8Slogwang 	return ((*fp->f_ops->fo_fill_kinfo)(fp, kif, fdp));
425a9643ea8Slogwang }
426a9643ea8Slogwang 
427a9643ea8Slogwang static __inline int
fo_mmap(struct file * fp,vm_map_t map,vm_offset_t * addr,vm_size_t size,vm_prot_t prot,vm_prot_t cap_maxprot,int flags,vm_ooffset_t foff,struct thread * td)428a9643ea8Slogwang fo_mmap(struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t size,
429a9643ea8Slogwang     vm_prot_t prot, vm_prot_t cap_maxprot, int flags, vm_ooffset_t foff,
430a9643ea8Slogwang     struct thread *td)
431a9643ea8Slogwang {
432a9643ea8Slogwang 
433a9643ea8Slogwang 	if (fp->f_ops->fo_mmap == NULL)
434a9643ea8Slogwang 		return (ENODEV);
435a9643ea8Slogwang 	return ((*fp->f_ops->fo_mmap)(fp, map, addr, size, prot, cap_maxprot,
436a9643ea8Slogwang 	    flags, foff, td));
437a9643ea8Slogwang }
438a9643ea8Slogwang 
439a9643ea8Slogwang static __inline int
fo_aio_queue(struct file * fp,struct kaiocb * job)440a9643ea8Slogwang fo_aio_queue(struct file *fp, struct kaiocb *job)
441a9643ea8Slogwang {
442a9643ea8Slogwang 
443a9643ea8Slogwang 	return ((*fp->f_ops->fo_aio_queue)(fp, job));
444a9643ea8Slogwang }
445a9643ea8Slogwang 
446*22ce4affSfengbojiang static __inline int
fo_add_seals(struct file * fp,int seals)447*22ce4affSfengbojiang fo_add_seals(struct file *fp, int seals)
448*22ce4affSfengbojiang {
449*22ce4affSfengbojiang 
450*22ce4affSfengbojiang 	if (fp->f_ops->fo_add_seals == NULL)
451*22ce4affSfengbojiang 		return (EINVAL);
452*22ce4affSfengbojiang 	return ((*fp->f_ops->fo_add_seals)(fp, seals));
453*22ce4affSfengbojiang }
454*22ce4affSfengbojiang 
455*22ce4affSfengbojiang static __inline int
fo_get_seals(struct file * fp,int * seals)456*22ce4affSfengbojiang fo_get_seals(struct file *fp, int *seals)
457*22ce4affSfengbojiang {
458*22ce4affSfengbojiang 
459*22ce4affSfengbojiang 	if (fp->f_ops->fo_get_seals == NULL)
460*22ce4affSfengbojiang 		return (EINVAL);
461*22ce4affSfengbojiang 	return ((*fp->f_ops->fo_get_seals)(fp, seals));
462*22ce4affSfengbojiang }
463*22ce4affSfengbojiang 
464*22ce4affSfengbojiang static __inline int
fo_fallocate(struct file * fp,off_t offset,off_t len,struct thread * td)465*22ce4affSfengbojiang fo_fallocate(struct file *fp, off_t offset, off_t len, struct thread *td)
466*22ce4affSfengbojiang {
467*22ce4affSfengbojiang 
468*22ce4affSfengbojiang 	if (fp->f_ops->fo_fallocate == NULL)
469*22ce4affSfengbojiang 		return (ENODEV);
470*22ce4affSfengbojiang 	return ((*fp->f_ops->fo_fallocate)(fp, offset, len, td));
471*22ce4affSfengbojiang }
472*22ce4affSfengbojiang 
473a9643ea8Slogwang #endif /* _KERNEL */
474a9643ea8Slogwang 
475a9643ea8Slogwang #endif /* !SYS_FILE_H */
476