[SOLVED] Loopback Device and file expansion

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kammce
Posts: 18
Joined: Sun Apr 15, 2012 9:17 pm

[SOLVED] Loopback Device and file expansion

Post 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.
Last edited by kammce on Thu Apr 26, 2012 8:11 pm, edited 1 time in total.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Loopback Device and file expansion

Post by Kazinsal »

It'll be what size you make it, minus whatever the filesystem you format the "disk" with takes up.
kammce
Posts: 18
Joined: Sun Apr 15, 2012 9:17 pm

Re: Loopback Device and file expansion

Post by kammce »

Thank you for your answer!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: [SOLVED] Loopback Device and file expansion

Post 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.
Every good solution is obvious once you've found it.
User avatar
AndrewAPrice
Member
Member
Posts: 2303
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: [SOLVED] Loopback Device and file expansion

Post 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.
My OS is Perception.
Post Reply