2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013 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.
32 #include <sys/systm.h>
34 #include <sys/vnode.h>
36 #include <sys/filedesc.h>
37 #include <linux/types.h>
38 #include <linux/wait.h>
39 #include <linux/semaphore.h>
47 struct pipe_inode_info;
48 struct vm_area_struct;
49 struct poll_table_struct;
55 #define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
56 #define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
59 typedef struct files_struct *fl_owner_t;
62 struct inode *d_inode;
65 struct file_operations;
69 const struct file_operations *f_op;
72 int f_mode; /* Just starting mode. */
73 struct dentry *f_dentry;
74 struct dentry f_dentry_store;
75 struct selinfo f_selinfo;
76 struct sigio *f_sigio;
77 struct vnode *f_vnode;
80 #define file linux_file
81 #define fasync_struct sigio *
83 #define fasync_helper(fd, filp, on, queue) \
86 *(queue) = &(filp)->f_sigio; \
92 #define kill_fasync(queue, sig, pollstat) \
94 if (*(queue) != NULL) \
95 pgsigio(*(queue), (sig), 0); \
98 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
100 struct file_operations {
101 struct module *owner;
102 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
103 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
104 unsigned int (*poll) (struct file *, struct poll_table_struct *);
105 long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long);
106 int (*mmap)(struct file *, struct vm_area_struct *);
107 int (*open)(struct inode *, struct file *);
108 int (*release)(struct inode *, struct file *);
109 int (*fasync)(int, struct file *, int);
111 /* Although not supported in FreeBSD, to align with Linux code
112 * we are adding llseek() only when it is mapped to no_llseek which returns
113 * an illegal seek error
115 loff_t (*llseek)(struct file *, loff_t, int);
117 /* We do not support these methods. Don't permit them to compile. */
118 loff_t (*llseek)(struct file *, loff_t, int);
119 ssize_t (*aio_read)(struct kiocb *, const struct iovec *,
120 unsigned long, loff_t);
121 ssize_t (*aio_write)(struct kiocb *, const struct iovec *,
122 unsigned long, loff_t);
123 int (*readdir)(struct file *, void *, filldir_t);
124 int (*ioctl)(struct inode *, struct file *, unsigned int,
126 long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
127 int (*flush)(struct file *, fl_owner_t id);
128 int (*fsync)(struct file *, struct dentry *, int datasync);
129 int (*aio_fsync)(struct kiocb *, int datasync);
130 int (*lock)(struct file *, int, struct file_lock *);
131 ssize_t (*sendpage)(struct file *, struct page *, int, size_t,
133 unsigned long (*get_unmapped_area)(struct file *, unsigned long,
134 unsigned long, unsigned long, unsigned long);
135 int (*check_flags)(int);
136 int (*flock)(struct file *, int, struct file_lock *);
137 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
138 loff_t *, size_t, unsigned int);
139 ssize_t (*splice_read)(struct file *, loff_t *,
140 struct pipe_inode_info *, size_t, unsigned int);
141 int (*setlease)(struct file *, long, struct file_lock **);
144 #define fops_get(fops) (fops)
146 #define FMODE_READ FREAD
147 #define FMODE_WRITE FWRITE
148 #define FMODE_EXEC FEXEC
151 register_chrdev_region(dev_t dev, unsigned range, const char *name)
158 unregister_chrdev_region(dev_t dev, unsigned range)
165 alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
172 /* No current support for seek op in FreeBSD */
174 nonseekable_open(struct inode *inode, struct file *filp)
180 iminor(struct inode *inode)
183 return dev2unit(inode->v_rdev);
186 static inline struct inode *
187 igrab(struct inode *inode)
191 error = vget(inode, 0, curthread);
199 iput(struct inode *inode)
206 no_llseek(struct file *file, loff_t offset, int whence)
211 #endif /* _LINUX_FS_H_ */