fs.h revision 289624
1/* $FreeBSD: head/sys/ofed/include/linux/fs.h 289624 2015-10-20 11:40:04Z hselasky $ */
2/*-
3 * Copyright (c) 2010 Isilon Systems, Inc.
4 * Copyright (c) 2010 iX Systems, Inc.
5 * Copyright (c) 2010 Panasas, Inc.
6 * Copyright (c) 2013 Mellanox Technologies, Ltd.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice unmodified, this list of conditions, and the following
14 *    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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30#ifndef	_LINUX_FS_H_
31#define	_LINUX_FS_H_
32
33#include <sys/cdefs.h>
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/conf.h>
37#include <sys/vnode.h>
38#include <sys/file.h>
39#include <sys/filedesc.h>
40#include <linux/types.h>
41#include <linux/wait.h>
42#include <linux/semaphore.h>
43
44struct module;
45struct kiocb;
46struct iovec;
47struct dentry;
48struct page;
49struct file_lock;
50struct pipe_inode_info;
51struct vm_area_struct;
52struct poll_table_struct;
53struct files_struct;
54
55#define	inode	vnode
56#define	i_cdev	v_rdev
57
58#define	S_IRUGO	(S_IRUSR | S_IRGRP | S_IROTH)
59#define	S_IWUGO	(S_IWUSR | S_IWGRP | S_IWOTH)
60
61
62typedef struct files_struct *fl_owner_t;
63
64struct dentry {
65	struct inode	*d_inode;
66};
67
68struct file_operations;
69
70struct linux_file {
71	struct file	*_file;
72	const struct file_operations	*f_op;
73	void 		*private_data;
74	int		f_flags;
75	int		f_mode;	/* Just starting mode. */
76	struct dentry	*f_dentry;
77	struct dentry	f_dentry_store;
78	struct selinfo	f_selinfo;
79	struct sigio	*f_sigio;
80	struct vnode	*f_vnode;
81};
82
83#define	file		linux_file
84#define	fasync_struct	sigio *
85
86#define	fasync_helper(fd, filp, on, queue)				\
87({									\
88	if ((on))							\
89		*(queue) = &(filp)->f_sigio;				\
90	else								\
91		*(queue) = NULL;					\
92	0;								\
93})
94
95#define	kill_fasync(queue, sig, pollstat)				\
96do {									\
97	if (*(queue) != NULL)						\
98		pgsigio(*(queue), (sig), 0);				\
99} while (0)
100
101typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
102
103struct file_operations {
104	struct module *owner;
105	ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
106	ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
107	unsigned int (*poll) (struct file *, struct poll_table_struct *);
108	long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long);
109	int (*mmap)(struct file *, struct vm_area_struct *);
110	int (*open)(struct inode *, struct file *);
111	int (*release)(struct inode *, struct file *);
112	int (*fasync)(int, struct file *, int);
113
114/* Although not supported in FreeBSD, to align with Linux code
115 * we are adding llseek() only when it is mapped to no_llseek which returns
116 * an illegal seek error
117 */
118	loff_t (*llseek)(struct file *, loff_t, int);
119#if 0
120	/* We do not support these methods.  Don't permit them to compile. */
121	loff_t (*llseek)(struct file *, loff_t, int);
122	ssize_t (*aio_read)(struct kiocb *, const struct iovec *,
123	    unsigned long, loff_t);
124	ssize_t (*aio_write)(struct kiocb *, const struct iovec *,
125	    unsigned long, loff_t);
126	int (*readdir)(struct file *, void *, filldir_t);
127	int (*ioctl)(struct inode *, struct file *, unsigned int,
128	    unsigned long);
129	long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
130	int (*flush)(struct file *, fl_owner_t id);
131	int (*fsync)(struct file *, struct dentry *, int datasync);
132	int (*aio_fsync)(struct kiocb *, int datasync);
133	int (*lock)(struct file *, int, struct file_lock *);
134	ssize_t (*sendpage)(struct file *, struct page *, int, size_t,
135	    loff_t *, int);
136	unsigned long (*get_unmapped_area)(struct file *, unsigned long,
137	    unsigned long, unsigned long, unsigned long);
138	int (*check_flags)(int);
139	int (*flock)(struct file *, int, struct file_lock *);
140	ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
141	    loff_t *, size_t, unsigned int);
142	ssize_t (*splice_read)(struct file *, loff_t *,
143	    struct pipe_inode_info *, size_t, unsigned int);
144	int (*setlease)(struct file *, long, struct file_lock **);
145#endif
146};
147#define	fops_get(fops)	(fops)
148
149#define	FMODE_READ	FREAD
150#define	FMODE_WRITE	FWRITE
151#define	FMODE_EXEC	FEXEC
152
153static inline int
154register_chrdev_region(dev_t dev, unsigned range, const char *name)
155{
156
157	return 0;
158}
159
160static inline void
161unregister_chrdev_region(dev_t dev, unsigned range)
162{
163
164	return;
165}
166
167static inline int
168alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
169			const char *name)
170{
171
172	return 0;
173}
174
175/* No current support for seek op in FreeBSD */
176static inline int
177nonseekable_open(struct inode *inode, struct file *filp)
178{
179	return 0;
180}
181
182static inline dev_t
183iminor(struct inode *inode)
184{
185
186	return dev2unit(inode->v_rdev);
187}
188
189static inline struct inode *
190igrab(struct inode *inode)
191{
192	int error;
193
194	error = vget(inode, 0, curthread);
195	if (error)
196		return (NULL);
197
198	return (inode);
199}
200
201static inline void
202iput(struct inode *inode)
203{
204
205	vrele(inode);
206}
207
208static inline loff_t
209no_llseek(struct file *file, loff_t offset, int whence)
210{
211        return -ESPIPE;
212}
213
214#endif /* _LINUX_FS_H_ */
215