File system mounting functions

mount() function

The mount() function is intended for mounting file systems. When using this function in KasperskyOS, it is important to consider the following details regarding its implementation:

In KasperskyOS, operations with file systems and the network are executed via a separate system program that implements a virtual file system (VFS). By default, the VFS program is not mapped to a program implementing a block device. To bind a process of the utilized virtual file system with the required block device, use the blkdev::entity_REPLACEMENT property of the set_target_properties function in the CMakeLists.txt file for building the Einit program. Possible values for the blkdev::entity_REPLACEMENT property (implementations of block devices):

The mount() function is declared in the header file sysroot-*-kos/include/sys/mount.h from the KasperskyOS SDK:

int mount(const char *source, const char *target,

const char *filesystemtype, unsigned long mountflags,

const void *data);

Function parameters:

Returns 0 if successful, otherwise returns –1. If an error occurs, the errno variable is set to a value indicating the cause of the error. The possible values of errno match the standard values defined in the libc library.

umount() function

This function is intended for unmounting file systems and is declared in the header file sysroot-*-kos/include/sys/mount.h from the KasperskyOS SDK:

int umount(const char *target);

Function parameters:

Returns 0 if successful, otherwise returns –1. If an error occurs, the errno variable is set to a value indicating the cause of the error. The possible values of errno match the standard values defined in the libc library.

Example function call:

#include <sys/mount.h>

int main(void)

{

// Create directory /c and specify

// the access rights for all users

if (mkdir("/c", S_IRWXU | S_IRWXG | S_IRWXO)) {

fprintf(stderr, "Failed to create dir\n");

return -1;

}

// Mount the ext2 file system from block device Ahci0Port0,0

// to directory /c using standard mount flags

// and without additional data

if (mount("Ahci0Port0,0", "/c", "ext2", 0, "")) {

fprintf(stderr, "Failed to mount 'ext2'\n");

return -1;

}

// Create directory /c/ram and specify

// the access rights for all users

if (mkdir("/c/ram", S_IRWXU | S_IRWXG | S_IRWXO) != 0)

{

printf("Failed to create \"/c/ram\" dir\n");

return EXIT_FAILURE;

}

// Mount the ramfs file system to directory /c/ram

// using standard mount flags

// and without additional data

if (mount("nodev", "/c/ram", "ramfs", 0, "") != 0)

{

printf("Failed to mount ramfs, /c/ram (error %d: \"%s\")\n",

errno,

strerror(errno));

return EXIT_FAILURE;

}

// ...

// Unmount the file system from directory /c/ram

if (umount("/c/ram")) {

fprintf(stderr, "Failed to umount 'ramfs'\n");

return -1;

}

return 0;

}

For other ways to mount file systems, see the section titled Mounting file systems when VFS starts.

Page top