Find the answer to your Linux question:
Results 1 to 2 of 2
I'm writing a kernel module that will create a directory in /proc and will dynamically create a set of files based on parameters passed in when the module is loaded. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    2

    Filename in Kernel Module file_operations.read


    I'm writing a kernel module that will create a directory in /proc and will dynamically create a set of files based on parameters passed in when the module is loaded. I want to have a single read function for all these files and then figure out which file it is from inside that function.

    So if I do a `cat /proc/registers/2` I'd call procfs_read_registers and somehow figure out that I'm reading "2".

    Code:
    static ssize_t procfs_read_registers(
      struct file *filp,
      char *buff,
      size_t len,
      loff_t *offset)
    {
      // Find File Name and write back the data for that register.
    }
    
    static const struct file_operations procfs_operations_registers = 
    {
      .owner = THIS_MODULE,
      .open = procfs_open_registers,
      .read = procfs_read_registers,
      .release = procfs_read_registers,
    };
    Dug through the kernel source but between that and the man pages I'm a bit lost.

  2. #2
    Just Joined!
    Join Date
    Feb 2010
    Posts
    2
    Figured it out.

    Code:
    filp->f_path.dentry->d_iname

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •