The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
vfs_ops.c File Reference
#include "vfs.h"
#include "kernel/errno.h"
#include "common/string.h"

Functions

kerr_t vfs_open (const char *path, vfs_file_t *file)
 open a file or directory by absolute path in the virtual file system.
kerr_t vfs_create (const char *path)
 create a regular file by absolute path.
kerr_t vfs_mkdir (const char *path)
 create a directory by absolute path.
kerr_t vfs_remove (const char *path)
 remove a file by absolute path.
kerr_t vfs_rmdir (const char *path)
 remove a directory by absolute path.
kerr_t vfs_rename (const char *old_path, const char *new_path)
 rename a file or directory by absolute paths.
kerr_t vfs_stat (const char *path, vfs_stat_t *stat_out)
 stat a file or directory by absolute path.
uint32_t vfs_read (vfs_file_t *file, uint32_t size, void *buffer)
 read data from an open file in the virtual file system.
uint32_t vfs_write (vfs_file_t *file, uint32_t size, const void *buffer)
 write data to an open file in the virtual file system.
kerr_t vfs_truncate (vfs_file_t *file, uint64_t length)
 cut or grow an open file to length bytes (growth reads as zeros).
kerr_t vfs_read_entry (vfs_file_t *file, fs_dirent_t *entryOut)
 read a directory entry from an open directory in the virtual file system.
void vfs_close (vfs_file_t *file)
 close an open file in the virtual file system.
uint8_t vfs_file_type (vfs_file_t *file)
 get the type of an open file in the virtual file system.
int32_t vfs_ioctl (vfs_file_t *file, uint32_t request, void *arg)
 issue a device-control (ioctl) request on an open file.
int32_t vfs_mmap (vfs_file_t *file, addr_space_t as, uintptr_t virt, size_t length, int prot, uint64_t offset)
 map an open file's memory into a process address space.
int64_t vfs_lseek (vfs_file_t *file, int64_t offset, int whence)
 move an open file's offset, as lseek does: through the filesystem's own seek op if it has one (devfs), else the ext2 file cursor.
void vfs_seek_end (vfs_file_t *file)
 move an open file's offset to its end (O_APPEND writes).
kerr_t vfs_fstat (vfs_file_t *file, vfs_stat_t *stat_out)
 stat an open file or directory.
kerr_t vfs_setattr (const char *path, const fs_attr_t *attr)
 change the permission bits and/or owner of a file by path, or of an open file.
kerr_t vfs_fsetattr (vfs_file_t *file, const fs_attr_t *attr)

Function Documentation

◆ vfs_open()

kerr_t vfs_open ( const char * path,
vfs_file_t * file )

open a file or directory by absolute path in the virtual file system.

Parameters
pathabsolute path to the file or directory.
filepointer to a vfs_file_t structure that will be initialized with the opened file
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_create()

kerr_t vfs_create ( const char * path)

create a regular file by absolute path.

Parameters
pathabsolute path to the new file.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_mkdir()

kerr_t vfs_mkdir ( const char * path)

create a directory by absolute path.

Parameters
pathabsolute path to the new directory.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_remove()

kerr_t vfs_remove ( const char * path)

remove a file by absolute path.

Parameters
pathabsolute path to the file to remove.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_rmdir()

kerr_t vfs_rmdir ( const char * path)

remove a directory by absolute path.

Parameters
pathabsolute path to the directory to remove.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_rename()

kerr_t vfs_rename ( const char * old_path,
const char * new_path )

rename a file or directory by absolute paths.

Parameters
old_pathabsolute path to the existing file or directory.
new_pathabsolute path to the new name for the file or directory.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_stat()

kerr_t vfs_stat ( const char * path,
vfs_stat_t * stat_out )

stat a file or directory by absolute path.

Parameters
pathabsolute path to the file or directory.
stat_outpointer to a vfs_stat_t structure that will be filled with the file's metadata.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_read()

uint32_t vfs_read ( vfs_file_t * file,
uint32_t size,
void * buffer )

read data from an open file in the virtual file system.

