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:
EACCES error in the IPC response.auto is available for mounting a file system that supports automatic mounting.libc library.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):
ramdisk_entity – RAM disk that reads the ramdisk<N>.img files from ROMFS and provides them as the ramdisk<N> file systems, where N is a positive integer.sdcard_ENTITY – SD card driver (MMC).ata_ENTITY – AHCI driver (ATA)."" (empty string) – interaction between the block device and the virtual file system is not required.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:
sourceMount source: device or virtual object (dummy). Supported formats:
device_name>[_p<volume_number>] – full name of the device. PARTLABEL=<label>, where label refers to the GPT (Globally Unique Identifier Partition Table) partition label.PARTUUID=<uuid>, where uuid refers to the GPT partition GUID.When mounting file systems that do not require a physical device (for example, ROMFS, ramfs, devfs), the source parameter is ignored.
targetDirectory in which the file system will be mounted. This directory must be created before the mount() function is called.
filesystemtypeType of file system. Permissible values:
romfs – read-only file system.ramfs – file system that runs in RAM. Used by default for the root file system.devfs – virtual file system for device management. Supported devices:log – equivalent of /dev/log for system logging.null – equivalent of /dev/null for redirecting and ignoring output.urandom – equivalent of /dev/random for generating pseudorandom numbers.bpf, npf, tun0/1/2/3 – network devices for working with network interfaces and filters.fat12, fat16, fat32, vfat – file systems of the FAT family. One implementation for the entire family.ext, ext2, ext3, ext4 – file systems of the ext family. One implementation for the entire family.ffs – file system used in NetBSD.auto – automatic mounting of the first file system from the list of registered file systems that satisfies the following conditions: requires a device and may be mounted automatically (for example, fat32, ext and ffs).mountflagsMount flags. Available values:
MS_RDONLY – mount the file system in read-only mode.MS_STRICTATIME – always update the last access time of files when their contents are changed.MS_SYNCHRONOUS – synchronous write to the file system.dataAdditional data for mountable file systems. Empty string, or NULL if the parameter does not have to be specified. The following values are permissible for the file systems of the ext family:
expand – expand the file system over the entire available space of the volume if this is permitted by the partition structure.check – initiate full auto-recovery of the file system when mounting.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:
targetDirectory from which the file system will be unmounted.
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