1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/*-
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _LINUX_FS_H_
#define _LINUX_FS_H_
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <linux/types.h>
#include <linux/wait.h>
#include <linux/semaphore.h>
struct module;
struct kiocb;
struct iovec;
struct dentry;
struct page;
struct file_lock;
struct pipe_inode_info;
struct vm_area_struct;
struct poll_table_struct;
struct files_struct;
#define inode vnode
#define i_cdev v_rdev
#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
#define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
typedef struct files_struct *fl_owner_t;
struct dentry {
struct inode *d_inode;
};
struct file_operations;
struct linux_file {
struct file *_file;
const struct file_operations *f_op;
void *private_data;
int f_flags;
int f_mode; /* Just starting mode. */
struct dentry *f_dentry;
struct dentry f_dentry_store;
struct selinfo f_selinfo;
struct sigio *f_sigio;
struct vnode *f_vnode;
};
#define file linux_file
#define fasync_struct sigio *
#define fasync_helper(fd, filp, on, queue) \
({ \
if ((on)) \
*(queue) = &(filp)->f_sigio; \
else \
*(queue) = NULL; \
0; \
})
#define kill_fasync(queue, sig, pollstat) \
do { \
if (*(queue) != NULL) \
pgsigio(*(queue), (sig), 0); \
} while (0)
typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
struct file_operations {
struct module *owner;
ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
unsigned int (*poll) (struct file *, struct poll_table_struct *);
long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long);
int (*mmap)(struct file *, struct vm_area_struct *);
int (*open)(struct inode *, struct file *);
int (*release)(struct inode *, struct file *);
int (*fasync)(int, struct file *, int);
/* Although not supported in FreeBSD, to align with Linux code
* we are adding llseek() only when it is mapped to no_llseek which returns
* an illegal seek error
*/
loff_t (*llseek)(struct file *, loff_t, int);
#if 0
/* We do not support these methods. Don't permit them to compile. */
loff_t (*llseek)(struct file *, loff_t, int);
ssize_t (*aio_read)(struct kiocb *, const struct iovec *,
unsigned long, loff_t);
ssize_t (*aio_write)(struct kiocb *, const struct iovec *,
unsigned long, loff_t);
int (*readdir)(struct file *, void *, filldir_t);
int (*ioctl)(struct inode *, struct file *, unsigned int,
unsigned long);
long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
int (*flush)(struct file *, fl_owner_t id);
int (*fsync)(struct file *, struct dentry *, int datasync);
int (*aio_fsync)(struct kiocb *, int datasync);
int (*lock)(struct file *, int, struct file_lock *);
ssize_t (*sendpage)(struct file *, struct page *, int, size_t,
loff_t *, int);
unsigned long (*get_unmapped_area)(struct file *, unsigned long,
unsigned long, unsigned long, unsigned long);
int (*check_flags)(int);
int (*flock)(struct file *, int, struct file_lock *);
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
loff_t *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *,
struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long, struct file_lock **);
#endif
};
#define fops_get(fops) (fops)
#define FMODE_READ FREAD
#define FMODE_WRITE FWRITE
#define FMODE_EXEC FEXEC
int __register_chrdev(unsigned int major, unsigned int baseminor,
unsigned int count, const char *name,
const struct file_operations *fops);
int __register_chrdev_p(unsigned int major, unsigned int baseminor,
unsigned int count, const char *name,
const struct file_operations *fops, uid_t uid,
gid_t gid, int mode);
void __unregister_chrdev(unsigned int major, unsigned int baseminor,
unsigned int count, const char *name);
static inline void
unregister_chrdev(unsigned int major, const char *name)
{
__unregister_chrdev(major, 0, 256, name);
}
static inline int
register_chrdev(unsigned int major, const char *name,
const struct file_operations *fops)
{
return (__register_chrdev(major, 0, 256, name, fops));
}
static inline int
register_chrdev_p(unsigned int major, const char *name,
const struct file_operations *fops, uid_t uid, gid_t gid, int mode)
{
return (__register_chrdev_p(major, 0, 256, name, fops, uid, gid, mode));
}
static inline int
register_chrdev_region(dev_t dev, unsigned range, const char *name)
{
return 0;
}
static inline void
unregister_chrdev_region(dev_t dev, unsigned range)
{
return;
}
static inline int
alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
const char *name)
{
return 0;
}
/* No current support for seek op in FreeBSD */
static inline int
nonseekable_open(struct inode *inode, struct file *filp)
{
return 0;
}
static inline dev_t
iminor(struct inode *inode)
{
return (minor(dev2unit(inode->v_rdev)));
}
static inline struct inode *
igrab(struct inode *inode)
{
int error;
error = vget(inode, 0, curthread);
if (error)
return (NULL);
return (inode);
}
static inline void
iput(struct inode *inode)
{
vrele(inode);
}
static inline loff_t
no_llseek(struct file *file, loff_t offset, int whence)
{
return -ESPIPE;
}
#endif /* _LINUX_FS_H_ */
|