Home | About | Partners | Contact Us
VA Linux Systems

yakrofs: Virtual Read-only File System

Yakrofs is a small virtual read-only file system for application development. It is intended for use in applications which have a need for a large number of resources stored in files with fast retrieval; ideal, for example, for game development, where hundreds of textures and sound samples must be organized well and retrievable with a high degree of efficiency.

To this end, yakrofs provides the following services:

  • A set of "virtual file system" objects which allow user-definable file systems. Two are provided: one which uses a standard file system directory tree, and one which uses a zip file.
  • A composite file system into which virtual file systems can be "mounted" in different locations. This allows for an extremely flexible setup where, for example, a zip file could be mounted as the root of the file system (/) but a directory could be mounted as a subtree (/images/main_character), which can ease the process of testing new resources without having to do a full build of application resources.
  • A single, simple handle-based C-callable interface (currently only 8 functions) which simplifies use of the library from other languages besides C.
Currently portions of yakrofs are written in C++, meaning that libstdc++ must be linked with your project. However, the API is entirely callable by C programs, so there is no worry about "corrupting" your C source code with C++.

Sample

Here is the sample program provided with the library, which gives a very basic view of some yak_rofs features:

#ifndef YAK_ROFS_H
#include "yak_rofs.h"
#endif

#include 

/*
  This is a simple program meant to show how the yak_rofs
  library can be used to open and read files from a virtual file
  system.
*/

void
print_buffer( char* buffer, int size )
{
  int i;
  for ( i = 0; i < size; ++i )
    {
      putchar( buffer[ i ] );
    }
  putchar( '\n' );
}

void
print_file( char* filename )
{
  ROFS_HANDLE h;
  h = yak_rofs_open_handle( filename );
  if ( yak_rofs_is_valid_handle( h ) )
    {
      print_buffer( yak_rofs_handle_buffer( h ), 
		    yak_rofs_handle_size( h ) );
    }
  else
    {
      puts( "Unable to open " );
      puts( filename );
      puts( "\n" );
    }
}


int main( int arg_count, char** arg_vector )
{
  /* first, mount the current directory as root and print the test text */
  yak_rofs_mount( ".", "/" );
  puts( "With current directory mounted as root, printing test_text.txt:\n" );
  print_file( "/test_text.txt" );

  /* now, unmount the current directory as root, mount the zip file as root, */
  /* and do the same thing. */
  yak_rofs_umount( "/" );
  yak_rofs_mount( "test.zip", "/" );
  puts( "\n\nWith test.zip mounted as root, printing test_text.txt:\n" );
  print_file( "/test_text.txt" );
}
With different files called "test.txt" (one in the current directory and one in a zip file named "test.zip", this produces the following output:
With current directory mounted as root, printing test_text.txt:

This is the text stored in the filesystem version of test_text.txt


With test.zip mounted as root, printing test_text.txt:

This is the text stored in the zip file version of test_text.txt

Downloadables

Yakrofs is currently not released in package form, as there are some elements that need to be fixed (for example, if you open a handle from a rofs mounted in the main tree, unmount the rofs, and then attempt to use the handle, you will get undefined behaviour--not good). Feel free to examine the cvs tree at the sourceforge prokect page at http://sourceforge.net/projects/yakrofs.

Hosted by Sourceforge

This project is hosted by the kind folks at SourceForge Logo
All trademarks and copyrights on this page are properties of their respective owners. Forum comments are owned by the poster. The rest is copyright ©1999-2000 VA Linux Systems, Inc.