View on GitHub

Lolfs

Container file / minimalistic filesystem

download .ZIPdownload .TGZ
Liblolfs - Little Object List (LOL) filesystem - by Niko Kiiskinen


        Please see file 'INSTALL' for detailed installation instructions
        The file COPYING is a copy of the General Public License v2,
        under which this software is distributed.

        This software package comes with some install scripts, some
        of which are distributed under The General Public License v3.
        See the file gpl3.txt for information about this license.


Manifesto

LolFS is a container file. It means that it is a file
     which has other files inside it.

     Once you create a lol container file (using the included
     'mkfs.lolfs' utility or 'lol fs' command, you can then
     store content (any files basically) into it.

     The 'lol' program is an interface app to execute common file
     operations, like copying files to and from the container,
     listing files, space usage etc.. See below for details.

     But wait.. Why would anybody store files into this
     container thing - why not just create a new directory and put
     those files there?

     I don't see a good reason, this is just a toy project for me
     and I like to play with it! - I am very aware of the double
     meaning of the name of this project :D

     Maybe I will add something interesting into future releases,
     something that might actually make this project useful -
     like automatic encryption of files..

     And there is one more thing. Maybe someone can make use of it
     as part of a bigger project that needs a container, after all,
     many projects have several data files around and it might
     become handy to store them all inside one "master" file.
     Lolfs has very simple C API (see bottom of this page) to put
     those things together.



    lol program
    ============

                The 'lol' program is the main user interface to create
                and access files inside a lolfs container.

                'lol' has several built-in functions which
                may be used to execute some common file operations.
                These functions are currently (in v 0.40) :

                - fs
                - cat
                - cc
                - cp
                - df
                - ls
                - rm
                - rs




                 lol fs function:
                 ----------------


                 lol fs   creates a new container file.


                 Example 1:
                             "lol fs -s 700M test.db"

                         This example creates a container file
                         'test.db' which has 700 Megabytes
                         of storage capacity.

                 Example 2:
                             "lol fs -b 1000 5000 lol.db"


                         This example creates a container file
                         'lol.db' which has 5000 data blocks,
                         each 1000 bytes. So the storage capacity
                         for this example is 1000 * 5000 bytes.




                 lol cat function:
                 -----------------


                 lol cat  Prints the contents of a file (inside a container)
                          to standard output.


                 Example 1:
                             "lol cat test.db:/readme.txt"

                 Example 2:
                             "lol cat test.db:/pic.jpg > backup.jpg"





                 lol cc function:
                 ----------------


                 lol cc     checks if a container has errors.


                 Example 1:
                             "lol cc test.db"

                 Example 2:
                             "lol cc -d test.db" (shows more details)




                 lol cp function:
                 ----------------

                 lol cp copies files to (and from) a container.

                     If you want to copy a file readme.txt to your
                     container file 'test.db', use:

                 Example 1:
                             "lol cp readme.txt test.db"


                     You can copy multiple files like:

                 Example 2:
                             "lol cp *.jpg test.db"


                     If you want to copy a file which is inside the container
                     back to your host filesystem, use:

                 Example 3:
                             "lol cp test.db:/readme.txt /some/directory"

                   NOTE: When accessing files inside your container, you must
                         separate the path with ':' like in above example.




              lol df function:
              ----------------


                    lol df  Shows how much space is used in container file.

                 Example:
                           "lol df my.db"





              lol ls function:
                 ----------------


                 lol ls   lists the files inside a container.

 
                         For example, if you want to list all the files
                         inside a container file "lol.db", type:

                 Example:
                           "lol ls lol.db"




               lol rm function:
                 ----------------


                 lol rm   deletes a file from your container file.


                 Example:
                           "lol rm test.db:/mother_in_law.jpg"


                 NOTE:   Note also here (this is common feature when accessing
                         files inside a container), that you must separate
                         the file with a ':' from it's container.



              lol rs function:
                 ----------------


                 lol rs    extends a container file by adding more
                           storage space into it. Use this function
                           if the container is full or is becoming full.


                 Example 1:

                            "lol rs -s 200M lol.db"

                             This adds 200 Megabytes new space to
                             container 'lol.db'.


                 Example 2:

                            "lol rs -b 1000 my.db"

                            This adds 1000 new data blocks to
                            container 'my.db'



    mkfs.lolfs program
    ===================


                "mkfs.lolfs" creates a new container file.


                  It works exactly as 'lol fs' command. (See above).


                 ( In Linux, lolfs may be used directly with removable storage,
                   without warranty of course!
                   So, you may actually insert an SDHC card to your Linux
                   and create a lol storage directly there. In that case the
                   "filename" parameter is just the name of the device,
                   for example "mkfs.lolfs -b 512 4000000 /dev/sdb"
                   You MUST know what you are doing then, and of course
                   you must be root to do that - or anything similar.
                   You have been warned! :)



    fsck.lolfs program
    ===================


                "fsck.lolfs" checks a lol container for errors.

                It works exactly as 'lol cc' command. (See above).


lolfs API:


lolfs API:
==========

     The API functions are explained in <lolfs.h>
     They are identical to their standard C counterparts,
     except the "lol_" prefix in the name:

     - For example use "lol_fopen" to open a file inside
       your container, it returns a lol_FILE* handle which
       may then be used to lol_fread, lol_fwrite, lol_fseek etc..

     - when you lol_fopen a file (or otherwise manipulate files inside
       a container file, you must separate the filesystem path from the
       file inside a container with a ':'

     Example: Create a file "test.txt" inside container called 'my.db'.

              lol fs -s 20k my.db

#include <stdio.h>
#include <string.h>
#include <lolfs.h>

int main()

/* test.c - a lolfs API test */

{

         lol_FILE *fp;
         char text[] = "Hello World!\n";

         fp = lol_fopen("my.db:/test.txt", "w");

         if (!(fp)) {
            printf("cannot create the file\n");
            return -1;
         }

         lol_fwrite((char *)text, strlen(text), 1, fp);
         lol_fclose(fp);
         return 0;

} // end main

How to compile and link a lolfs C program:

gcc test.c -o test -llolfs

(You may need to include compiler option -L/path/to/librarydir if the linker does not find lolfs library)

gcc test.c -o test -L/usr/local/lib64 -llolfs -I/usr/local/include

Run the test:

shell> ./test

List the files inside my.db

shell> lol ls my.db

Thu Dec 29 19:56:18 2016 13 hello.txt
total 1

See the contents of hello.txt

shell> lol cat my.db:/hello.txt
Hello World!

Questions, Bug reports, etc..

 Niko Kiiskinen
 lolfs.bugs@gmail.com
 https://github.com/nkiiskin/lolfs

Distribution date: Thu Dec 29 05:02:47 EET 2016