squashfuse_extract
probonopd opened this issue · 2 comments
probonopd commented
If would be nice if there was a tool to extract rather than list the files in a squashfs file, similar to squashfuse_ls
.
probonopd commented
@vasi gave me hints to use the following:
- sqfs_traverse_*: https://github.com/vasi/squashfuse/blob/master/traverse.h#L33 . This lets you look at every file in the filesystem, gives you a sqfs_traverse structure that contains a sqfs_dir_entry, which itself gives you a sqfs_inode_id .
- sqfs_inode_get: https://github.com/vasi/squashfuse/blob/master/fs.h#L119 From an inode id, this gives you an sqfs_inode structure. That contains various information about the file/dir/socket/whatever. https://github.com/vasi/squashfuse/blob/master/fs.h#L54
- The types of "whatever" are in the inode's base.inode_type -
Lines 79 to 93 in 78360b7
- sqfs_read_range: https://github.com/vasi/squashfuse/blob/master/file.h#L60 Given a sqfs_inode, this reads some data from it!
- Also, be careful about reading the file all at once. What if the file size is 10 GB? Your program will attempt to malloc() a giant buffer! You can replace one giant read with multiple small ones!
- To get just one file, you don't have to traverse the whole archive. You can just use sqfs_lookup_path(): https://github.com/vasi/squashfuse/blob/master/dir.h#L72
probonopd commented
I have started a (very) simplistic tool to extract regular files and directories from a squashfs file at https://github.com/probonopd/squashfuse/blob/master/extract.c