PatchworkOS  966e257
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.

Macros

#define VFS_ROOT_ENTRY_NAME   "__root__"
 The name of the root entry.
 
#define VFS_DEVICE_NAME_NONE   "__no_device__"
 The name used to indicate no device.
 
#define BUFFER_READ(buffer, count, offset, src, size)
 Helper macros for implementing file operations dealing with simple buffers.
 
#define BUFFER_WRITE(buffer, count, offset, src, 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.
 
uint64_t vfs_read (file_t *file, void *buffer, uint64_t count)
 Read from a file.
 
uint64_t vfs_write (file_t *file, const void *buffer, uint64_t count)
 Write to a file.
 
uint64_t vfs_seek (file_t *file, int64_t offset, seek_origin_t origin)
 Seek in a file.
 
uint64_t vfs_ioctl (file_t *file, uint64_t request, void *argp, uint64_t size)
 Perform an ioctl operation on a file.
 
void * vfs_mmap (file_t *file, void *address, uint64_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.
 
uint64_t vfs_getdents (file_t *file, dirent_t *buffer, uint64_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.
 
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

◆ VFS_ROOT_ENTRY_NAME

#define VFS_ROOT_ENTRY_NAME   "__root__"

The name of the root entry.

Definition at line 32 of file vfs.h.

◆ VFS_DEVICE_NAME_NONE

#define VFS_DEVICE_NAME_NONE   "__no_device__"

The name used to indicate no device.

Definition at line 37 of file vfs.h.

◆ BUFFER_READ

#define BUFFER_READ (   buffer,
  count,
  offset,
  src,
  size 
)
Value:
({ \
uint64_t readCount = (*(offset) <= (size)) ? MIN((count), (size) - *(offset)) : 0; \
memcpy((buffer), (src) + *(offset), readCount); \
*(offset) += readCount; \
readCount; \
})
#define MIN(x, y)
Definition math.h:16
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static atomic_long count
Definition main.c:10
__UINT64_TYPE__ uint64_t
Definition stdint.h:17

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 194 of file vfs.h.

◆ BUFFER_WRITE

#define BUFFER_WRITE (   buffer,
  count,
  offset,
  src,
  size 
)
Value:
({ \
uint64_t writeCount = (*(offset) <= (size)) ? MIN((count), (size) - *(offset)) : 0; \
memcpy((buffer) + *(offset), (src), 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.
srcThe source buffer.
sizeThe size of the source buffer.
Returns
The number of bytes written.

Definition at line 212 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 94 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 108 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.
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 158 of file vfs.c.

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

◆ vfs_read()

uint64_t vfs_read ( file_t file,
void *  buffer,
uint64_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 200 of file vfs.c.

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

◆ vfs_write()

uint64_t vfs_write ( file_t file,
const void *  buffer,
uint64_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 239 of file vfs.c.

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

◆ vfs_seek()

uint64_t vfs_seek ( file_t file,
int64_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 286 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,
uint64_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 304 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,
uint64_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 333 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 440 of file vfs.c.

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

◆ vfs_getdents()

uint64_t vfs_getdents ( file_t file,
dirent_t buffer,
uint64_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 515 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.

Definition at line 556 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 609 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 698 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 765 of file vfs.c.

Here is the caller graph for this function: