14
14
#include <linux/pagemap.h>
15
15
#include <linux/sched/mm.h>
16
16
#include <linux/fsnotify.h>
17
+ #include <linux/uio.h>
17
18
18
19
#include "kernfs-internal.h"
19
20
@@ -180,11 +181,10 @@ static const struct seq_operations kernfs_seq_ops = {
180
181
* it difficult to use seq_file. Implement simplistic custom buffering for
181
182
* bin files.
182
183
*/
183
- static ssize_t kernfs_file_direct_read (struct kernfs_open_file * of ,
184
- char __user * user_buf , size_t count ,
185
- loff_t * ppos )
184
+ static ssize_t kernfs_file_read_iter (struct kiocb * iocb , struct iov_iter * iter )
186
185
{
187
- ssize_t len = min_t (size_t , count , PAGE_SIZE );
186
+ struct kernfs_open_file * of = kernfs_of (iocb -> ki_filp );
187
+ ssize_t len = min_t (size_t , iov_iter_count (iter ), PAGE_SIZE );
188
188
const struct kernfs_ops * ops ;
189
189
char * buf ;
190
190
@@ -210,7 +210,7 @@ static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
210
210
of -> event = atomic_read (& of -> kn -> attr .open -> event );
211
211
ops = kernfs_ops (of -> kn );
212
212
if (ops -> read )
213
- len = ops -> read (of , buf , len , * ppos );
213
+ len = ops -> read (of , buf , len , iocb -> ki_pos );
214
214
else
215
215
len = - EINVAL ;
216
216
@@ -220,12 +220,12 @@ static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
220
220
if (len < 0 )
221
221
goto out_free ;
222
222
223
- if (copy_to_user ( user_buf , buf , len ) ) {
223
+ if (copy_to_iter ( buf , len , iter ) != len ) {
224
224
len = - EFAULT ;
225
225
goto out_free ;
226
226
}
227
227
228
- * ppos += len ;
228
+ iocb -> ki_pos += len ;
229
229
230
230
out_free :
231
231
if (buf == of -> prealloc_buf )
@@ -235,22 +235,11 @@ static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
235
235
return len ;
236
236
}
237
237
238
- /**
239
- * kernfs_fop_read - kernfs vfs read callback
240
- * @file: file pointer
241
- * @user_buf: data to write
242
- * @count: number of bytes
243
- * @ppos: starting offset
244
- */
245
- static ssize_t kernfs_fop_read (struct file * file , char __user * user_buf ,
246
- size_t count , loff_t * ppos )
238
+ static ssize_t kernfs_fop_read_iter (struct kiocb * iocb , struct iov_iter * iter )
247
239
{
248
- struct kernfs_open_file * of = kernfs_of (file );
249
-
250
- if (of -> kn -> flags & KERNFS_HAS_SEQ_SHOW )
251
- return seq_read (file , user_buf , count , ppos );
252
- else
253
- return kernfs_file_direct_read (of , user_buf , count , ppos );
240
+ if (kernfs_of (iocb -> ki_filp )-> kn -> flags & KERNFS_HAS_SEQ_SHOW )
241
+ return seq_read_iter (iocb , iter );
242
+ return kernfs_file_read_iter (iocb , iter );
254
243
}
255
244
256
245
/**
@@ -960,7 +949,7 @@ void kernfs_notify(struct kernfs_node *kn)
960
949
EXPORT_SYMBOL_GPL (kernfs_notify );
961
950
962
951
const struct file_operations kernfs_file_fops = {
963
- .read = kernfs_fop_read ,
952
+ .read_iter = kernfs_fop_read_iter ,
964
953
.write = kernfs_fop_write ,
965
954
.llseek = generic_file_llseek ,
966
955
.mmap = kernfs_fop_mmap ,
0 commit comments