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/cdefs.h> 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/conf.h> 36#include <sys/vnode.h> 37#include <sys/file.h> 38#include <sys/filedesc.h> 39#include <linux/types.h> 40#include <linux/wait.h> 41#include <linux/semaphore.h> 42 43struct module; 44struct kiocb; 45struct iovec; 46struct dentry; 47struct page; 48struct file_lock; 49struct pipe_inode_info; 50struct vm_area_struct; 51struct poll_table_struct; 52struct files_struct; 53 54#define inode vnode 55#define i_cdev v_rdev 56 57#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 58#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 59 60 61typedef struct files_struct *fl_owner_t; 62 63struct dentry { 64 struct inode *d_inode; 65}; 66 67struct file_operations; 68 69struct linux_file { 70 struct file *_file; 71 const struct file_operations *f_op; 72 void *private_data; 73 int f_flags; 74 int f_mode; /* Just starting mode. */ 75 struct dentry *f_dentry; 76 struct dentry f_dentry_store; 77 struct selinfo f_selinfo; 78 struct sigio *f_sigio; 79 struct vnode *f_vnode; 80}; 81 82#define file linux_file 83#define fasync_struct sigio * 84 85#define fasync_helper(fd, filp, on, queue) \ 86({ \ 87 if ((on)) \ 88 *(queue) = &(filp)->f_sigio; \ 89 else \ 90 *(queue) = NULL; \ 91 0; \ 92}) 93 94#define kill_fasync(queue, sig, pollstat) \ 95do { \ 96 if (*(queue) != NULL) \ 97 pgsigio(*(queue), (sig), 0); \ 98} while (0) 99 100typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 101 102struct file_operations { 103 struct module *owner; 104 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); 105 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); 106 unsigned int (*poll) (struct file *, struct poll_table_struct *); 107 long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long); 108 int (*mmap)(struct file *, struct vm_area_struct *); 109 int (*open)(struct inode *, struct file *); 110 int (*release)(struct inode *, struct file *); 111 int (*fasync)(int, struct file *, int); 112 113/* Although not supported in FreeBSD, to align with Linux code 114 * we are adding llseek() only when it is mapped to no_llseek which returns 115 * an illegal seek error 116 */ 117 loff_t (*llseek)(struct file *, loff_t, int); 118#if 0 119 /* We do not support these methods. Don't permit them to compile. */ 120 loff_t (*llseek)(struct file *, loff_t, int); 121 ssize_t (*aio_read)(struct kiocb *, const struct iovec *, 122 unsigned long, loff_t); 123 ssize_t (*aio_write)(struct kiocb *, const struct iovec *, 124 unsigned long, loff_t); 125 int (*readdir)(struct file *, void *, filldir_t); 126 int (*ioctl)(struct inode *, struct file *, unsigned int, 127 unsigned long); 128 long (*compat_ioctl)(struct file *, unsigned int, unsigned long); 129 int (*flush)(struct file *, fl_owner_t id); 130 int (*fsync)(struct file *, struct dentry *, int datasync); 131 int (*aio_fsync)(struct kiocb *, int datasync); 132 int (*lock)(struct file *, int, struct file_lock *); 133 ssize_t (*sendpage)(struct file *, struct page *, int, size_t, 134 loff_t *, int); 135 unsigned long (*get_unmapped_area)(struct file *, unsigned long, 136 unsigned long, unsigned long, unsigned long); 137 int (*check_flags)(int); 138 int (*flock)(struct file *, int, struct file_lock *); 139 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, 140 loff_t *, size_t, unsigned int); 141 ssize_t (*splice_read)(struct file *, loff_t *, 142 struct pipe_inode_info *, size_t, unsigned int); 143 int (*setlease)(struct file *, long, struct file_lock **); 144#endif 145}; 146#define fops_get(fops) (fops) 147 148#define FMODE_READ FREAD 149#define FMODE_WRITE FWRITE 150#define FMODE_EXEC FEXEC 151 152static inline int 153register_chrdev_region(dev_t dev, unsigned range, const char *name) 154{ 155 156 return 0; 157} 158 159static inline void 160unregister_chrdev_region(dev_t dev, unsigned range) 161{ 162 163 return; 164} 165 166static inline int 167alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, 168 const char *name) 169{ 170 171 return 0; 172} 173 174/* No current support for seek op in FreeBSD */ 175static inline int 176nonseekable_open(struct inode *inode, struct file *filp) 177{ 178 return 0; 179} 180 181static inline dev_t 182iminor(struct inode *inode) 183{ 184 185 return dev2unit(inode->v_rdev); 186} 187 188static inline struct inode * 189igrab(struct inode *inode) 190{ 191 int error; 192 193 error = vget(inode, 0, curthread); 194 if (error) 195 return (NULL); 196 197 return (inode); 198} 199 200static inline void 201iput(struct inode *inode) 202{ 203 204 vrele(inode); 205} 206 207static inline loff_t 208no_llseek(struct file *file, loff_t offset, int whence) 209{ 210 return -ESPIPE; 211} 212 213#endif /* _LINUX_FS_H_ */ 214