fs.h revision 219820
1/*- 2 * Copyright (c) 2010 Isilon Systems, Inc. 3 * Copyright (c) 2010 iX Systems, Inc. 4 * Copyright (c) 2010 Panasas, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice unmodified, this list of conditions, and the following 12 * disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28#ifndef _LINUX_FS_H_ 29#define _LINUX_FS_H_ 30 31#include <sys/systm.h> 32#include <sys/conf.h> 33#include <sys/vnode.h> 34#include <sys/file.h> 35#include <sys/filedesc.h> 36#include <linux/types.h> 37#include <linux/wait.h> 38#include <linux/semaphore.h> 39 40struct module; 41struct kiocb; 42struct iovec; 43struct dentry; 44struct page; 45struct file_lock; 46struct pipe_inode_info; 47struct vm_area_struct; 48struct poll_table_struct; 49struct files_struct; 50 51#define inode vnode 52#define i_cdev v_rdev 53 54#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 55#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 56 57 58typedef struct files_struct *fl_owner_t; 59 60struct dentry { 61 struct inode *d_inode; 62}; 63 64struct file_operations; 65 66struct linux_file { 67 struct file *_file; 68 const struct file_operations *f_op; 69 void *private_data; 70 int f_flags; 71 int f_mode; /* Just starting mode. */ 72 struct dentry *f_dentry; 73 struct dentry f_dentry_store; 74 struct selinfo f_selinfo; 75 struct sigio *f_sigio; 76}; 77 78#define file linux_file 79#define fasync_struct sigio * 80 81#define fasync_helper(fd, filp, on, queue) \ 82({ \ 83 if ((on)) \ 84 *(queue) = &(filp)->f_sigio; \ 85 else \ 86 *(queue) = NULL; \ 87 0; \ 88}) 89 90#define kill_fasync(queue, sig, pollstat) \ 91do { \ 92 if (*(queue) != NULL) \ 93 pgsigio(*(queue), (sig), 0); \ 94} while (0) 95 96typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 97 98struct file_operations { 99 struct module *owner; 100 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); 101 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); 102 unsigned int (*poll) (struct file *, struct poll_table_struct *); 103 long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long); 104 int (*mmap)(struct file *, struct vm_area_struct *); 105 int (*open)(struct inode *, struct file *); 106 int (*release)(struct inode *, struct file *); 107 int (*fasync)(int, struct file *, int); 108#if 0 109 /* We do not support these methods. Don't permit them to compile. */ 110 loff_t (*llseek)(struct file *, loff_t, int); 111 ssize_t (*aio_read)(struct kiocb *, const struct iovec *, 112 unsigned long, loff_t); 113 ssize_t (*aio_write)(struct kiocb *, const struct iovec *, 114 unsigned long, loff_t); 115 int (*readdir)(struct file *, void *, filldir_t); 116 int (*ioctl)(struct inode *, struct file *, unsigned int, 117 unsigned long); 118 long (*compat_ioctl)(struct file *, unsigned int, unsigned long); 119 int (*flush)(struct file *, fl_owner_t id); 120 int (*fsync)(struct file *, struct dentry *, int datasync); 121 int (*aio_fsync)(struct kiocb *, int datasync); 122 int (*lock)(struct file *, int, struct file_lock *); 123 ssize_t (*sendpage)(struct file *, struct page *, int, size_t, 124 loff_t *, int); 125 unsigned long (*get_unmapped_area)(struct file *, unsigned long, 126 unsigned long, unsigned long, unsigned long); 127 int (*check_flags)(int); 128 int (*flock)(struct file *, int, struct file_lock *); 129 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, 130 loff_t *, size_t, unsigned int); 131 ssize_t (*splice_read)(struct file *, loff_t *, 132 struct pipe_inode_info *, size_t, unsigned int); 133 int (*setlease)(struct file *, long, struct file_lock **); 134#endif 135}; 136#define fops_get(fops) (fops) 137 138#define FMODE_READ FREAD 139#define FMODE_WRITE FWRITE 140#define FMODE_EXEC FEXEC 141 142static inline int 143register_chrdev_region(dev_t dev, unsigned range, const char *name) 144{ 145 146 return 0; 147} 148 149static inline void 150unregister_chrdev_region(dev_t dev, unsigned range) 151{ 152 153 return; 154} 155 156static inline dev_t 157iminor(struct inode *inode) 158{ 159 160 return dev2unit(inode->v_rdev); 161} 162 163static inline struct inode * 164igrab(struct inode *inode) 165{ 166 int error; 167 168 error = vget(inode, 0, curthread); 169 if (error) 170 return (NULL); 171 172 return (inode); 173} 174 175static inline void 176iput(struct inode *inode) 177{ 178 179 vrele(inode); 180} 181 182#endif /* _LINUX_FS_H_ */ 183