AgentD / squashfs-tools-ng

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

File permissions on Windows #127

Closed caesay closed 2 months ago

caesay commented 3 months ago

When packing a squashfs filesystem on Windows using gensquashfs.exe, all the files are created with 0644 permissions, even when -d mode=0755 is set. This is problematic if the file system is designed to be mounted on Linux with FUSE and run. (in that instance, it will be read-only, and the permissions can not be corrected later)

I don't think this is what the --defaults arg was intended for, but the help text seems to imply the -d default arg should be used for anything implicit. On windows, there is no file permissions per say, so I think it makes sense. Alternatively, we could have a separate argument allowing us to override the permission of all files? Even better would be an glob, because technically only the executable files need to be set to 0755.

AgentD commented 2 months ago

Hi @caesay ,

yes, on Windows the directory scanning code assumes 0644 for files and 0755 for directories.

There is a --pack-file option (in hindsight, properly calling it a manifest might have been less ambiguous) where you can specify a detailed filesystem manifest with permissions, ownership and everything, in a style similar to Linux gen_init_cpio.

The tree described in the manifest doesn't even have to exist on the disk at all, when packing a file, a source path can be specified that does not have to match the path in the generated filesystem.

This is also where the --defaults comes into play. If e.g. the manifest specifies /foo and /foo/bar/baz, the defaults are assumed for /foo/bar. The manifest can still overwrite this at a later point. The defaults are also assumed for the / root directory and IIRC I also patched the manifest parsing code at one point to allow overriding that too.

If --pack-file and --pack-dir are specified, the file path in the manifest can be specified relative to that source directory.

Globbing from the source directory is already supported with the following syntax:

glob <path> <mode|*> <uid|*> <gid|*> [OPTIONS...] <location>

The <path> is the location in the tree, and <location> is a source path, which can be relative to --pack-dir.

For mode, uid, gid, specifying * means, take the values from the filesystem found on disk, instead of explicitly setting them.

The options try to imitate the Unix find program, e.g. the option -name is supported with a shell globbing pattern that needs to match for stuff to be included. Filtering by type -type d for directory or -type f for regular files is also supported (as well as device files, symlinks etc. but that is probably less useful on Windows).

Hope that helps!