Malcolm's github site Baby X Resource compiler Baby X FileSystem    Baby X FS banner

The BBX_FileSystem object

The Baby X FileSystem object, BBX_FileSystem, is a Baby X object designed to work with FileSystem XML files. The object makes it easy for programmers to use these files aand to manipulate the. It is part of the BabyXFS or Baby X FileSystem project, whch is a project designed to allow Baby X user to mount directories. The C code is documented here

A baby virtual filesystem

The BBX_FileSystem object is designed to answer the question of how to mount virtual file systems in Baby X or other small "baby" hobby programs. So like all of Baby X, the emphasis is on simplicity and portability, to give the hobby programmer an easy or "baby" component to work with. So the BBX_FileSystem object use FileSystem XML files, a vey clean XML format designed for Baby X, but free for anyone to use. It loads a FileSystem XML file and treates it as an internal drive which the program can query.

The object has two dependencies, a BabyXFS utilities file, and an XML parser. So three .c files and three .h files are all you need to take to use it. The files are hosted on github, here. And then you simply drop those files into your program and you can use it. It's all clean ANSI C.

And you can easily convert a folder on your machine to a FileSystem XML file using the utilities in the BabyXFS subsystem. So the object is extremely powerful and easy to use, and of course like all of Baby X, it is free for anyone to use for any purpose, thought it is mainly aimed at the hobby programmer writing small programs.

Mounting host directories

Whilst the BBX_FileSystem object is designed to be used with FileSystem XML files, you can also mount a host directory. There is of course little point doing this in a user program, as you would just use stdio and the facilities of the host operating system directly, But it is a development tool. Whilst developing the program you set the BBX_FileSystem object to BBX_FS_ANSI mode, and it use the host directory. Any you've all the facilities of the host machine for editing that folder. Then when the program is near release, and you have settled on the resource files, you convert to a FileSystem XML file using the BabyXFS tool babyxfs_dirtoxml, and switch the object to BBX_FS_STRING mode.

The functions

These are the functions in the library.


    //
    //  bbx_filesystem.h
    //  babyxfs
    //
    //  Created by Malcolm McLean on 31/05/2024.
    //

    #ifndef bbx_filesystem_h
    #define bbx_filesystem_h

    #define BBX_FS_STDIO 1
    #define BBX_FS_STRING 2

    typedef struct bbx_filesystem BBX_FileSystem;

    BBX_FileSystem *bbx_filesystem(void);
    void bbx_filesystem_kill(BBX_FileSystem *bbx_fs);
    int bbx_filesystem_set(BBX_FileSystem *bbx_fs, const char *pathorxml, int mode);
    FILE *bbx_filesystem_fopen(BBX_FileSystem *bbx_fs, const char *path, const char *mode);
    int bbx_filesystem_fclose(BBX_FileSystem *bbx_fs, FILE *fp);
    char *bbx_filesystem_slurp(BBX_FileSystem *bbx_fs, const char *path, const char *mode);
    unsigned char *bbx_filesystem_slurpb(BBX_FileSystem *bbx_fs, const char *path, const char *mode, int *N);
    int bbx_filesystem_unlink(BBX_FileSystem *bbx_fs, const char *path);
    const char *bbx_filesystem_getname(BBX_FileSystem *bbx_fs);
    int bbx_filesystem_setreadir(BBX_FileSystem *bbx_fs, char **(*fptr)(const char *path, void *ptr), void *ptr);
    int bbx_filesystem_dump(BBX_FileSystem *bbx_fs, FILE *fp);
    char **bbx_filesystem_mkdir(BBX_FileSystem *bbx_fs, const char *path);
    char **bbx_filesystem_rmdir(BBX_FileSystem *bbx_fs, const char *path);
    char **bbx_filesystem_list(BBX_FileSystem *bbx_fs, const char *path);

    #endif /* bbx_filesystem_h */