zargony / fuse-rs

Rust library for filesystems in userspace (FUSE)
MIT License
1.05k stars 131 forks source link

Read file using inode number #156

Closed mb720 closed 3 years ago

mb720 commented 3 years ago

Hi and thanks for fuse-rs!

I'd like to read the contents of a file using its inode number, basically reimplementing what debugfs does with the cat command:

debugfs -R 'cat <8>' /dev/sda3

In this example, /dev/sda3 has an ext4 file system.

I know that this create has read but I'm not sure whether this method is suitable for my task.

How would I use read to get at the contents of a file using the file's inode number?

Thanks!


Using inode number 8 in the example above is not a coincidence: I want to read the ext4 journal with Rust.

Minoru commented 3 years ago

Hi! I think you're confusing a few things here.

The debugfs that you linked is a virtual filesystem that Linux kernel uses for debugging. It has no relationship to the debugfs binary that contains the cat command. Do not look at the docs for debugfs-the-filesystem, they are irrelevant.

The read() function that you linked is a part of a FUSE low-level interface, which is an interface between the kernel and your application. It gets called by the kernel when someone tries to read a file, but the inode is supplied by the kernel, based on your app's earlier response to lookup() function which converts paths to inodes. There is no way to directly call this read() from the userspace; you can only call things like open(2) and read(2) which the kernel then translates into calls to FUSE's lookup() and read().

Linux, and Unix-likes in general, don't provide an API to read a specific inode, because Unix's permissions system relies on paths.

If you want to read the ext4 journal, you have to open /dev/sda3 as a binary file, find the offset at which the journal starts, and read that. Or maybe script over debugfs-the-tool to parse its output. I don't think FUSE, or this crate, can help you with any of that.

mb720 commented 3 years ago

You're right, the link to debugfs should have been to the tool.

Thank you for confirming that fuse-rs is probably not the right choice for my little undertaking.

My current leads are getting inspiration from jls (part of The Sleuth Kit) that uses the method ext2fs_dinode_load to get at the file contents and cat from debugfs which calls dump_file.