1 /*- 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. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice unmodified, this list of conditions, and the following 13 * disclaimer. 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. 17 * 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. 28 * 29 * $FreeBSD$ 30 */ 31 #ifndef _LINUX_FS_H_ 32 #define _LINUX_FS_H_ 33 34 #include <sys/cdefs.h> 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/conf.h> 38 #include <sys/vnode.h> 39 #include <sys/file.h> 40 #include <sys/filedesc.h> 41 #include <linux/types.h> 42 #include <linux/wait.h> 43 #include <linux/semaphore.h> 44 45 struct module; 46 struct kiocb; 47 struct iovec; 48 struct dentry; 49 struct page; 50 struct file_lock; 51 struct pipe_inode_info; 52 struct vm_area_struct; 53 struct poll_table_struct; 54 struct files_struct; 55 56 #define inode vnode 57 #define i_cdev v_rdev 58 59 #define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 60 #define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 61 62 63 typedef struct files_struct *fl_owner_t; 64 65 struct dentry { 66 struct inode *d_inode; 67 }; 68 69 struct file_operations; 70 71 struct linux_file { 72 struct file *_file; 73 const struct file_operations *f_op; 74 void *private_data; 75 int f_flags; 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; 82 }; 83 84 #define file linux_file 85 #define fasync_struct sigio * 86 87 #define fasync_helper(fd, filp, on, queue) \ 88 ({ \ 89 if ((on)) \ 90 *(queue) = &(filp)->f_sigio; \ 91 else \ 92 *(queue) = NULL; \ 93 0; \ 94 }) 95 96 #define kill_fasync(queue, sig, pollstat) \ 97 do { \ 98 if (*(queue) != NULL) \ 99 pgsigio(*(queue), (sig), 0); \ 100 } while (0) 101 102 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 103 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); 114 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 118 */ 119 loff_t (*llseek)(struct file *, loff_t, int); 120 #if 0 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, 129 unsigned long); 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, 136 loff_t *, int); 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 **); 146 #endif 147 }; 148 #define fops_get(fops) (fops) 149 150 #define FMODE_READ FREAD 151 #define FMODE_WRITE FWRITE 152 #define FMODE_EXEC FEXEC 153 154 static inline int 155 register_chrdev_region(dev_t dev, unsigned range, const char *name) 156 { 157 158 return 0; 159 } 160 161 static inline void 162 unregister_chrdev_region(dev_t dev, unsigned range) 163 { 164 165 return; 166 } 167 168 static inline int 169 alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, 170 const char *name) 171 { 172 173 return 0; 174 } 175 176 /* No current support for seek op in FreeBSD */ 177 static inline int 178 nonseekable_open(struct inode *inode, struct file *filp) 179 { 180 return 0; 181 } 182 183 static inline dev_t 184 iminor(struct inode *inode) 185 { 186 187 return dev2unit(inode->v_rdev); 188 } 189 190 static inline struct inode * 191 igrab(struct inode *inode) 192 { 193 int error; 194 195 error = vget(inode, 0, curthread); 196 if (error) 197 return (NULL); 198 199 return (inode); 200 } 201 202 static inline void 203 iput(struct inode *inode) 204 { 205 206 vrele(inode); 207 } 208 209 static inline loff_t 210 no_llseek(struct file *file, loff_t offset, int whence) 211 { 212 return -ESPIPE; 213 } 214 215 #endif /* _LINUX_FS_H_ */ 216