r/linuxdev • • Apr 10 '20

How to write to a proc file?

I need to make this linux kernel module where I am supposed to get the source and destination IP addresses of some docker containers and print them out in a file. I can capture IP addresses and print them out on the kernel log.

After hours of trying to figure out how to use proc_fs.h, I managed to find out how to create a proc_dir_entry . Now since, I am using netfilter.h to capture packets, I need the file to be written every time the hook function gets called. I found this function in proc_fs.h but I don't quite understand it:

typedef int (*proc_write_t)(struct file *, char *, size_t);

Is this function changing instances of int to some struct called proc_write_t composed of a file pointer, char pointer, and the size of what you are going to write?

7 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/NotAHippo4 Apr 11 '20

Also, I am reading about sysfs.h. Isnt the sysfs supposed to be used for actual devices or computer resources instead of simply files?

1

u/datenwolf Apr 11 '20

No, that's what the devfs is supposed for. Sysfs is for anything that's not tied to a process and also that's not tied to a specific device or which is tied to a device, but doesn't fit the block, char, ioctl model. For example kernel module parameters are accessible in /sys/module/${MODULE_NAME}