2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/vnode.h>
40 #include <sys/filedesc.h>
41 #include <linux/types.h>
42 #include <linux/wait.h>
43 #include <linux/semaphore.h>
51 struct pipe_inode_info;
52 struct vm_area_struct;
53 struct poll_table_struct;
59 #define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
60 #define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
63 typedef struct files_struct *fl_owner_t;
66 struct inode *d_inode;
69 struct file_operations;
73 const struct file_operations *f_op;
76 int f_mode; /* Just starting mode. */
77 struct dentry *f_dentry;
78 struct dentry f_dentry_store;
79 struct selinfo f_selinfo;
80 struct sigio *f_sigio;
81 struct vnode *f_vnode;
84 #define file linux_file
85 #define fasync_struct sigio *
87 #define fasync_helper(fd, filp, on, queue) \
90 *(queue) = &(filp)->f_sigio; \
96 #define kill_fasync(queue, sig, pollstat) \
98 if (*(queue) != NULL) \
99 pgsigio(*(queue), (sig), 0); \
102 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
104 struct file_operations {
105 struct module *owner;
106 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
107 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
108 unsigned int (*poll) (struct file *, struct poll_table_struct *);
109 long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long);
110 int (*mmap)(struct file *, struct vm_area_struct *);
111 int (*open)(struct inode *, struct file *);
112 int (*release)(struct inode *, struct file *);
113 int (*fasync)(int, struct file *, int);
115 /* Although not supported in FreeBSD, to align with Linux code
116 * we are adding llseek() only when it is mapped to no_llseek which returns
117 * an illegal seek error
119 loff_t (*llseek)(struct file *, loff_t, int);
121 /* We do not support these methods. Don't permit them to compile. */
122 loff_t (*llseek)(struct file *, loff_t, int);
123 ssize_t (*aio_read)(struct kiocb *, const struct iovec *,
124 unsigned long, loff_t);
125 ssize_t (*aio_write)(struct kiocb *, const struct iovec *,
126 unsigned long, loff_t);
127 int (*readdir)(struct file *, void *, filldir_t);
128 int (*ioctl)(struct inode *, struct file *, unsigned int,
130 long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
131 int (*flush)(struct file *, fl_owner_t id);
132 int (*fsync)(struct file *, struct dentry *, int datasync);
133 int (*aio_fsync)(struct kiocb *, int datasync);
134 int (*lock)(struct file *, int, struct file_lock *);
135 ssize_t (*sendpage)(struct file *, struct page *, int, size_t,
137 unsigned long (*get_unmapped_area)(struct file *, unsigned long,
138 unsigned long, unsigned long, unsigned long);
139 int (*check_flags)(int);
140 int (*flock)(struct file *, int, struct file_lock *);
141 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
142 loff_t *, size_t, unsigned int);
143 ssize_t (*splice_read)(struct file *, loff_t *,
144 struct pipe_inode_info *, size_t, unsigned int);
145 int (*setlease)(struct file *, long, struct file_lock **);
148 #define fops_get(fops) (fops)
150 #define FMODE_READ FREAD
151 #define FMODE_WRITE FWRITE
152 #define FMODE_EXEC FEXEC
154 int __register_chrdev(unsigned int major, unsigned int baseminor,
155 unsigned int count, const char *name,
156 const struct file_operations *fops);
157 int __register_chrdev_p(unsigned int major, unsigned int baseminor,
158 unsigned int count, const char *name,
159 const struct file_operations *fops, uid_t uid,
160 gid_t gid, int mode);
161 void __unregister_chrdev(unsigned int major, unsigned int baseminor,
162 unsigned int count, const char *name);
165 unregister_chrdev(unsigned int major, const char *name)
168 __unregister_chrdev(major, 0, 256, name);
172 register_chrdev(unsigned int major, const char *name,
173 const struct file_operations *fops)
176 return (__register_chrdev(major, 0, 256, name, fops));
180 register_chrdev_p(unsigned int major, const char *name,
181 const struct file_operations *fops, uid_t uid, gid_t gid, int mode)
184 return (__register_chrdev_p(major, 0, 256, name, fops, uid, gid, mode));
188 register_chrdev_region(dev_t dev, unsigned range, const char *name)
195 unregister_chrdev_region(dev_t dev, unsigned range)
202 alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
209 /* No current support for seek op in FreeBSD */
211 nonseekable_open(struct inode *inode, struct file *filp)
217 iminor(struct inode *inode)
220 return (minor(dev2unit(inode->v_rdev)));
223 static inline struct inode *
224 igrab(struct inode *inode)
228 error = vget(inode, 0, curthread);
236 iput(struct inode *inode)
243 no_llseek(struct file *file, loff_t offset, int whence)
248 #endif /* _LINUX_FS_H_ */