Parameters
filepointer to the vfs_file_t structure representing the open file.
sizenumber of bytes to read.
bufferpointer to the buffer where the read data will be stored.
Returns
number of bytes actually read, or 0 on failure.

◆ vfs_write()

uint32_t vfs_write ( vfs_file_t * file,
uint32_t size,
const void * buffer )

write data to an open file in the virtual file system.

Parameters
filepointer to the vfs_file_t structure representing the open file.
sizenumber of bytes to write.
bufferpointer to the source data.
Returns
number of bytes actually written, or 0 on failure.

◆ vfs_truncate()

kerr_t vfs_truncate ( vfs_file_t * file,
uint64_t length )

cut or grow an open file to length bytes (growth reads as zeros).

Returns
KERR_OK on success, or an error code on failure.

◆ vfs_read_entry()

kerr_t vfs_read_entry ( vfs_file_t * file,
fs_dirent_t * entryOut )

read a directory entry from an open directory in the virtual file system.

Parameters
filepointer to the vfs_file_t structure representing the open directory.
entryOutpointer to output directory entry.
Returns
KERR_OK on success, or an error code on failure.

◆ vfs_close()

void vfs_close ( vfs_file_t * file)

close an open file in the virtual file system.

Parameters
filepointer to the vfs_file_t structure representing the open file.
Returns
void

◆ vfs_file_type()

uint8_t vfs_file_type ( vfs_file_t * file)

get the type of an open file in the virtual file system.

Parameters
filepointer to the vfs_file_t structure representing the open file.
Returns
file type (FS_TYPE_FILE, FS_TYPE_DIR, or FS_TYPE_UNKNOWN).

◆ vfs_ioctl()

int32_t vfs_ioctl ( vfs_file_t * file,
uint32_t request,
void * arg )

issue a device-control (ioctl) request on an open file.

dispatches through the backing filesystem; only special filesystems (devfs) implement it, forwarding to the device. others return -ENOTTY.

Parameters
filepointer to the vfs_file_t representing the open file.
requestdriver-defined request code.
argrequest-specific argument (typically a bounds-checked pointer).
Returns
0 on success, or a negative errno on failure.

◆ vfs_mmap()

int32_t vfs_mmap ( vfs_file_t * file,
addr_space_t as,
uintptr_t virt,
size_t length,
int prot,
uint64_t offset )

map an open file's memory into a process address space.

dispatches through the backing filesystem; only device nodes (devfs) that forward to a mappable device succeed. others return -ENODEV.

Parameters
filepointer to the vfs_file_t representing the open file.
page_directoryphysical address of the target process page directory.
virtpage-aligned destination virtual address.
lengthbytes to map (page-multiple).
protPROT_* bits.
offsetpage-aligned byte offset into the mapped object.
Returns
0 on success, or a negative errno on failure.

◆ vfs_lseek()

int64_t vfs_lseek ( vfs_file_t * file,
int64_t offset,
int whence )

move an open file's offset, as lseek does: through the filesystem's own seek op if it has one (devfs), else the ext2 file cursor.

Parameters
filethe open file.
offsetbytes relative to whence.
whenceVFS_SEEK_SET, VFS_SEEK_CUR or VFS_SEEK_END.
Returns
the new offset, or a negative errno (EINVAL for a bad whence or a negative result).

◆ vfs_seek_end()

void vfs_seek_end ( vfs_file_t * file)

move an open file's offset to its end (O_APPEND writes).

Parameters
filethe open file.

◆ vfs_fstat()

kerr_t vfs_fstat ( vfs_file_t * file,
vfs_stat_t * stat_out )

stat an open file or directory.

Parameters
filethe open file.
stat_outreceives its metadata.
Returns
KERR_OK, or an error code.

◆ vfs_setattr()

kerr_t vfs_setattr ( const char * path,
const fs_attr_t * attr )

change the permission bits and/or owner of a file by path, or of an open file.

Returns
KERR_OK, KERR_PERM if the filesystem keeps no owners, or the error of opening the path.

◆ vfs_fsetattr()

kerr_t vfs_fsetattr ( vfs_file_t * file,
const fs_attr_t * attr )