3

I want to experiment with some Virtual File Systems, like having 1 file in which all data is stored (1 file = virtual disk). For example I can open the virtual disk and put files into it, write data to the files, read data from file, open files and use fseek etc..

Is there any library I can use for that? License stuff etc is not important. I just want to test it on my machine because I'm borred, So I want to try this in C++/C.

Thanks in advance! :)

If the library is windows only then it's also okay, maybe I will find a linux library so I can make 2 projects?


Edit: Thanks to BRPocock I know my question is a bit unclear. What I really want is a library which has the ability to store files, read files, and perform file operations on a VFS which the library already provides. And ofcourse mounting. So, What I would preffer is if there is a library which gives me this functions in C++:

OpenVirtualDrive(const name[]);//
CloseVirtualDrive(handle);//
fopen(const name[], mode);//open file, return handle
fclose(handle);//close handle
ftemp(); //open file as temporary file
fremove(const name[]);//delete file

fwrite(handle, array[]);//write array to file
fread(handle, array[], size = sizeof array, pack = false);//read from file
fputchar(handle, value, utf8 = true);//put char into file
fgetchar(handle, value, utf8 = true);//read char from file, move pointer
fblockwrite(handle, const buffer[], size = sizeof buffer);//write block
fblockread(handle, buffer[], size = sizeof buffer);//read block, move pointer

fseek(handle, position = 0, seek_whence: whence = seek_start);//move pointer
flength(handle);//size of file
fexist(const pattern[]);//check if file exists
fmatch(name[], const pattern[], index = 0, size = sizeof name);//search for file

This is just pseudo code :P

  • This sounds like an OS-level thing and probably doesn't need any C/C++ code written. You could create a "disk image" file somewhere and then mount that image as a read/write disk. Linux does this with `loop` FS and the `mount` command. Mac OS X has image creation in Disk Utility and the Finder can mount images directly (just double-click them). Dunno what Windows does, but I'd bet something like VirtualCloneDrive is all you'd need. Once done with this, you can then access your image with any language's standard file operations. – Mike DeSimone May 09 '12 at 18:56
  • A similar [question](http://stackoverflow.com/questions/2336804/open-source-embedded-filesystem-or-single-file-virtual-filesystem-or-structure) that might provide some ideas... – Ioan May 09 '12 at 20:01

1 Answers1

4

Linux (and many BSDs, including, I believe, MacOSX) uses the FUSE system (http://fuse.sourceforge.net/) to provide those kinds of services. You should be able to find many examples on the 'Net.

I believe the “accepted” way to do the same thing on Windows is to write it as a device-driver loadable module (.dll) … a quick Googling points at http://msdn.microsoft.com/en-us/windows/hardware/gg463062 as the starting-point, perhaps.

BRPocock
  • 13,638
  • 3
  • 31
  • 50
  • It's not really that I want to create a new File System totally myself hehe :D The fuse link looks Usefull, thanks, but the windows Kit states in short that you have to make your own FS too. I prefer tto first make it on Windows then on Linux :P –  May 09 '12 at 17:30
  • 1
    Well, what your question describes is, actually, making a new filesystem. However, if you just want to create a virtual *block device* onto which you can store someone else's filesystem (e.g. a FAT filesystem), look at the Windows device drivers for block devices. On Linux, you can use the `loop` filesystem device (to “loop back” a filesystem onto a file) natively – BRPocock May 09 '12 at 17:33
  • 2
    And I found http://code.google.com/p/whefs/ But I need some examples on how to use it :$ –  May 09 '12 at 17:46