47
47
#include <sys/stat.h>
48
48
49
49
int
50
- zfs_file_open (const char * path , int flags , int mode , zfs_file_t * * fpp )
50
+ zfs_file_open (const char * path , int flags , int mode , zfs_file_t * * zfpp )
51
51
{
52
52
struct thread * td ;
53
+ struct file * fp ;
54
+ zfs_file_t * zfp ;
53
55
int rc , fd ;
54
56
55
57
td = curthread ;
@@ -61,20 +63,31 @@ zfs_file_open(const char *path, int flags, int mode, zfs_file_t **fpp)
61
63
return (SET_ERROR (rc ));
62
64
fd = td -> td_retval [0 ];
63
65
td -> td_retval [0 ] = 0 ;
64
- if (fget (curthread , fd , & cap_no_rights , fpp ))
66
+ rc = fget (curthread , fd , & cap_no_rights , & fp );
67
+ if (rc ) {
65
68
kern_close (td , fd );
69
+ return (SET_ERROR (rc ));
70
+ }
71
+ zfp = kmem_alloc (sizeof (* zfp ), KM_SLEEP );
72
+ zfp -> zf_fd = fd ;
73
+ zfp -> zf_fp = fp ;
74
+ * zfpp = zfp ;
66
75
return (0 );
67
76
}
68
77
69
78
void
70
- zfs_file_close (zfs_file_t * fp )
79
+ zfs_file_close (zfs_file_t * zfp )
71
80
{
72
- fo_close (fp , curthread );
81
+ struct thread * td = curthread ;
82
+
83
+ fdrop (zfp -> zf_fp , td );
84
+ kern_close (td , zfp -> zf_fd );
85
+ kmem_free (zfp , sizeof (* zfp ));
73
86
}
74
87
75
88
static int
76
- zfs_file_write_impl (zfs_file_t * fp , const void * buf , size_t count , loff_t * offp ,
77
- ssize_t * resid )
89
+ zfs_file_write_impl (struct file * fp , const void * buf , size_t count ,
90
+ loff_t * offp , ssize_t * resid )
78
91
{
79
92
ssize_t rc ;
80
93
struct uio auio ;
@@ -110,8 +123,9 @@ zfs_file_write_impl(zfs_file_t *fp, const void *buf, size_t count, loff_t *offp,
110
123
}
111
124
112
125
int
113
- zfs_file_write (zfs_file_t * fp , const void * buf , size_t count , ssize_t * resid )
126
+ zfs_file_write (zfs_file_t * zfp , const void * buf , size_t count , ssize_t * resid )
114
127
{
128
+ struct file * fp = zfp -> zf_fp ;
115
129
loff_t off = fp -> f_offset ;
116
130
ssize_t rc ;
117
131
@@ -123,14 +137,14 @@ zfs_file_write(zfs_file_t *fp, const void *buf, size_t count, ssize_t *resid)
123
137
}
124
138
125
139
int
126
- zfs_file_pwrite (zfs_file_t * fp , const void * buf , size_t count , loff_t off ,
140
+ zfs_file_pwrite (zfs_file_t * zfp , const void * buf , size_t count , loff_t off ,
127
141
ssize_t * resid )
128
142
{
129
- return (zfs_file_write_impl (fp , buf , count , & off , resid ));
143
+ return (zfs_file_write_impl (zfp -> zf_fp , buf , count , & off , resid ));
130
144
}
131
145
132
146
static int
133
- zfs_file_read_impl (zfs_file_t * fp , void * buf , size_t count , loff_t * offp ,
147
+ zfs_file_read_impl (struct file * fp , void * buf , size_t count , loff_t * offp ,
134
148
ssize_t * resid )
135
149
{
136
150
ssize_t rc ;
@@ -162,8 +176,9 @@ zfs_file_read_impl(zfs_file_t *fp, void *buf, size_t count, loff_t *offp,
162
176
}
163
177
164
178
int
165
- zfs_file_read (zfs_file_t * fp , void * buf , size_t count , ssize_t * resid )
179
+ zfs_file_read (zfs_file_t * zfp , void * buf , size_t count , ssize_t * resid )
166
180
{
181
+ struct file * fp = zfp -> zf_fp ;
167
182
loff_t off = fp -> f_offset ;
168
183
ssize_t rc ;
169
184
@@ -174,17 +189,18 @@ zfs_file_read(zfs_file_t *fp, void *buf, size_t count, ssize_t *resid)
174
189
}
175
190
176
191
int
177
- zfs_file_pread (zfs_file_t * fp , void * buf , size_t count , loff_t off ,
192
+ zfs_file_pread (zfs_file_t * zfp , void * buf , size_t count , loff_t off ,
178
193
ssize_t * resid )
179
194
{
180
- return (zfs_file_read_impl (fp , buf , count , & off , resid ));
195
+ return (zfs_file_read_impl (zfp -> zf_fp , buf , count , & off , resid ));
181
196
}
182
197
183
198
int
184
- zfs_file_seek (zfs_file_t * fp , loff_t * offp , int whence )
199
+ zfs_file_seek (zfs_file_t * zfp , loff_t * offp , int whence )
185
200
{
186
- int rc ;
201
+ struct file * fp = zfp -> zf_fp ;
187
202
struct thread * td ;
203
+ int rc ;
188
204
189
205
td = curthread ;
190
206
if ((fp -> f_ops -> fo_flags & DFLAG_SEEKABLE ) == 0 )
@@ -196,8 +212,9 @@ zfs_file_seek(zfs_file_t *fp, loff_t *offp, int whence)
196
212
}
197
213
198
214
int
199
- zfs_file_getattr (zfs_file_t * fp , zfs_file_attr_t * zfattr )
215
+ zfs_file_getattr (zfs_file_t * zfp , zfs_file_attr_t * zfattr )
200
216
{
217
+ struct file * fp = zfp -> zf_fp ;
201
218
struct thread * td ;
202
219
struct stat sb ;
203
220
int rc ;
@@ -238,8 +255,10 @@ zfs_vop_fsync(vnode_t *vp)
238
255
}
239
256
240
257
int
241
- zfs_file_fsync (zfs_file_t * fp , int flags )
258
+ zfs_file_fsync (zfs_file_t * zfp , int flags )
242
259
{
260
+ struct file * fp = zfp -> zf_fp ;
261
+
243
262
if (fp -> f_type != DTYPE_VNODE )
244
263
return (EINVAL );
245
264
@@ -249,29 +268,36 @@ zfs_file_fsync(zfs_file_t *fp, int flags)
249
268
zfs_file_t *
250
269
zfs_file_get (int fd )
251
270
{
271
+ zfs_file_t * zfp ;
252
272
struct file * fp ;
253
273
254
274
if (fget (curthread , fd , & cap_no_rights , & fp ))
255
275
return (NULL );
256
276
257
- return (fp );
277
+ zfp = kmem_alloc (sizeof (* zfp ), KM_SLEEP );
278
+ zfp -> zf_fd = fd ;
279
+ zfp -> zf_fp = fp ;
280
+
281
+ return (zfp );
258
282
}
259
283
260
284
void
261
- zfs_file_put (zfs_file_t * fp )
285
+ zfs_file_put (zfs_file_t * zfp )
262
286
{
263
- fdrop (fp , curthread );
287
+ fdrop (zfp -> zf_fp , curthread );
288
+ kmem_free (zfp , sizeof (* zfp ));
264
289
}
265
290
266
291
loff_t
267
- zfs_file_off (zfs_file_t * fp )
292
+ zfs_file_off (zfs_file_t * zfp )
268
293
{
269
- return (fp -> f_offset );
294
+ return (zfp -> zf_fp -> f_offset );
270
295
}
271
296
272
297
void *
273
- zfs_file_private (zfs_file_t * fp )
298
+ zfs_file_private (zfs_file_t * zfp )
274
299
{
300
+ struct file * fp = zfp -> zf_fp ;
275
301
file_t * tmpfp ;
276
302
void * data ;
277
303
int error ;
0 commit comments