1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5271127Shselasky * Copyright (c) 2013 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28219820Sjeff */ 29219820Sjeff#ifndef _LINUX_FS_H_ 30219820Sjeff#define _LINUX_FS_H_ 31219820Sjeff 32219820Sjeff#include <sys/systm.h> 33219820Sjeff#include <sys/conf.h> 34219820Sjeff#include <sys/vnode.h> 35219820Sjeff#include <sys/file.h> 36219820Sjeff#include <sys/filedesc.h> 37219820Sjeff#include <linux/types.h> 38219820Sjeff#include <linux/wait.h> 39219820Sjeff#include <linux/semaphore.h> 40219820Sjeff 41219820Sjeffstruct module; 42219820Sjeffstruct kiocb; 43219820Sjeffstruct iovec; 44219820Sjeffstruct dentry; 45219820Sjeffstruct page; 46219820Sjeffstruct file_lock; 47219820Sjeffstruct pipe_inode_info; 48219820Sjeffstruct vm_area_struct; 49219820Sjeffstruct poll_table_struct; 50219820Sjeffstruct files_struct; 51219820Sjeff 52219820Sjeff#define inode vnode 53219820Sjeff#define i_cdev v_rdev 54219820Sjeff 55219820Sjeff#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 56219820Sjeff#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 57219820Sjeff 58219820Sjeff 59219820Sjefftypedef struct files_struct *fl_owner_t; 60219820Sjeff 61219820Sjeffstruct dentry { 62219820Sjeff struct inode *d_inode; 63219820Sjeff}; 64219820Sjeff 65219820Sjeffstruct file_operations; 66219820Sjeff 67219820Sjeffstruct linux_file { 68219820Sjeff struct file *_file; 69219820Sjeff const struct file_operations *f_op; 70219820Sjeff void *private_data; 71219820Sjeff int f_flags; 72219820Sjeff int f_mode; /* Just starting mode. */ 73219820Sjeff struct dentry *f_dentry; 74219820Sjeff struct dentry f_dentry_store; 75219820Sjeff struct selinfo f_selinfo; 76219820Sjeff struct sigio *f_sigio; 77251617Sjhb struct vnode *f_vnode; 78219820Sjeff}; 79219820Sjeff 80219820Sjeff#define file linux_file 81219820Sjeff#define fasync_struct sigio * 82219820Sjeff 83219820Sjeff#define fasync_helper(fd, filp, on, queue) \ 84219820Sjeff({ \ 85219820Sjeff if ((on)) \ 86219820Sjeff *(queue) = &(filp)->f_sigio; \ 87219820Sjeff else \ 88219820Sjeff *(queue) = NULL; \ 89219820Sjeff 0; \ 90219820Sjeff}) 91219820Sjeff 92219820Sjeff#define kill_fasync(queue, sig, pollstat) \ 93219820Sjeffdo { \ 94219820Sjeff if (*(queue) != NULL) \ 95219820Sjeff pgsigio(*(queue), (sig), 0); \ 96219820Sjeff} while (0) 97219820Sjeff 98219820Sjefftypedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 99219820Sjeff 100219820Sjeffstruct file_operations { 101219820Sjeff struct module *owner; 102219820Sjeff ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); 103219820Sjeff ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); 104219820Sjeff unsigned int (*poll) (struct file *, struct poll_table_struct *); 105219820Sjeff long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long); 106219820Sjeff int (*mmap)(struct file *, struct vm_area_struct *); 107219820Sjeff int (*open)(struct inode *, struct file *); 108219820Sjeff int (*release)(struct inode *, struct file *); 109219820Sjeff int (*fasync)(int, struct file *, int); 110271127Shselasky 111271127Shselasky/* Although not supported in FreeBSD, to align with Linux code 112271127Shselasky * we are adding llseek() only when it is mapped to no_llseek which returns 113271127Shselasky * an illegal seek error 114271127Shselasky */ 115271127Shselasky loff_t (*llseek)(struct file *, loff_t, int); 116219820Sjeff#if 0 117219820Sjeff /* We do not support these methods. Don't permit them to compile. */ 118219820Sjeff loff_t (*llseek)(struct file *, loff_t, int); 119219820Sjeff ssize_t (*aio_read)(struct kiocb *, const struct iovec *, 120219820Sjeff unsigned long, loff_t); 121219820Sjeff ssize_t (*aio_write)(struct kiocb *, const struct iovec *, 122219820Sjeff unsigned long, loff_t); 123219820Sjeff int (*readdir)(struct file *, void *, filldir_t); 124219820Sjeff int (*ioctl)(struct inode *, struct file *, unsigned int, 125219820Sjeff unsigned long); 126219820Sjeff long (*compat_ioctl)(struct file *, unsigned int, unsigned long); 127219820Sjeff int (*flush)(struct file *, fl_owner_t id); 128219820Sjeff int (*fsync)(struct file *, struct dentry *, int datasync); 129219820Sjeff int (*aio_fsync)(struct kiocb *, int datasync); 130219820Sjeff int (*lock)(struct file *, int, struct file_lock *); 131219820Sjeff ssize_t (*sendpage)(struct file *, struct page *, int, size_t, 132219820Sjeff loff_t *, int); 133219820Sjeff unsigned long (*get_unmapped_area)(struct file *, unsigned long, 134219820Sjeff unsigned long, unsigned long, unsigned long); 135219820Sjeff int (*check_flags)(int); 136219820Sjeff int (*flock)(struct file *, int, struct file_lock *); 137219820Sjeff ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, 138219820Sjeff loff_t *, size_t, unsigned int); 139219820Sjeff ssize_t (*splice_read)(struct file *, loff_t *, 140219820Sjeff struct pipe_inode_info *, size_t, unsigned int); 141219820Sjeff int (*setlease)(struct file *, long, struct file_lock **); 142219820Sjeff#endif 143219820Sjeff}; 144219820Sjeff#define fops_get(fops) (fops) 145219820Sjeff 146219820Sjeff#define FMODE_READ FREAD 147219820Sjeff#define FMODE_WRITE FWRITE 148219820Sjeff#define FMODE_EXEC FEXEC 149219820Sjeff 150219820Sjeffstatic inline int 151219820Sjeffregister_chrdev_region(dev_t dev, unsigned range, const char *name) 152219820Sjeff{ 153219820Sjeff 154219820Sjeff return 0; 155219820Sjeff} 156219820Sjeff 157219820Sjeffstatic inline void 158219820Sjeffunregister_chrdev_region(dev_t dev, unsigned range) 159219820Sjeff{ 160219820Sjeff 161219820Sjeff return; 162219820Sjeff} 163219820Sjeff 164271127Shselaskystatic inline int 165271127Shselaskyalloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, 166271127Shselasky const char *name) 167271127Shselasky{ 168271127Shselasky 169271127Shselasky return 0; 170271127Shselasky} 171271127Shselasky 172271127Shselasky/* No current support for seek op in FreeBSD */ 173271127Shselaskystatic inline int 174271127Shselaskynonseekable_open(struct inode *inode, struct file *filp) 175271127Shselasky{ 176271127Shselasky return 0; 177271127Shselasky} 178271127Shselasky 179219820Sjeffstatic inline dev_t 180219820Sjeffiminor(struct inode *inode) 181219820Sjeff{ 182219820Sjeff 183219820Sjeff return dev2unit(inode->v_rdev); 184219820Sjeff} 185219820Sjeff 186219820Sjeffstatic inline struct inode * 187219820Sjeffigrab(struct inode *inode) 188219820Sjeff{ 189219820Sjeff int error; 190219820Sjeff 191219820Sjeff error = vget(inode, 0, curthread); 192219820Sjeff if (error) 193219820Sjeff return (NULL); 194219820Sjeff 195219820Sjeff return (inode); 196219820Sjeff} 197219820Sjeff 198219820Sjeffstatic inline void 199219820Sjeffiput(struct inode *inode) 200219820Sjeff{ 201219820Sjeff 202219820Sjeff vrele(inode); 203219820Sjeff} 204219820Sjeff 205271127Shselaskystatic inline loff_t 206271127Shselaskyno_llseek(struct file *file, loff_t offset, int whence) 207271127Shselasky{ 208271127Shselasky return -ESPIPE; 209271127Shselasky} 210271127Shselasky 211271127Shselasky#endif /* _LINUX_FS_H_ */ 212