Wednesday, April 22, 2009

bmpfs

This is really cool! File systems you can SEE!

Python code:
#!/usr/bin/python
# create_image.py
import Image
im = Image.new('RGB', (8192,8192),(255,255,255))
im.save('new.bmp', 'BMP')


Put the above in a file and run:
python create_image.py

This creates a blank, white bitmap. Nothing special yet.

Next do this:
sudo losetup /dev/loop0 new.bmp -o 100
sudo mkfs.ext2 /dev/loop0
sudo losetup /dev/loop0 -d


Now look at the bitmap. There's a thin bar along the bottom. That's your file allocation table! You now have an ~190 MB combination disk image-bitmap image!

Now lets stick something in our new "disk image":
mkdir temp
sudo mount -o loop,offset=100,user new.bmp temp
sudo chown 1000:1000 temp
# replace 1000 with you user and group id respectively

Now copy something respectably sized into temp. I copied a 32mb video into there.

Unmount the image and you can look at it:

sudo umount temp
eog new.bmp


also try this (imagemagick required):

convert new.bmp new.png

Note the size of the file(s) you put in there. I put a 33799296 byte video in there and the png came out to 33939231 bytes. (Videos are basically not compressible.) Not bad. Since png uses lossless compression, you can convert back and the bitmap still mounts! Try it!

No comments:

Post a Comment