fs.h revision 280764
1219820Sjeff/*-
2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc.
3219820Sjeff * Copyright (c) 2010 iX Systems, Inc.
4219820Sjeff * Copyright (c) 2010 Panasas, Inc.
5270710Shselasky * 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
32280764Shselasky#include <sys/cdefs.h>
33280764Shselasky#include <sys/param.h>
34219820Sjeff#include <sys/systm.h>
35219820Sjeff#include <sys/conf.h>
36219820Sjeff#include <sys/vnode.h>
37219820Sjeff#include <sys/file.h>
38219820Sjeff#include <sys/filedesc.h>
39219820Sjeff#include <linux/types.h>
40219820Sjeff#include <linux/wait.h>
41219820Sjeff#include <linux/semaphore.h>
42219820Sjeff
43219820Sjeffstruct module;
44219820Sjeffstruct kiocb;
45219820Sjeffstruct iovec;
46219820Sjeffstruct dentry;
47219820Sjeffstruct page;
48219820Sjeffstruct file_lock;
49219820Sjeffstruct pipe_inode_info;
50219820Sjeffstruct vm_area_struct;
51219820Sjeffstruct poll_table_struct;
52219820Sjeffstruct files_struct;
53219820Sjeff
54219820Sjeff#define	inode	vnode
55219820Sjeff#define	i_cdev	v_rdev
56219820Sjeff
57219820Sjeff#define	S_IRUGO	(S_IRUSR | S_IRGRP | S_IROTH)
58219820Sjeff#define	S_IWUGO	(S_IWUSR | S_IWGRP | S_IWOTH)
59219820Sjeff
60219820Sjeff
61219820Sjefftypedef struct files_struct *fl_owner_t;
62219820Sjeff
63219820Sjeffstruct dentry {
64219820Sjeff	struct inode	*d_inode;
65219820Sjeff};
66219820Sjeff
67219820Sjeffstruct file_operations;
68219820Sjeff
69219820Sjeffstruct linux_file {
70219820Sjeff	struct file	*_file;
71219820Sjeff	const struct file_operations	*f_op;
72219820Sjeff	void 		*private_data;
73219820Sjeff	int		f_flags;
74219820Sjeff	int		f_mode;	/* Just starting mode. */
75219820Sjeff	struct dentry	*f_dentry;
76219820Sjeff	struct dentry	f_dentry_store;
77219820Sjeff	struct selinfo	f_selinfo;
78219820Sjeff	struct sigio	*f_sigio;
79251617Sjhb	struct vnode	*f_vnode;
80219820Sjeff};
81219820Sjeff
82219820Sjeff#define	file		linux_file
83219820Sjeff#define	fasync_struct	sigio *
84219820Sjeff
85219820Sjeff#define	fasync_helper(fd, filp, on, queue)				\
86219820Sjeff({									\
87219820Sjeff	if ((on))							\
88219820Sjeff		*(queue) = &(filp)->f_sigio;				\
89219820Sjeff	else								\
90219820Sjeff		*(queue) = NULL;					\
91219820Sjeff	0;								\
92219820Sjeff})
93219820Sjeff
94219820Sjeff#define	kill_fasync(queue, sig, pollstat)				\
95219820Sjeffdo {									\
96219820Sjeff	if (*(queue) != NULL)						\
97219820Sjeff		pgsigio(*(queue), (sig), 0);				\
98219820Sjeff} while (0)
99219820Sjeff
100219820Sjefftypedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
101219820Sjeff
102219820Sjeffstruct file_operations {
103219820Sjeff	struct module *owner;
104219820Sjeff	ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
105219820Sjeff	ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
106219820Sjeff	unsigned int (*poll) (struct file *, struct poll_table_struct *);
107219820Sjeff	long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long);
108219820Sjeff	int (*mmap)(struct file *, struct vm_area_struct *);
109219820Sjeff	int (*open)(struct inode *, struct file *);
110219820Sjeff	int (*release)(struct inode *, struct file *);
111219820Sjeff	int (*fasync)(int, struct file *, int);
112270710Shselasky
113270710Shselasky/* Although not supported in FreeBSD, to align with Linux code
114270710Shselasky * we are adding llseek() only when it is mapped to no_llseek which returns
115270710Shselasky * an illegal seek error
116270710Shselasky */
117270710Shselasky	loff_t (*llseek)(struct file *, loff_t, int);
118219820Sjeff#if 0
119219820Sjeff	/* We do not support these methods.  Don't permit them to compile. */
120219820Sjeff	loff_t (*llseek)(struct file *, loff_t, int);
121219820Sjeff	ssize_t (*aio_read)(struct kiocb *, const struct iovec *,
122219820Sjeff	    unsigned long, loff_t);
123219820Sjeff	ssize_t (*aio_write)(struct kiocb *, const struct iovec *,
124219820Sjeff	    unsigned long, loff_t);
125219820Sjeff	int (*readdir)(struct file *, void *, filldir_t);
126219820Sjeff	int (*ioctl)(struct inode *, struct file *, unsigned int,
127219820Sjeff	    unsigned long);
128219820Sjeff	long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
129219820Sjeff	int (*flush)(struct file *, fl_owner_t id);
130219820Sjeff	int (*fsync)(struct file *, struct dentry *, int datasync);
131219820Sjeff	int (*aio_fsync)(struct kiocb *, int datasync);
132219820Sjeff	int (*lock)(struct file *, int, struct file_lock *);
133219820Sjeff	ssize_t (*sendpage)(struct file *, struct page *, int, size_t,
134219820Sjeff	    loff_t *, int);
135219820Sjeff	unsigned long (*get_unmapped_area)(struct file *, unsigned long,
136219820Sjeff	    unsigned long, unsigned long, unsigned long);
137219820Sjeff	int (*check_flags)(int);
138219820Sjeff	int (*flock)(struct file *, int, struct file_lock *);
139219820Sjeff	ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
140219820Sjeff	    loff_t *, size_t, unsigned int);
141219820Sjeff	ssize_t (*splice_read)(struct file *, loff_t *,
142219820Sjeff	    struct pipe_inode_info *, size_t, unsigned int);
143219820Sjeff	int (*setlease)(struct file *, long, struct file_lock **);
144219820Sjeff#endif
145219820Sjeff};
146219820Sjeff#define	fops_get(fops)	(fops)
147219820Sjeff
148219820Sjeff#define	FMODE_READ	FREAD
149219820Sjeff#define	FMODE_WRITE	FWRITE
150219820Sjeff#define	FMODE_EXEC	FEXEC
151219820Sjeff
152219820Sjeffstatic inline int
153219820Sjeffregister_chrdev_region(dev_t dev, unsigned range, const char *name)
154219820Sjeff{
155219820Sjeff
156219820Sjeff	return 0;
157219820Sjeff}
158219820Sjeff
159219820Sjeffstatic inline void
160219820Sjeffunregister_chrdev_region(dev_t dev, unsigned range)
161219820Sjeff{
162219820Sjeff
163219820Sjeff	return;
164219820Sjeff}
165219820Sjeff
166270710Shselaskystatic inline int
167270710Shselaskyalloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
168270710Shselasky			const char *name)
169270710Shselasky{
170270710Shselasky
171270710Shselasky	return 0;
172270710Shselasky}
173270710Shselasky
174270710Shselasky/* No current support for seek op in FreeBSD */
175270710Shselaskystatic inline int
176270710Shselaskynonseekable_open(struct inode *inode, struct file *filp)
177270710Shselasky{
178270710Shselasky	return 0;
179270710Shselasky}
180270710Shselasky
181219820Sjeffstatic inline dev_t
182219820Sjeffiminor(struct inode *inode)
183219820Sjeff{
184219820Sjeff
185219820Sjeff	return dev2unit(inode->v_rdev);
186219820Sjeff}
187219820Sjeff
188219820Sjeffstatic inline struct inode *
189219820Sjeffigrab(struct inode *inode)
190219820Sjeff{
191219820Sjeff	int error;
192219820Sjeff
193219820Sjeff	error = vget(inode, 0, curthread);
194219820Sjeff	if (error)
195219820Sjeff		return (NULL);
196219820Sjeff
197219820Sjeff	return (inode);
198219820Sjeff}
199219820Sjeff
200219820Sjeffstatic inline void
201219820Sjeffiput(struct inode *inode)
202219820Sjeff{
203219820Sjeff
204219820Sjeff	vrele(inode);
205219820Sjeff}
206219820Sjeff
207270710Shselaskystatic inline loff_t
208270710Shselaskyno_llseek(struct file *file, loff_t offset, int whence)
209270710Shselasky{
210270710Shselasky        return -ESPIPE;
211270710Shselasky}
212270710Shselasky
213270710Shselasky#endif /* _LINUX_FS_H_ */
214