Page 1 of 1

FUSE-mounting partitions in image file

Posted: Sat May 28, 2022 9:50 am
by kurtmweber
Let's say I've written a FUSE driver for my OS's filesystem. On a particular disk image file, that filesystem is one of several partitions. I'd like to be able to mount that partition in my host/development system to streamline the process of populating it for testing purposes, particularly before I get writing working in my OS project.

The FUSE manual doesn't seem to indicate any way to specify a specific partition by name within an image file to mount (or even by specifying an offset + length, as one might with losetup).

It occurs to me that (as perhaps indicated above) one could use losetup + partx to detect and add loopback devices for the partitions, and then mount the partition's loopback device via fuse--but that seems a bit kludgey. Is there a better, more straightforward way that I'm overlooking or that someone else has come up with (and that does not require privilege elevation, as working with loopback devices does)?

Re: FUSE-mounting partitions in image file

Posted: Sat May 28, 2022 10:40 am
by Ethin
If this is a QEMU image, use qemu-nbd(8) to manipulate it like a normal device.

Re: FUSE-mounting partitions in image file

Posted: Sat May 28, 2022 10:46 am
by kurtmweber
It's not, it's just a raw disk image.

Re: FUSE-mounting partitions in image file

Posted: Sat May 28, 2022 12:05 pm
by nullplan
Add an "offset" option to your FUSE driver (or, more likely, offset and length), then write a program that parses the partition table of the disk image and tells you offset and length of the partition you want. Change your FUSE driver to limit your file accesses to the given range.

That is how UNIX was supposed to work, use different tools for different jobs. Parsing partition tables is not the same job as implementing a file system.