PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
Virtual File System

Virtual File System. More...

Collaboration diagram for Virtual File System:

Detailed Description

Virtual File System.

The Virtual File System (VFS) provides a single unified interface for any and all filesystems, including virtual filesystems used to expose kernel resources to user space.

Todo:
Most of this is going to be removed when the new IRP system is fully implemented, but for now its usefull to keep it around during the refactor.

Macros

#define BUFFER_READ(buffer, count, offset, src, size)
 Helper macros for implementing file operations dealing with simple buffers.
 
#define BUFFER_WRITE(buffer, count, offset, dest, size)
 Helper macro for implementing file operations dealing with simple buffer writes.
 

Functions

file_tvfs_open (const pathname_t *pathname, process_t *process)
 Open a file.
 
uint64_t vfs_open2 (const pathname_t *pathname, file_t *files[2], process_t *process)
 Open one file, returning two file handles.
 
file_tvfs_openat (const path_t *from, const pathname_t *pathname, process_t *process)
 Open a file relative to another path.
 
size_t vfs_read (file_t *file, void *buffer, size_t count)
 Read from a file.
 
size_t vfs_write (file_t *file, const void *buffer, size_t count)
 Write to a file.
 
size_t vfs_seek (file_t *file, ssize_t offset, seek_origin_t origin)
 Seek in a file.
 
uint64_t vfs_ioctl (file_t *file, uint64_t request, void *argp, size_t size)
 Perform an ioctl operation on a file.
 
void * vfs_mmap (file_t *file, void *address, size_t length, pml_flags_t flags)
 Memory map a file.
 
uint64_t vfs_poll (poll_file_t *files, uint64_t amount, clock_t timeout)
 Poll multiple files.
 
size_t vfs_getdents (file_t *file, dirent_t *buffer, size_t count)
 Get directory entries from a directory file.
 
uint64_t vfs_stat (const pathname_t *pathname, stat_t *buffer, process_t *process)
 Get file information.
 
uint64_t vfs_link (const pathname_t *oldPathname, const pathname_t *newPathname, process_t *process)
 Make the same file appear twice in the filesystem.
 
size_t vfs_readlink (vnode_t *symlink, char *buffer, size_t size)
 Read the path in a symbolic link.
 
uint64_t vfs_symlink (const pathname_t *target, const pathname_t *linkpath, process_t *process)
 Create a symbolic link.
 
uint64_t vfs_remove (const pathname_t *pathname, process_t *process)
 Remove a file or directory.
 
uint64_t vfs_id_get (void)
 Generates a new unique ID, to be used for any VFS object.
 

Macro Definition Documentation

◆ BUFFER_READ

#define BUFFER_READ (   buffer,
  count,
  offset,
  src,
  size 
)
Value:
({ \
size_t readCount = (*(offset) <= (size)) ? MIN((count), (size) - *(offset)) : 0; \
memcpy((buffer), (src) + *(offset), readCount); \
*(offset) += readCount; \
readCount; \
})
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
#define MIN(x, y)
Definition math.h:18
static uint64_t offset
Definition screen.c:19
static atomic_long count
Definition main.c:11

Helper macros for implementing file operations dealing with simple buffers.

Parameters
bufferThe destination buffer.
countThe number of bytes to read/write.
offsetA pointer to the current offset, will be updated.
srcThe source buffer.
sizeThe size of the source buffer.
Returns
The number of bytes read/written.

Definition at line 209 of file vfs.h.

◆ BUFFER_WRITE

#define BUFFER_WRITE (   buffer,
  count,
  offset,
  dest,
  size 
)
Value:
({ \
size_t writeCount = (*(offset) <= (size)) ? MIN((count), (size) - *(offset)) : 0; \
memcpy((dest) + *(offset), (buffer), writeCount); \
*(offset) += writeCount; \
writeCount; \
})

Helper macro for implementing file operations dealing with simple buffer writes.

Parameters
bufferThe destination buffer.
countThe number of bytes to write.
offsetA pointer to the current offset, will be updated.
destThe destination buffer.
sizeThe size of the destination buffer.
Returns
The number of bytes written.

Definition at line 227 of file vfs.h.

Function Documentation

◆ vfs_open()

file_t * vfs_open ( const pathname_t pathname,
process_t process 
)

Open a file.

Parameters
pathnameThe pathname of the file to open.
processThe process opening the file.
Returns
On success, the opened file. On failure, returns NULL and errno is set.

Definition at line 156 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_open2()

uint64_t vfs_open2 ( const pathname_t pathname,
file_t files[2],
process_t process 
)

Open one file, returning two file handles.

Used primarily to implement pipes.

Parameters
pathnameThe pathname of the file to open.
filesThe output array of two file pointers.
processThe process opening the file.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 167 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_openat()

