QTools 6.9.3
QFSGen ROM File-System Generator

QFSGen is a cross-platform, command-line utility that generates a ROM-based file system, which can be incorporated in a C source code. Specifically, QFSGen utility generates a C header file that contains a bunch of constant byte arrays representing your files and directories. This generated header file (named fsdata.h by default) can be subsequently included in the ROM-Based File System implementation.

QFSGen is deployed as natively compiled executable and is located in the sub-directory qtools/bin/. QFSGen is available in portable source code and can be compiled on all desktop platforms (Windows and POSIX – Linux, macOS...).

Note
The main motivation for the QFSGen utility is to generate ROM-based file systems for embedded HTTP servers. However, the utility can be used for any ROM-based file systems.

QFSGen Usage

You use the QFSGen utility from command-prompt. First, change current directory to the directory, where you wish to generate the C header file (named fsdata.h by default) and type:

qfsgen website -h

where website is a directory, which contains the files and sub-directories you wish to include into your ROM-based file system. This particular QFSGen invocation will generate the file-system found in the directory website with HTTP headers (-h option).

Example run of the QFSGen utility

QFSGen Command-Line Parameters

QFSGen takes the following command-line parameters:

PARAMETER DEFAULT COMMENT
fs-dir file system directory (relative or absolute)
[output-flie] fsdata.h output file name (optional)
OPTIONS    
-h   generate HTTP headers

How QFSGen Works

QFSGen recursively scans the provided directory and recursively encodes any file and sub-directory into an array in the generated header file. For example, here is the content of the website directory:

+-website/
  +-img/
  | +-AN_QP_and_lwIP.jpg
  | +-arrow.gif
  | +-favicon.ico
  | +-footer.jpg
  | +-logo_lwip_qp.jpg
  | +-logo_ql.jpg
  | +-logo_sics.gif
  | +-PSiCC2.gif
  | +-QP_datasheet.gif
  +-404.htm
  +-bg_footer.gif
  +-cgi_demo.htm
  +-index.htm
  +-ssi_demo.shtm
  +-style.css
  +-thank_you.htm
  +-udp_demo.htm

This directory structure is then encoded into the following header file fsdata.h:

/* This file has been generated with the qfsgen utility. */
/* /404.htm */
static unsigned char const data_404_htm[] = {
/* name: */
0x2F, 0x34, 0x30, 0x34, 0x2E, 0x68, 0x74, 0x6D, 0x00,
/* HTTP header: */
0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x30, 0x20, 0x34,
. . .
0x6D, 0x6C, 0x0D, 0x0A, 0x0D, 0x0A,
/* data: */
0x3C, 0x21, 0x44, 0x4F, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20,
0x68, 0x74, 0x6D, 0x6C, 0x3E, 0x0A
};
struct fsdata_file const file_404_htm[] = {
{
(struct fsdata_file *)0,
data_404_htm,
data_404_htm + 9,
sizeof(data_404_htm) - 9
}
};
/* /thank_you.htm */
static unsigned char const data_thank_you_htm[] = {
/* name: */
0x2F, 0x74, 0x68, 0x61, 0x6E, 0x6B, 0x5F, 0x79, 0x6F, 0x75,
0x2E, 0x68, 0x74, 0x6D, 0x00,
/* HTTP header: */
0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x30, 0x20, 0x32,
. . .
0x0D, 0x0A, 0x0D, 0x0A,
/* data: */
0x3C, 0x21, 0x44, 0x4F, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20,
0x4D, 0x4C, 0x3E, 0x0A
};
struct fsdata_file const file_thank_you_htm[] = {
{
file_style_css,
data_thank_you_htm,
data_thank_you_htm + 15,
sizeof(data_thank_you_htm) - 15
}
};
/* /udp_demo.htm */
static unsigned char const data_udp_demo_htm[] = {
/* name: */
0x2F, 0x75, 0x64, 0x70, 0x5F, 0x64, 0x65, 0x6D, 0x6F, 0x2E,
0x68, 0x74, 0x6D, 0x00,
/* HTTP header: */
0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x30, 0x20, 0x32,
. . .
0x0D, 0x0A, 0x0D, 0x0A,
/* data: */
0x3C, 0x21, 0x44, 0x4F, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20,
. . .
0x3E, 0x0A
};
struct fsdata_file const file_udp_demo_htm[] = {
{
file_thank_you_htm,
data_udp_demo_htm,
data_udp_demo_htm + 14,
sizeof(data_udp_demo_htm) - 14
}
};
#define FS_ROOT file_udp_demo_htm
#define FS_NUMFILES 17

Subsequently, the fsdata.h header file is included in the ROM file-system implementation file fs.c, which is included in the qfsgen/source directory.


Next: Revision History