Using the ROMFS file system (romfs.h)

The API is defined in the header file sysroot-*-kos/include/kos/romfs.h from the KasperskyOS SDK.

The API is designed to work with ROMFS file systems, which includes the ROMFS image supplied as part of the KasperskyOS kernel image and the ROMFS image placed in memory by the bootloader (similar to initrd in Linux). The mechanism that implements the API does not use VFS.

The input data and output data of some API functions are associated with blobs because the romfs.h API implementation uses the blob_api.h API, which is designed to gain access to named blobs.

Information about API functions is provided in the table below.

Mounting a ROMFS image

To mount a ROMFS image, call the KosRomFsMount() or KosRomFsMountByHandle() function.

You must use the romFsName parameter of the KosRomFsMount() or KosRomFsMountByHandle() function to specify an arbitrary mount point name whose size must not exceed the value of the KOS_ROMFS_MAX_NAME constant (not counting the terminating zero). In one process, each mount point must have a unique name.

You must use the blobName parameter of the KosRomFsMount() function to specify the name of the blob containing the required ROMFS image: romfs.0 or romfs.1. In the first case, the ROMFS image will be mounted from the kernel image. In the second case, the ROMFS image that was placed in memory by the bootloader will be mounted.

In the blob parameter of the KosRomFsMountByHandle() function, you must specify the handle of the blob containing the required ROMFS image. This handle must be obtained by calling the KnBlobGet() function from the blob_api.h API. You must use the name parameter of the KnBlobGet() function to define the name of the blob containing the required ROMFS image: romfs.0 or romfs.1 (similar to the blobName parameter of the KosRomFsMount() function). After mounting, you can close the handle of the blob.

The KosRomFsMount() and KosRomFsMountByHandle() functions mount only in the calling process. The same ROMFS image can have several simultaneously existing mount points that were created by calls of the KosRomFsMount() or KosRomFsMountByHandle() function in one or more processes.

Opening a file

To open a file, you must call the KosRomFsOpen() function while specifying a string in the format <mount point name>/<file name> via the path parameter.

The same file can have several simultaneously existing identifiers that were obtained by calling the KosRomFsOpen() function in one or more processes. In this case, operations with the file via different identifiers are performed without mutual influence.

Reading data from a file

To read data from a file, use the KosRomFsRead() function. This function reads a file starting from the defined offset relative to the beginning of the file.

Receiving information about a file

To get the file size, call the KosRomFsGetFileSize() function.

To obtain information that includes the file size, the unique ID of the file in ROMFS, and the SID for the blob containing the ROMFS image, call the KosRomFsGetFileStat() function.

Closing a file

To close the file, call the KosRomFsClose() function.

Unmounting a ROMFS image

To unmount a ROMFS image, call the KosRomFsUnmount() function.

To unmount all ROMFS images, call the KosRomFsUnmountAll() function.

The KosRomFsUnmount() and KosRomFsUnmountAll() functions unmount only in the calling process.

A file that is open when the ROMFS image is unmounted remains available for operations until it is closed.

Information about API functions

Romfs.h functions

Function

Information about the function

KosRomFsMount()

Purpose

Mounts a ROMFS image.

Parameters

  • [in] romFsName – pointer to the name of the mount point.
  • [in] blobName – pointer to the name of the blob containing the ROMFS image.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsMountByHandle()

Purpose

Mounts a ROMFS image.

Parameters

  • [in] romFsName – pointer to the name of the mount point.
  • [in] blob – handle of the blob containing the ROMFS image.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsUnmount()

Purpose

Unmounts a ROMFS image.

Parameters

  • [in] romFsName – pointer to the name of the mount point.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsUnmountAll()

Purpose

Unmounts all ROMFS images.

Parameters

N/A

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsOpen()

Purpose

Opens a file.

Parameters

  • [in] path – pointer to a string in the format <mount point name>/<file name>.
  • [out] file – pointer to the file ID.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsClose()

Purpose

Closes a file.

Parameters

  • [in] file – file ID.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsRead()

Purpose

Reads data from a file, starting from the defined offset.

Parameters

  • [in] file – file ID.
  • [in] offset – offset (relative to the beginning of the file) from which reading should start, in bytes.
  • [out] buf – pointer to the data read buffer.
  • [in] bufSize – size of the buffer defined via the buf parameter, in bytes.
  • [out] read – actual size of the read data in bytes.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsGetFileSize()

Purpose

Gets the size of a file.

Parameters

  • [in] file – file ID.
  • [out] size – pointer to the file size (in bytes).

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

KosRomFsGetFileStat()

Purpose

Gets information about the file.

Parameters

  • [in] file – file ID.
  • [out] stat – pointer to the structure containing the file size in bytes, the unique file identifier in ROMFS, and the SID for the blob containing the ROMFS image.

Returned values

If successful, the function returns rcOk, otherwise it returns an error code.

Page top