Page 1 of 1

[SOLVED] Loopback Device and file expansion

Posted: Thu Apr 26, 2012 2:27 pm
by kammce
when you mount a file as a drive as shown in Loopback_device will it expand as needed or will it only be able to store what size I make it?

Thank you for your time.

Re: Loopback Device and file expansion

Posted: Thu Apr 26, 2012 3:34 pm
by Kazinsal
It'll be what size you make it, minus whatever the filesystem you format the "disk" with takes up.

Re: Loopback Device and file expansion

Posted: Thu Apr 26, 2012 8:11 pm
by kammce
Thank you for your answer!

Re: [SOLVED] Loopback Device and file expansion

Posted: Thu Apr 26, 2012 11:14 pm
by Solar
The file, in its current size, will be mounted as if it were a block device.

Some emulators allow having "sparse" image files, i.e. an image of 1 GiB but being 99% unused can be only a couple of megabytes. But that is a completely different mechanism from what loopback does.

Re: [SOLVED] Loopback Device and file expansion

Posted: Mon Apr 30, 2012 9:29 pm
by AndrewAPrice
Some file systems (ext3/4) have the option of supporting sparse files. That means you can write to the very last byte of the file at the size you want it to be, and it'll allocate the space of the last inode, but skip allocating the inodes where nothing has been written to (and if you read from there it'll return all 0s).

Of course, unless you have an API to differentiate between "File size" and "Size on disk" (such as Windows provides) then you have no way of finding out exactly how much space a file takes up.

Also interesting, is with sparse files, you could have a 1GB hard drive claiming to have a directory containing 1TB of files. :)

Alternatively, you could let your loop back device write past the end of the file and extend it - and design a file system for endless expanding mediums.