fs.h revision 271127
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#ifndef _LINUX_FS_H_ 30#define _LINUX_FS_H_ 31 32#include <sys/systm.h> 33#include <sys/conf.h> 34#include <sys/vnode.h> 35#include <sys/file.h> 36#include <sys/filedesc.h> 37#include <linux/types.h> 38#include <linux/wait.h> 39#include <linux/semaphore.h> 40 41struct module; 42struct kiocb; 43struct iovec; 44struct dentry; 45struct page; 46struct file_lock; 47struct pipe_inode_info; 48struct vm_area_struct; 49struct poll_table_struct; 50struct files_struct; 51 52#define inode vnode 53#define i_cdev v_rdev 54 55#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 56#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 57 58 59typedef struct files_struct *fl_owner_t; 60 61struct dentry { 62 struct inode *d_inode; 63}; 64 65struct file_operations; 66 67struct linux_file { 68 struct file *_file; 69 const struct file_operations *f_op; 70 void *private_data; 71 int f_flags; 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; 78}; 79 80#define file linux_file 81#define fasync_struct sigio * 82 83#define fasync_helper(fd, filp, on, queue) \ 84({ \ 85 if ((on)) \ 86 *(queue) = &(filp)->f_sigio; \ 87 else \ 88 *(queue) = NULL; \ 89 0; \ 90}) 91 92#define kill_fasync(queue, sig, pollstat) \ 93do { \ 94 if (*(queue) != NULL) \ 95 pgsigio(*(queue), (sig), 0); \ 96} while (0) 97 98typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 99 100struct 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); 110 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 114 */ 115 loff_t (*llseek)(struct file *, loff_t, int); 116#if 0 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, 125 unsigned long); 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, 132 loff_t *, int); 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 **); 142#endif 143}; 144#define fops_get(fops) (fops) 145 146#define FMODE_READ FREAD 147#define FMODE_WRITE FWRITE 148#define FMODE_EXEC FEXEC 149 150static inline int 151register_chrdev_region(dev_t dev, unsigned range, const char *name) 152{ 153 154 return 0; 155} 156 157static inline void 158unregister_chrdev_region(dev_t dev, unsigned range) 159{ 160 161 return; 162} 163 164static inline int 165alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, 166 const char *name) 167{ 168 169 return 0; 170} 171 172/* No current support for seek op in FreeBSD */ 173static inline int 174nonseekable_open(struct inode *inode, struct file *filp) 175{ 176 return 0; 177} 178 179static inline dev_t 180iminor(struct inode *inode) 181{ 182 183 return dev2unit(inode->v_rdev); 184} 185 186static inline struct inode * 187igrab(struct inode *inode) 188{ 189 int error; 190 191 error = vget(inode, 0, curthread); 192 if (error) 193 return (NULL); 194 195 return (inode); 196} 197 198static inline void 199iput(struct inode *inode) 200{ 201 202 vrele(inode); 203} 204 205static inline loff_t 206no_llseek(struct file *file, loff_t offset, int whence) 207{ 208 return -ESPIPE; 209} 210 211#endif /* _LINUX_FS_H_ */ 212