fs.h revision 219820
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;
76219820Sjeff};
77219820Sjeff
78219820Sjeff#define	file		linux_file
79219820Sjeff#define	fasync_struct	sigio *
80219820Sjeff
81219820Sjeff#define	fasync_helper(fd, filp, on, queue)				\
82219820Sjeff({									\
83219820Sjeff	if ((on))							\
84219820Sjeff		*(queue) = &(filp)->f_sigio;				\
85219820Sjeff	else								\
86219820Sjeff		*(queue) = NULL;					\
87219820Sjeff	0;								\
88219820Sjeff})
89219820Sjeff
90219820Sjeff#define	kill_fasync(queue, sig, pollstat)				\
91219820Sjeffdo {									\
92219820Sjeff	if (*(queue) != NULL)						\
93219820Sjeff		pgsigio(*(queue), (sig), 0);				\
94219820Sjeff} while (0)
95219820Sjeff
96219820Sjefftypedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
97219820Sjeff
98219820Sjeffstruct file_operations {
99219820Sjeff	struct module *owner;
100219820Sjeff	ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
101219820Sjeff	ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
102219820Sjeff	unsigned int (*poll) (struct file *, struct poll_table_struct *);
103219820Sjeff	long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long);
104219820Sjeff	int (*mmap)(struct file *, struct vm_area_struct *);
105219820Sjeff	int (*open)(struct inode *, struct file *);
106219820Sjeff	int (*release)(struct inode *, struct file *);
107219820Sjeff	int (*fasync)(int, struct file *, int);
108219820Sjeff#if 0
109219820Sjeff	/* We do not support these methods.  Don't permit them to compile. */
110219820Sjeff	loff_t (*llseek)(struct file *, loff_t, int);
111219820Sjeff	ssize_t (*aio_read)(struct kiocb *, const struct iovec *,
112219820Sjeff	    unsigned long, loff_t);
113219820Sjeff	ssize_t (*aio_write)(struct kiocb *, const struct iovec *,
114219820Sjeff	    unsigned long, loff_t);
115219820Sjeff	int (*readdir)(struct file *, void *, filldir_t);
116219820Sjeff	int (*ioctl)(struct inode *, struct file *, unsigned int,
117219820Sjeff	    unsigned long);
118219820Sjeff	long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
119219820Sjeff	int (*flush)(struct file *, fl_owner_t id);
120219820Sjeff	int (*fsync)(struct file *, struct dentry *, int datasync);
121219820Sjeff	int (*aio_fsync)(struct kiocb *, int datasync);
122219820Sjeff	int (*lock)(struct file *, int, struct file_lock *);
123219820Sjeff	ssize_t (*sendpage)(struct file *, struct page *, int, size_t,
124219820Sjeff	    loff_t *, int);
125219820Sjeff	unsigned long (*get_unmapped_area)(struct file *, unsigned long,
126219820Sjeff	    unsigned long, unsigned long, unsigned long);
127219820Sjeff	int (*check_flags)(int);
128219820Sjeff	int (*flock)(struct file *, int, struct file_lock *);
129219820Sjeff	ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
130219820Sjeff	    loff_t *, size_t, unsigned int);
131219820Sjeff	ssize_t (*splice_read)(struct file *, loff_t *,
132219820Sjeff	    struct pipe_inode_info *, size_t, unsigned int);
133219820Sjeff	int (*setlease)(struct file *, long, struct file_lock **);
134219820Sjeff#endif
135219820Sjeff};
136219820Sjeff#define	fops_get(fops)	(fops)
137219820Sjeff
138219820Sjeff#define	FMODE_READ	FREAD
139219820Sjeff#define	FMODE_WRITE	FWRITE
140219820Sjeff#define	FMODE_EXEC	FEXEC
141219820Sjeff
142219820Sjeffstatic inline int
143219820Sjeffregister_chrdev_region(dev_t dev, unsigned range, const char *name)
144219820Sjeff{
145219820Sjeff
146219820Sjeff	return 0;
147219820Sjeff}
148219820Sjeff
149219820Sjeffstatic inline void
150219820Sjeffunregister_chrdev_region(dev_t dev, unsigned range)
151219820Sjeff{
152219820Sjeff
153219820Sjeff	return;
154219820Sjeff}
155219820Sjeff
156219820Sjeffstatic inline dev_t
157219820Sjeffiminor(struct inode *inode)
158219820Sjeff{
159219820Sjeff
160219820Sjeff	return dev2unit(inode->v_rdev);
161219820Sjeff}
162219820Sjeff
163219820Sjeffstatic inline struct inode *
164219820Sjeffigrab(struct inode *inode)
165219820Sjeff{
166219820Sjeff	int error;
167219820Sjeff
168219820Sjeff	error = vget(inode, 0, curthread);
169219820Sjeff	if (error)
170219820Sjeff		return (NULL);
171219820Sjeff
172219820Sjeff	return (inode);
173219820Sjeff}
174219820Sjeff
175219820Sjeffstatic inline void
176219820Sjeffiput(struct inode *inode)
177219820Sjeff{
178219820Sjeff
179219820Sjeff	vrele(inode);
180219820Sjeff}
181219820Sjeff
182219820Sjeff#endif	/* _LINUX_FS_H_ */
183