Read/write files within a Linux kernel module

后端 未结 2 832
一个人的身影
一个人的身影 2020-11-22 03:29

I know all the discussions about why one should not read/write files from kernel, instead how to use /proc or netlink to do that. I want to read/write anyw

2条回答
  •  我在风中等你
    2020-11-22 04:15

    Since version 4.14 of Linux kernel, vfs_read and vfs_write functions are no longer exported for use in modules. Instead, functions exclusively for kernel's file access are provided:

    # Read the file from the kernel space.
    ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos);
    
    # Write the file from the kernel space.
    ssize_t kernel_write(struct file *file, const void *buf, size_t count,
                loff_t *pos);
    

    Also, filp_open no longer accepts user-space string, so it can be used for kernel access directly (without dance with set_fs).

提交回复
热议问题