@@ -242,13 +242,7 @@ static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
242
242
return kernfs_file_read_iter (iocb , iter );
243
243
}
244
244
245
- /**
246
- * kernfs_fop_write - kernfs vfs write callback
247
- * @file: file pointer
248
- * @user_buf: data to write
249
- * @count: number of bytes
250
- * @ppos: starting offset
251
- *
245
+ /*
252
246
* Copy data in from userland and pass it to the matching kernfs write
253
247
* operation.
254
248
*
@@ -258,20 +252,18 @@ static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
258
252
* modify only the the value you're changing, then write entire buffer
259
253
* back.
260
254
*/
261
- static ssize_t kernfs_fop_write (struct file * file , const char __user * user_buf ,
262
- size_t count , loff_t * ppos )
255
+ static ssize_t kernfs_fop_write_iter (struct kiocb * iocb , struct iov_iter * iter )
263
256
{
264
- struct kernfs_open_file * of = kernfs_of (file );
257
+ struct kernfs_open_file * of = kernfs_of (iocb -> ki_filp );
258
+ ssize_t len = iov_iter_count (iter );
265
259
const struct kernfs_ops * ops ;
266
- ssize_t len ;
267
260
char * buf ;
268
261
269
262
if (of -> atomic_write_len ) {
270
- len = count ;
271
263
if (len > of -> atomic_write_len )
272
264
return - E2BIG ;
273
265
} else {
274
- len = min_t (size_t , count , PAGE_SIZE );
266
+ len = min_t (size_t , len , PAGE_SIZE );
275
267
}
276
268
277
269
buf = of -> prealloc_buf ;
@@ -282,7 +274,7 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
282
274
if (!buf )
283
275
return - ENOMEM ;
284
276
285
- if (copy_from_user (buf , user_buf , len ) ) {
277
+ if (copy_from_iter (buf , len , iter ) != len ) {
286
278
len = - EFAULT ;
287
279
goto out_free ;
288
280
}
@@ -301,15 +293,15 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
301
293
302
294
ops = kernfs_ops (of -> kn );
303
295
if (ops -> write )
304
- len = ops -> write (of , buf , len , * ppos );
296
+ len = ops -> write (of , buf , len , iocb -> ki_pos );
305
297
else
306
298
len = - EINVAL ;
307
299
308
300
kernfs_put_active (of -> kn );
309
301
mutex_unlock (& of -> mutex );
310
302
311
303
if (len > 0 )
312
- * ppos += len ;
304
+ iocb -> ki_pos += len ;
313
305
314
306
out_free :
315
307
if (buf == of -> prealloc_buf )
@@ -662,7 +654,7 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
662
654
663
655
/*
664
656
* Write path needs to atomic_write_len outside active reference.
665
- * Cache it in open_file. See kernfs_fop_write () for details.
657
+ * Cache it in open_file. See kernfs_fop_write_iter () for details.
666
658
*/
667
659
of -> atomic_write_len = ops -> atomic_write_len ;
668
660
@@ -950,7 +942,7 @@ EXPORT_SYMBOL_GPL(kernfs_notify);
950
942
951
943
const struct file_operations kernfs_file_fops = {
952
944
.read_iter = kernfs_fop_read_iter ,
953
- .write = kernfs_fop_write ,
945
+ .write_iter = kernfs_fop_write_iter ,
954
946
.llseek = generic_file_llseek ,
955
947
.mmap = kernfs_fop_mmap ,
956
948
.open = kernfs_fop_open ,
0 commit comments