fs.h revision 311803
160107Sobrien/*- 232822Syokota * Copyright (c) 2010 Isilon Systems, Inc. 332822Syokota * Copyright (c) 2010 iX Systems, Inc. 432822Syokota * Copyright (c) 2010 Panasas, Inc. 532822Syokota * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 632822Syokota * All rights reserved. 732822Syokota * 832822Syokota * Redistribution and use in source and binary forms, with or without 932822Syokota * modification, are permitted provided that the following conditions 1032822Syokota * are met: 1137204Ssteve * 1. Redistributions of source code must retain the above copyright 1243334Syokota * notice unmodified, this list of conditions, and the following 1343334Syokota * disclaimer. 1443334Syokota * 2. Redistributions in binary form must reproduce the above copyright 1543334Syokota * notice, this list of conditions and the following disclaimer in the 1643334Syokota * documentation and/or other materials provided with the distribution. 1743334Syokota * 1843334Syokota * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1943334Syokota * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2032822Syokota * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2132822Syokota * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2232822Syokota * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2332822Syokota * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2432822Syokota * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2532822Syokota * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2632822Syokota * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2743334Syokota * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2832822Syokota * 2932822Syokota * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/fs.h 311803 2017-01-09 17:25:23Z hselasky $ 3032822Syokota */ 3132822Syokota#ifndef _LINUX_FS_H_ 3237204Ssteve#define _LINUX_FS_H_ 3337204Ssteve 3432822Syokota#include <sys/cdefs.h> 3532822Syokota#include <sys/param.h> 3632822Syokota#include <sys/systm.h> 3732822Syokota#include <sys/conf.h> 3832822Syokota#include <sys/vnode.h> 3932822Syokota#include <sys/file.h> 4032822Syokota#include <sys/filedesc.h> 4132822Syokota#include <linux/types.h> 4232822Syokota#include <linux/wait.h> 4332822Syokota#include <linux/semaphore.h> 4432822Syokota 4543334Syokotastruct module; 4643334Syokotastruct kiocb; 4732822Syokotastruct iovec; 4832822Syokotastruct dentry; 4937204Sstevestruct page; 5043334Syokotastruct file_lock; 5132822Syokotastruct pipe_inode_info; 5232822Syokotastruct vm_area_struct; 5332822Syokotastruct poll_table_struct; 5432822Syokotastruct files_struct; 5532822Syokota 5632822Syokota#define inode vnode 5732822Syokota#define i_cdev v_rdev 5832822Syokota 5938140Syokota#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) 6032822Syokota#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH) 6143334Syokota 6232822Syokota 6332822Syokotatypedef struct files_struct *fl_owner_t; 6432822Syokota 6532822Syokotastruct dentry { 6632822Syokota struct inode *d_inode; 6732822Syokota}; 6832822Syokota 6932822Syokotastruct file_operations; 7032822Syokota 7132822Syokotastruct linux_file { 7232822Syokota struct file *_file; 7332822Syokota const struct file_operations *f_op; 7432822Syokota void *private_data; 7543334Syokota int f_flags; 7643334Syokota int f_mode; /* Just starting mode. */ 7732822Syokota struct dentry *f_dentry; 7832822Syokota struct dentry f_dentry_store; 7932822Syokota struct selinfo f_selinfo; 8043334Syokota struct sigio *f_sigio; 8132822Syokota struct vnode *f_vnode; 8232822Syokota}; 8343334Syokota 8432822Syokota#define file linux_file 8532822Syokota#define fasync_struct sigio * 8632822Syokota 8732822Syokota#define fasync_helper(fd, filp, on, queue) \ 8832822Syokota({ \ 8943334Syokota if ((on)) \ 9043334Syokota *(queue) = &(filp)->f_sigio; \ 9132822Syokota else \ 9243334Syokota *(queue) = NULL; \ 9332822Syokota 0; \ 9432822Syokota}) 9532822Syokota 9632822Syokota#define kill_fasync(queue, sig, pollstat) \ 9732822Syokotado { \ 9843334Syokota if (*(queue) != NULL) \ 9932822Syokota pgsigio(*(queue), (sig), 0); \ 10032822Syokota} while (0) 10132822Syokota 10232822Syokotatypedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 10332822Syokota 10432822Syokotastruct file_operations { 10532822Syokota struct module *owner; 10632822Syokota ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); 10732822Syokota ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); 10832822Syokota unsigned int (*poll) (struct file *, struct poll_table_struct *); 10943334Syokota long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long); 11043334Syokota int (*mmap)(struct file *, struct vm_area_struct *); 11143334Syokota int (*open)(struct inode *, struct file *); 11243334Syokota int (*release)(struct inode *, struct file *); 11343334Syokota int (*fasync)(int, struct file *, int); 11443334Syokota 11532822Syokota/* Although not supported in FreeBSD, to align with Linux code 11632822Syokota * we are adding llseek() only when it is mapped to no_llseek which returns 11732822Syokota * an illegal seek error 11832822Syokota */ 11932822Syokota loff_t (*llseek)(struct file *, loff_t, int); 12032822Syokota#if 0 12132822Syokota /* We do not support these methods. Don't permit them to compile. */ 12232822Syokota loff_t (*llseek)(struct file *, loff_t, int); 12332822Syokota ssize_t (*aio_read)(struct kiocb *, const struct iovec *, 12432822Syokota unsigned long, loff_t); 12532822Syokota ssize_t (*aio_write)(struct kiocb *, const struct iovec *, 12632822Syokota unsigned long, loff_t); 12732822Syokota int (*readdir)(struct file *, void *, filldir_t); 12832822Syokota int (*ioctl)(struct inode *, struct file *, unsigned int, 12932822Syokota unsigned long); 13032822Syokota long (*compat_ioctl)(struct file *, unsigned int, unsigned long); 13132822Syokota int (*flush)(struct file *, fl_owner_t id); 13232822Syokota int (*fsync)(struct file *, struct dentry *, int datasync); 13332822Syokota int (*aio_fsync)(struct kiocb *, int datasync); 13432822Syokota int (*lock)(struct file *, int, struct file_lock *); 13532822Syokota ssize_t (*sendpage)(struct file *, struct page *, int, size_t, 13632822Syokota loff_t *, int); 13732822Syokota unsigned long (*get_unmapped_area)(struct file *, unsigned long, 13832822Syokota unsigned long, unsigned long, unsigned long); 13932822Syokota int (*check_flags)(int); 140 int (*flock)(struct file *, int, struct file_lock *); 141 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, 142 loff_t *, size_t, unsigned int); 143 ssize_t (*splice_read)(struct file *, loff_t *, 144 struct pipe_inode_info *, size_t, unsigned int); 145 int (*setlease)(struct file *, long, struct file_lock **); 146#endif 147}; 148#define fops_get(fops) (fops) 149 150#define FMODE_READ FREAD 151#define FMODE_WRITE FWRITE 152#define FMODE_EXEC FEXEC 153 154int __register_chrdev(unsigned int major, unsigned int baseminor, 155 unsigned int count, const char *name, 156 const struct file_operations *fops); 157int __register_chrdev_p(unsigned int major, unsigned int baseminor, 158 unsigned int count, const char *name, 159 const struct file_operations *fops, uid_t uid, 160 gid_t gid, int mode); 161void __unregister_chrdev(unsigned int major, unsigned int baseminor, 162 unsigned int count, const char *name); 163 164static inline void 165unregister_chrdev(unsigned int major, const char *name) 166{ 167 168 __unregister_chrdev(major, 0, 256, name); 169} 170 171static inline int 172register_chrdev(unsigned int major, const char *name, 173 const struct file_operations *fops) 174{ 175 176 return (__register_chrdev(major, 0, 256, name, fops)); 177} 178 179static inline int 180register_chrdev_p(unsigned int major, const char *name, 181 const struct file_operations *fops, uid_t uid, gid_t gid, int mode) 182{ 183 184 return (__register_chrdev_p(major, 0, 256, name, fops, uid, gid, mode)); 185} 186 187static inline int 188register_chrdev_region(dev_t dev, unsigned range, const char *name) 189{ 190 191 return 0; 192} 193 194static inline void 195unregister_chrdev_region(dev_t dev, unsigned range) 196{ 197 198 return; 199} 200 201static inline int 202alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, 203 const char *name) 204{ 205 206 return 0; 207} 208 209/* No current support for seek op in FreeBSD */ 210static inline int 211nonseekable_open(struct inode *inode, struct file *filp) 212{ 213 return 0; 214} 215 216static inline dev_t 217iminor(struct inode *inode) 218{ 219 220 return (minor(dev2unit(inode->v_rdev))); 221} 222 223static inline struct inode * 224igrab(struct inode *inode) 225{ 226 int error; 227 228 error = vget(inode, 0, curthread); 229 if (error) 230 return (NULL); 231 232 return (inode); 233} 234 235static inline void 236iput(struct inode *inode) 237{ 238 239 vrele(inode); 240} 241 242static inline loff_t 243no_llseek(struct file *file, loff_t offset, int whence) 244{ 245 return -ESPIPE; 246} 247 248#endif /* _LINUX_FS_H_ */ 249