fs.h revision 251617
1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5219820Sjeff * All rights reserved. 6219820Sjeff * 7219820Sjeff * Redistribution and use in source and binary forms, with or without 8219820Sjeff * modification, are permitted provided that the following conditions 9219820Sjeff * are met: 10219820Sjeff * 1. Redistributions of source code must retain the above copyright 11219820Sjeff * notice unmodified, this list of conditions, and the following 12219820Sjeff * disclaimer. 13219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 14219820Sjeff * notice, this list of conditions and the following disclaimer in the 15219820Sjeff * documentation and/or other materials provided with the distribution. 16219820Sjeff * 17219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27219820Sjeff */ 28219820Sjeff#ifndef _LINUX_FS_H_ 29219820Sjeff#define _LINUX_FS_H_ 30219820Sjeff 31219820Sjeff#include <sys/systm.h> 32219820Sjeff#include <sys/conf.h> 33219820Sjeff#include <sys/vnode.h> 34219820Sjeff#include <sys/file.h> 35219820Sjeff#include <sys/filedesc.h> 36219820Sjeff#include <linux/types.h> 37219820Sjeff#include <linux/wait.h> 38219820Sjeff#include <linux/semaphore.h> 39219820Sjeff 40219820Sjeffstruct module; 41219820Sjeffstruct kiocb; 42219820Sjeffstruct iovec; 43219820Sjeffstruct dentry; 44219820Sjeffstruct page; 45219820Sjeffstruct file_lock; 46219820Sjeffstruct pipe_inode_info; 47219820Sjeffstruct vm_area_struct; 48219820Sjeffstruct poll_table_struct; 49219820Sjeffstruct files_struct; 50219820Sjeff 51219820Sjeff#define inode vnode 52219820Sjeff#define i_cdev v_rdev 53219820Sjeff 54219820Sjeff#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 55219820Sjeff#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 56219820Sjeff 57219820Sjeff 58219820Sjefftypedef struct files_struct *fl_owner_t; 59219820Sjeff 60219820Sjeffstruct dentry { 61219820Sjeff struct inode *d_inode; 62219820Sjeff}; 63219820Sjeff 64219820Sjeffstruct file_operations; 65219820Sjeff 66219820Sjeffstruct linux_file { 67219820Sjeff struct file *_file; 68219820Sjeff const struct file_operations *f_op; 69219820Sjeff void *private_data; 70219820Sjeff int f_flags; 71219820Sjeff int f_mode; /* Just starting mode. */ 72219820Sjeff struct dentry *f_dentry; 73219820Sjeff struct dentry f_dentry_store; 74219820Sjeff struct selinfo f_selinfo; 75219820Sjeff struct sigio *f_sigio; 76251617Sjhb struct vnode *f_vnode; 77219820Sjeff}; 78219820Sjeff 79219820Sjeff#define file linux_file 80219820Sjeff#define fasync_struct sigio * 81219820Sjeff 82219820Sjeff#define fasync_helper(fd, filp, on, queue) \ 83219820Sjeff({ \ 84219820Sjeff if ((on)) \ 85219820Sjeff *(queue) = &(filp)->f_sigio; \ 86219820Sjeff else \ 87219820Sjeff *(queue) = NULL; \ 88219820Sjeff 0; \ 89219820Sjeff}) 90219820Sjeff 91219820Sjeff#define kill_fasync(queue, sig, pollstat) \ 92219820Sjeffdo { \ 93219820Sjeff if (*(queue) != NULL) \ 94219820Sjeff pgsigio(*(queue), (sig), 0); \ 95219820Sjeff} while (0) 96219820Sjeff 97219820Sjefftypedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 98219820Sjeff 99219820Sjeffstruct file_operations { 100219820Sjeff struct module *owner; 101219820Sjeff ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); 102219820Sjeff ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); 103219820Sjeff unsigned int (*poll) (struct file *, struct poll_table_struct *); 104219820Sjeff long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long); 105219820Sjeff int (*mmap)(struct file *, struct vm_area_struct *); 106219820Sjeff int (*open)(struct inode *, struct file *); 107219820Sjeff int (*release)(struct inode *, struct file *); 108219820Sjeff int (*fasync)(int, struct file *, int); 109219820Sjeff#if 0 110219820Sjeff /* We do not support these methods. Don't permit them to compile. */ 111219820Sjeff loff_t (*llseek)(struct file *, loff_t, int); 112219820Sjeff ssize_t (*aio_read)(struct kiocb *, const struct iovec *, 113219820Sjeff unsigned long, loff_t); 114219820Sjeff ssize_t (*aio_write)(struct kiocb *, const struct iovec *, 115219820Sjeff unsigned long, loff_t); 116219820Sjeff int (*readdir)(struct file *, void *, filldir_t); 117219820Sjeff int (*ioctl)(struct inode *, struct file *, unsigned int, 118219820Sjeff unsigned long); 119219820Sjeff long (*compat_ioctl)(struct file *, unsigned int, unsigned long); 120219820Sjeff int (*flush)(struct file *, fl_owner_t id); 121219820Sjeff int (*fsync)(struct file *, struct dentry *, int datasync); 122219820Sjeff int (*aio_fsync)(struct kiocb *, int datasync); 123219820Sjeff int (*lock)(struct file *, int, struct file_lock *); 124219820Sjeff ssize_t (*sendpage)(struct file *, struct page *, int, size_t, 125219820Sjeff loff_t *, int); 126219820Sjeff unsigned long (*get_unmapped_area)(struct file *, unsigned long, 127219820Sjeff unsigned long, unsigned long, unsigned long); 128219820Sjeff int (*check_flags)(int); 129219820Sjeff int (*flock)(struct file *, int, struct file_lock *); 130219820Sjeff ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, 131219820Sjeff loff_t *, size_t, unsigned int); 132219820Sjeff ssize_t (*splice_read)(struct file *, loff_t *, 133219820Sjeff struct pipe_inode_info *, size_t, unsigned int); 134219820Sjeff int (*setlease)(struct file *, long, struct file_lock **); 135219820Sjeff#endif 136219820Sjeff}; 137219820Sjeff#define fops_get(fops) (fops) 138219820Sjeff 139219820Sjeff#define FMODE_READ FREAD 140219820Sjeff#define FMODE_WRITE FWRITE 141219820Sjeff#define FMODE_EXEC FEXEC 142219820Sjeff 143219820Sjeffstatic inline int 144219820Sjeffregister_chrdev_region(dev_t dev, unsigned range, const char *name) 145219820Sjeff{ 146219820Sjeff 147219820Sjeff return 0; 148219820Sjeff} 149219820Sjeff 150219820Sjeffstatic inline void 151219820Sjeffunregister_chrdev_region(dev_t dev, unsigned range) 152219820Sjeff{ 153219820Sjeff 154219820Sjeff return; 155219820Sjeff} 156219820Sjeff 157219820Sjeffstatic inline dev_t 158219820Sjeffiminor(struct inode *inode) 159219820Sjeff{ 160219820Sjeff 161219820Sjeff return dev2unit(inode->v_rdev); 162219820Sjeff} 163219820Sjeff 164219820Sjeffstatic inline struct inode * 165219820Sjeffigrab(struct inode *inode) 166219820Sjeff{ 167219820Sjeff int error; 168219820Sjeff 169219820Sjeff error = vget(inode, 0, curthread); 170219820Sjeff if (error) 171219820Sjeff return (NULL); 172219820Sjeff 173219820Sjeff return (inode); 174219820Sjeff} 175219820Sjeff 176219820Sjeffstatic inline void 177219820Sjeffiput(struct inode *inode) 178219820Sjeff{ 179219820Sjeff 180219820Sjeff vrele(inode); 181219820Sjeff} 182219820Sjeff 183219820Sjeff#endif /* _LINUX_FS_H_ */ 184