Connection with the Virtual Filesystem

Up to now, I have presented everything that is required from a sequential file user. The rest, that is, connecting the operations with the virtual filesystem, is left to the kernel. To establish the connection, it is necessary to use the seq_read as read method for file_operations as shown above in the case of debugfs_kprobes_operations. The method bridges VFS and sequential files.

First of all, the function needs to obtain the seq_file instance from the VFS layer's struct file. Recall that seq_opened has established a connection via private_data.

If some data are waiting to be written out — as indicated by a positive count element of struct seq_file —, they are copied to userland with copy_to_user. Additionally, updating the various status elements of seq_file is required.

In the next step, new data are generated. After calling start, the kernel calls show and next one after another until the available buffer is filled. Finally, stop is employed, and the generated data are copied to userspace using copy_to_user.

Continue reading here: Writing Filesystems with Libfs

Was this article helpful?

0 0