file_t * vfs_openat ( const path_t from,
const pathname_t pathname,
process_t process 
)

Open a file relative to another path.

Parameters
fromThe path to open the file relative to, or NULL to use the process's current working directory.
pathnameThe pathname of the file to open.
processThe process opening the file.
Returns
On success, the opened file. On failure, returns NULL and errno is set.

Definition at line 223 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_read()

size_t vfs_read ( file_t file,
void *  buffer,
size_t  count 
)

Read from a file.

Follows POSIX semantics.

Parameters
fileThe file to read from.
bufferThe buffer to read into.
countThe number of bytes to read.
Returns
On success, the number of bytes read. On failure, ERR and errno is set.

Definition at line 279 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_write()

size_t vfs_write ( file_t file,
const void *  buffer,
size_t  count 
)

Write to a file.

Follows POSIX semantics.

Parameters
fileThe file to write to.
bufferThe buffer to write from.
countThe number of bytes to write.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 313 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_seek()

size_t vfs_seek ( file_t file,
ssize_t  offset,
seek_origin_t  origin 
)

Seek in a file.

Follows POSIX semantics.

Parameters
fileThe file to seek in.
offsetThe offset to seek to.
originThe origin to seek from.
Returns
On success, the new file position. On failure, ERR and errno is set.

Definition at line 355 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_ioctl()

uint64_t vfs_ioctl ( file_t file,
uint64_t  request,
void *  argp,
size_t  size 
)

Perform an ioctl operation on a file.

Parameters
fileThe file to perform the ioctl on.
requestThe ioctl request.
argpThe argument pointer.
sizeThe size of the argument.
Returns
On success, the result of the ioctl. On failure, ERR and errno is set.

Definition at line 373 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_mmap()

void * vfs_mmap ( file_t file,
void *  address,
size_t  length,
pml_flags_t  flags 
)

Memory map a file.

Parameters
fileThe file to memory map.
addressThe address to map to, or NULL to let the kernel choose.
lengthThe length to map.
flagsThe page table flags for the mapping.
Returns
On success, the mapped address. On failure, returns NULL and errno is set.

Definition at line 397 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_poll()

uint64_t vfs_poll ( poll_file_t files,
uint64_t  amount,
clock_t  timeout 
)

Poll multiple files.

Parameters
filesThe array of files to poll.
amountThe number of files in the array.
timeoutThe timeout in clock ticks, or CLOCKS_NEVER to wait indefinitely.
Returns
On success, the number of files that are ready. On failure, ERR and errno is set.

Definition at line 503 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_getdents()

size_t vfs_getdents ( file_t file,
dirent_t buffer,
size_t  count 
)

Get directory entries from a directory file.

Parameters
fileThe directory file to read from.
bufferThe buffer to read into.
countThe number of bytes to read.
Returns
On success, the number of bytes read. On failure, ERR and errno is set.

Definition at line 845 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_stat()

uint64_t vfs_stat ( const pathname_t pathname,
stat_t buffer,
process_t process 
)

Get file information.

Parameters
pathnameThe pathname of the file to get information about.
bufferThe buffer to store the file information in.
processThe process performing the stat.
Returns
On success, 0. On failure, ERR and errno is set.
Todo:
Reimplement this after the async system.

Definition at line 925 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_link()

uint64_t vfs_link ( const pathname_t oldPathname,
const pathname_t newPathname,
process_t process 
)

Make the same file appear twice in the filesystem.

Parameters
oldPathnameThe existing file.
newPathnameThe new link to create, must not exist and be in the same filesystem as the oldPathname.
processThe process performing the linking.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 991 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_readlink()

size_t vfs_readlink ( vnode_t symlink,
char *  buffer,
size_t  size 
)

Read the path in a symbolic link.

Parameters
symlinkThe symbolic link vnode.
bufferThe buffer to store the path in.
sizeThe size of the buffer.
processThe process performing the readlink.
Returns
On success, the number of bytes read. On failure, ERR and errno is set.

Definition at line 1080 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_symlink()

uint64_t vfs_symlink ( const pathname_t target,
const pathname_t linkpath,
process_t process 
)

Create a symbolic link.

Parameters
targetThe pathname to which the symbolic link will point.
linkpathThe pathname of the symbolic link to create.
processThe process performing the symlink creation.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 1104 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_remove()

uint64_t vfs_remove ( const pathname_t pathname,
process_t process 
)

Remove a file or directory.

Parameters
pathnameThe pathname of the file or directory to remove.
processThe process performing the removal.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 1160 of file vfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vfs_id_get()

uint64_t vfs_id_get ( void  )

Generates a new unique ID, to be used for any VFS object.

Returns
A new unique ID.

Definition at line 1236 of file vfs.c.

Here is the caller graph for this function: