Skip to content
slaeshjag edited this page Mar 25, 2013 · 13 revisions

libDarnit uses a few formats not found anywhere else. There's mostly no reason for this other than "why not." Support tools for working with them are mostly available though.

LDI

A LDI file "libDarnit Image" is a file container clumping multiple files together into one. It is mainly to reduce clutter without needing massive directory hierarchies. Like zip, an LDI can be opened even if it's appended to another file (that isn't a LDI) since the necessary info about it is also located at the end of the file.

To access a file inside an LDI, you need to mount the LDI. This adds all the files in the LDI to the VFS that darnit-filesystem looks in when you try to open a file. All functions except the dynlib functions can trasparently access files in mounted LDI files.

Creating a LDI file

To create a LDI file, it is recommended that you use the with libDarnit provided utility called darnit-fsimage. It adds all the files in a directory to a LDI. Inside the LDI, the file appear under the directory you added them from.

For example, if you run darnit-fsimage directory directory.ldi, the file directory.ldi will be created containing the files in directory. If you have a file called file1.blargh inside directory, after that you mount directory.ldi, you can open it by calling d_file_open with directory/file1.blargh as fname.

LDI file format

All integers in the LDI file is stored in big endian. Here is a figure showing the structure of a LDI file.

Structure of a LDI file

typedef struct {
        unsigned int                    magic;
        unsigned int                    version;
        unsigned int                    files;
} FILESYSTEM_IMG_HEADER;

This is the main header, it's located at the start of the file.

  • magic - The magic number for LDI files is 0x83B3661B
  • version - The version for the currently implemented LDI specification is 0xBBA77ABC
  • files - The number of files contained in the LDI file

However, LDI files can also be appended to other files and still be perfectly mountable. Therefore, at the end of every LDI file, the following struct is present.

typedef struct {
        unsigned int                    file_size;
        unsigned int                    magic;
} FILESYSTEM_IMG_END;
  • file_size - Size of the LDI image file including all headers but this one
  • magic - Same magic number as in the man header

Clone this wiki locally