AgentD / squashfs-tools-ng

A new set of tools and libraries for working with SquashFS images
Other
194 stars 30 forks source link

gensquashfs: Allow to disable padding #113

Open Gottox opened 1 year ago

Gottox commented 1 year ago

I'm planning to use squashfs as an archive format, for that it would be cool to be able to disable padding completely. mksquashfs already supports that with the -nopad option. gensquashfs also has such a feature, but the lowest value that can be chosen is 1024 byte padding.

I couldn't find any pointers to that value in the reference, so I would guess, that kb alignment is the minimal value that makes it usable using kernel mount.

It would be awesome if I could disable padding completely.

AgentD commented 1 year ago

Hi,

yes, the padding is a requirement by the kernel module. It is referred to as "device block size" and the kernel config you can choose this to be either 1k or 4k. I chose 4k as default, because then it also happens to be 1k padding.

This is really just padding it with 0 bytes at the end to make the size a multiple. It does not entail any internal alignment.

So how big are your archives that this would actually matter? If you have a 100k archive, the padding makes up between 1% and 4% of that size at most. For an archive that's 1M in size the padding makes up less than 0.4% at most.

Gottox commented 1 year ago

Ah, thanks for the pointer in the kernel config!

To explain my use case a bit more: My plan was to append structured data (a signature) at the end of the archive. Extracting it from the archive is pretty easy as I'm using libsqsh and does not involve any padding logic: Just read from the "bytes used" value in the superblock till the end of the file.

On creation time I rely on shell tools, so I can't read out the header. Instead I'm just doing something like that:

mksquashfs ... foobar.img ... -nopad
signify -S -m foobar.img ... 
cat foobar.img.sig >> foobar.img
# If I want it to be mountable: (TIL :D)
truncate --size '%4096' foobar.img

With gensquashfs I gain the ability to set xattrs on any filesystem, like tmpfs. That's one of the reasons why I'd like to switch to gensquashfs.