PDA

View Full Version : Making A Mountable File



Mr.Macdonald
August 11th, 2008, 05:08 AM
As practice in programming i wanted to make a file that could be mounted, similar to an iso. could someone point me in the right direction

remember that this is practice so please don't tell me that their will be little value in this because i know the product will be of little value but the practice will the the value

mssever
August 11th, 2008, 05:14 AM
As practice in programming i wanted to make a file that could be mounted, similar to an iso. could someone point me in the right direction

remember that this is practice so please don't tell me that their will be little value in this because i know the product will be of little value but the practice will the the value
Try something like this:

dd if=/dev/zero of=/some/file bs=blocksize count=numberofblocksThen, format your file.

Mr.Macdonald
August 11th, 2008, 05:59 AM
i don't think i was clear enough.

I want to design my own file format that could be mounted. Like an Iso file.
Basically I could mount it to a folder, then drop files into the folder, unmount it, mount that file elsewhere, and read from the files from that elsewhere place. (sorry for all the commas)

mssever
August 11th, 2008, 06:16 AM
i don't think i was clear enough.

I want to design my own file format that could be mounted. Like an Iso file.
Basically I could mount it to a folder, then drop files into the folder, unmount it, mount that file elsewhere, and read from the files from that elsewhere place. (sorry for all the commas)
All an ISO is is a plain file (such as is generated by dd) that is formated as iso-9660. There's nothing special about it. My code will give you that type of file if you format it as such. Or, you can have an ext3 filesystem. Or...

Zugzwang
August 11th, 2008, 02:52 PM
A clarification for the OP:

Mounting a file is exactly the same as mounting a device, with the only difference that it's a file. :-) So in order to have a mountable file, it has to reflect a file system that is recognized by the kernel, like FAT, ISO-9660, NTFS, EXT2FS, whatever. So you basically need to implement a writer to such a file system which is quite a complicated task.

You might also want to look into FUSE (http://fuse.sourceforge.net/) which is not what you asked for but might be worth looking at.

mssever
August 11th, 2008, 03:07 PM
So you basically need to implement a writer to such a file system which is quite a complicated task.
Nothing complicated about it. (My commands below are in bold.)


~:$ dd if=/dev/zero of=test bs=1024 count=50000
50000+0 records in
50000+0 records out
51200000 bytes (51 MB) copied, 0.400806 s, 128 MB/s
~:$ mkfs.ext3 test
mke2fs 1.40.8 (13-Mar-2008)
test is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
12544 inodes, 50000 blocks
2500 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=51380224
7 block groups
8192 blocks per group, 8192 fragments per group
1792 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
~:$ sudo mount -t ext3 -o defaults,loop test /mnt
~:$ ls /mnt/
lost+found/
~:$

Mr.Macdonald
August 11th, 2008, 05:32 PM
For mssever:

I want to design my own file format that could be mounted. Like an Iso file.using ext3, iso-9660, fat or others doesn't qualify because i didn't design it

And i will look into writing a filesystem, thanks