You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Details:
Takes a filename as input, checks if the file exists, and removes it.
openfile
Purpose:
Opens a file and creates an EmulatedFile object with a specified filesize.
Details:
Used to open files for reading and writing, with options for file creation.
openmetadata
Purpose:
Opens a file to access its metadata and returns an EmulatedFile object.
Details:
Retrieves the file size and relevant metadata upon opening.
pathexists
Purpose:
Checks if a given file path exists.
Details:
Returns a boolean indicating whether the file path is valid.
EmulatedFile Struct
new
Purpose:
Creates a new EmulatedFile instance, opening a file and initializing its size.
Details:
Opens the file with read/write permissions and stores a Mutex<File>.
new_metadata
Purpose:
Creates an EmulatedFile instance by reading the file's metadata.
Details:
Retrieves file size and other metadata.
close
Purpose:
Closes the EmulatedFile.
Details:
Ensures resources are released after file operations.
shrink
Purpose:
Shrinks the file size to the specified length.
Details:
Reduces the file length and updates the filesize field.
fdatasync
Purpose:
Syncs data to disk without syncing file metadata.
Details:
Uses sync_data() to ensure file data is written to disk.
fsync
Purpose:
Syncs both file data and metadata to disk.
Details:
Ensures full synchronization of file contents.
sync_file_range
Purpose:
Syncs a specified file range to disk.
Details:
Allows syncing a portion of the file's data based on offset, bytes, and flags.
readat
Purpose:
Reads data from a file at a specified offset.
Details:
Populates a C-buffer with data read from the file.
writeat
Purpose:
Writes data to a file at a specified offset.
Details:
Takes data from a C-buffer and writes it to the file.
readfile_to_new_bytes
Purpose:
Reads the entire file into a byte vector.
Details:
Useful for reading a file's full content into memory.
writefile_from_bytes
Purpose:
Writes an entire byte vector to the file.
Details:
Replaces the file's content with new data from the byte buffer.
zerofill_at
Purpose:
Writes zeroes to the file starting at a specified offset.
Details:
Useful for initializing or overwriting portions of the file with zeros.
as_fd_handle_raw_int
Purpose:
Retrieves the file descriptor as an integer.
Details:
Returns the raw file descriptor from the file object.
EmulatedFileMap Struct
new
Purpose:
Creates a new EmulatedFileMap instance and maps a file into memory.
Details:
Maps 1MB of file space and reserves 8 bytes for tracking written data.
write_to_map
Purpose:
Writes data to the mapped region of the file.
Details:
Automatically extends the mapped memory if the data exceeds the current map size.
extend_map
Purpose:
Extends the memory-mapped region of the file by 1MB.
Details:
Resizes the map when more space is needed for logging or writing.
close_emulatedfilemap
Purpose:
Closes the memory-mapped file, unmaps the file, and releases resources.
Details:
Ensures the file is properly unmapped before closing.
mapfilenew
Purpose:
Creates a new memory-mapped file.
Details:
Opens the file and maps 1MB of space, preparing the file for logging or other operations.
Test Module
test_path_exists_true
Purpose:
Tests whether pathexists returns true for an existing file.
Details:
Uses a temporary file to verify the functionality of pathexists.
test_path_exists_false
Purpose:
Tests whether pathexists returns false for a non-existent file.
Details:
Verifies that the function behaves as expected when the file does not exist.
File: misc.rs
AdvisoryLock Struct
new
Purpose:
Initializes a new AdvisoryLock instance.
Details:
Creates a new mutex with a guard value of 0 (unlocked state) and a condition variable for managing locks.
lock_ex
Purpose:
Acquires an exclusive lock on the mutex.
Details:
Waits until the guard value is 0 (unlocked) before setting it to -1 to indicate that an exclusive lock is held.
lock_sh
Purpose:
Acquires a shared lock on the mutex.
Details:
Waits until no exclusive lock is held (guard value >= 0) and increments the guard value to indicate a shared lock is held.
try_lock_ex
Purpose:
Attempts to acquire an exclusive lock without blocking.
Details:
If the guard value is 0 (unlocked), it sets it to -1 and returns true. Otherwise, it returns false.
try_lock_sh
Purpose:
Attempts to acquire a shared lock without blocking.
Details:
If no exclusive lock is held (guard value >= 0), it increments the guard value and returns true. Otherwise, it returns false.
unlock
Purpose:
Releases the lock, whether shared or exclusive.
Details:
If a shared lock is held (guard value > 0), it decrements the guard value by 1. If no more shared locks are held (guard value becomes 0), it notifies a waiting writer.
If an exclusive lock is held (guard value -1), it sets the guard value to 0 and notifies all waiting readers and writers.
File: pipe.rs
new_pipe
Purpose:
Creates a new pipe with the specified buffer size.
Details:
Calls EmulatedPipe::new_with_capacity to initialize the pipe.
EmulatedPipe Struct
new_with_capacity
Purpose:
Initializes a new EmulatedPipe with a specified buffer size.
Details:
Uses a RingBuffer to split the buffer into a producer (write end) and consumer (read end).
set_eof
Purpose:
Marks the pipe as having reached the end-of-file (EOF).
Details:
Sets the eof flag to true, indicating no more data will be written to the pipe.
get_write_ref
Purpose:
Retrieves the current write reference count.
Details:
Returns the number of active write references on the pipe.
get_read_ref
Purpose:
Retrieves the current read reference count.
Details:
Returns the number of active read references on the pipe.
incr_ref
Purpose:
Increments the reference count for either read or write, based on flags.
Details:
Increases the reference count depending on whether the pipe is opened for reading (O_RDONLY) or writing (O_WRONLY).
decr_ref
Purpose:
Decrements the reference count for either read or write, based on flags.
Details:
Decreases the reference count depending on whether the pipe is closed for reading (O_RDONLY) or writing (O_WRONLY).
check_select_read
Purpose:
Checks whether the pipe is ready for reading.
Details:
Returns true if the pipe has data to be read or has reached EOF. Otherwise, it returns false.
check_select_write
Purpose:
Checks whether the pipe is ready for writing.
Details:
Returns true if there is available space in the pipe's write buffer.
write_to_pipe
Purpose:
Writes data to the pipe from a provided memory buffer.
Details:
Attempts to write length bytes into the pipe. If the pipe is full and non-blocking mode is enabled, it returns EAGAIN. If all read ends are closed, it returns EPIPE.
read_from_pipe
Purpose:
Reads data from the pipe into a provided memory buffer.
Details:
Reads up to length bytes. If non-blocking mode is enabled and no data is available, it returns EAGAIN. If EOF is reached, it returns 0.
Debug Implementation for EmulatedPipe
Purpose:
Provides a custom Debug implementation for the EmulatedPipe struct.
Details:
Displays the read/write reference counts and the EOF status.
File: types.rs
FSData Struct
Purpose:
Represents filesystem data, including information such as block size, total blocks, and free blocks.
Details:
This struct includes fields like f_bsize (block size) and f_blocks (total number of blocks), among others. It is designed to maintain compatibility with the stat and fstat system calls.
get_fdset
Purpose:
Retrieves a file descriptor set from the union argument.
Details:
Converts a raw pointer to an internal FdSet and returns a reference to it if valid. Otherwise, returns None.
get_statdatastruct
Purpose:
Retrieves a stat structure from the union argument.
Details:
Returns a mutable reference to a stat structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_fsdatastruct
Purpose:
Retrieves a statfs structure from the union argument.
Details:
Returns a mutable reference to a statfs structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_ioctlptrunion
Purpose:
Retrieves an IoctlPtrUnion from the union argument.
Details:
Returns the IoctlPtrUnion without any additional validation.
get_ioctl_int
Purpose:
Retrieves an integer from an IoctlPtrUnion.
Details:
Returns the integer value if the pointer is valid. Otherwise, returns an error indicating an invalid pointer.
get_ioctl_char
Purpose:
Retrieves a character (u8) from an IoctlPtrUnion.
Details:
Returns the character value if the pointer is valid. Otherwise, returns an error indicating an invalid pointer.
pack_dirents
Purpose:
Packs directory entries into a buffer.
Details:
Takes a vector of directory entries (ClippedDirent structs) and their associated names, and packs them into a buffer pointed to by baseptr. It assumes the names are null-terminated and padded to the next 8-byte boundary.
get_sockaddr
Purpose:
Retrieves a SockaddrDummy structure from the union argument.
Details:
Returns a mutable reference to a SockaddrDummy structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_epollevent
Purpose:
Retrieves an epoll_event structure from the union argument.
Details:
Returns a mutable reference to an epoll_event structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_itimerval
Purpose:
Retrieves an itimerval structure from the union argument.
Details:
Returns a mutable reference to an itimerval structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_constitimerval
Purpose:
Retrieves a constant itimerval structure from the union argument.
Details:
Returns a reference to an itimerval structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_sem
Purpose:
Retrieves a sem_t structure (semaphore) from the union argument.
Details:
Returns a mutable reference to a sem_t structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
get_ifaddrs
Purpose:
Retrieves an ifaddrs structure (network interface address) from the union argument.
Details:
Returns a mutable reference to an ifaddrs structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.
The text was updated successfully, but these errors were encountered:
Removing commented lines under /interface folder should be good for now. That would be great if @ChinmayShringi can put a draft on items need to be done here.
Removed Functions Documentation
Index of Removed Functions
File:
file.rs
: PR #53File:
misc.rs
: PR #54File:
pipe.rs
: PR #55File:
types.rs
: PR #56File:
file.rs
removefile
Deletes a file from the filesystem.
Takes a filename as input, checks if the file exists, and removes it.
openfile
Opens a file and creates an
EmulatedFile
object with a specified filesize.Used to open files for reading and writing, with options for file creation.
openmetadata
Opens a file to access its metadata and returns an
EmulatedFile
object.Retrieves the file size and relevant metadata upon opening.
pathexists
Checks if a given file path exists.
Returns a boolean indicating whether the file path is valid.
EmulatedFile Struct
new
Creates a new
EmulatedFile
instance, opening a file and initializing its size.Opens the file with read/write permissions and stores a
Mutex<File>
.new_metadata
Creates an
EmulatedFile
instance by reading the file's metadata.Retrieves file size and other metadata.
close
Closes the
EmulatedFile
.Ensures resources are released after file operations.
shrink
Shrinks the file size to the specified length.
Reduces the file length and updates the
filesize
field.fdatasync
Syncs data to disk without syncing file metadata.
Uses
sync_data()
to ensure file data is written to disk.fsync
Syncs both file data and metadata to disk.
Ensures full synchronization of file contents.
sync_file_range
Syncs a specified file range to disk.
Allows syncing a portion of the file's data based on offset, bytes, and flags.
readat
Reads data from a file at a specified offset.
Populates a C-buffer with data read from the file.
writeat
Writes data to a file at a specified offset.
Takes data from a C-buffer and writes it to the file.
readfile_to_new_bytes
Reads the entire file into a byte vector.
Useful for reading a file's full content into memory.
writefile_from_bytes
Writes an entire byte vector to the file.
Replaces the file's content with new data from the byte buffer.
zerofill_at
Writes zeroes to the file starting at a specified offset.
Useful for initializing or overwriting portions of the file with zeros.
as_fd_handle_raw_int
Retrieves the file descriptor as an integer.
Returns the raw file descriptor from the file object.
EmulatedFileMap Struct
new
Creates a new
EmulatedFileMap
instance and maps a file into memory.Maps 1MB of file space and reserves 8 bytes for tracking written data.
write_to_map
Writes data to the mapped region of the file.
Automatically extends the mapped memory if the data exceeds the current map size.
extend_map
Extends the memory-mapped region of the file by 1MB.
Resizes the map when more space is needed for logging or writing.
close_emulatedfilemap
Closes the memory-mapped file, unmaps the file, and releases resources.
Ensures the file is properly unmapped before closing.
mapfilenew
Creates a new memory-mapped file.
Opens the file and maps 1MB of space, preparing the file for logging or other operations.
Test Module
test_path_exists_true
Tests whether
pathexists
returnstrue
for an existing file.Uses a temporary file to verify the functionality of
pathexists
.test_path_exists_false
Tests whether
pathexists
returnsfalse
for a non-existent file.Verifies that the function behaves as expected when the file does not exist.
File:
misc.rs
AdvisoryLock Struct
new
Initializes a new
AdvisoryLock
instance.Creates a new mutex with a guard value of
0
(unlocked state) and a condition variable for managing locks.lock_ex
Acquires an exclusive lock on the mutex.
Waits until the guard value is
0
(unlocked) before setting it to-1
to indicate that an exclusive lock is held.lock_sh
Acquires a shared lock on the mutex.
Waits until no exclusive lock is held (guard value
>= 0
) and increments the guard value to indicate a shared lock is held.try_lock_ex
Attempts to acquire an exclusive lock without blocking.
If the guard value is
0
(unlocked), it sets it to-1
and returnstrue
. Otherwise, it returnsfalse
.try_lock_sh
Attempts to acquire a shared lock without blocking.
If no exclusive lock is held (guard value
>= 0
), it increments the guard value and returnstrue
. Otherwise, it returnsfalse
.unlock
Releases the lock, whether shared or exclusive.
> 0
), it decrements the guard value by 1. If no more shared locks are held (guard value becomes0
), it notifies a waiting writer.-1
), it sets the guard value to0
and notifies all waiting readers and writers.File:
pipe.rs
new_pipe
Creates a new pipe with the specified buffer size.
Calls
EmulatedPipe::new_with_capacity
to initialize the pipe.EmulatedPipe Struct
new_with_capacity
Initializes a new
EmulatedPipe
with a specified buffer size.Uses a
RingBuffer
to split the buffer into a producer (write end) and consumer (read end).set_eof
Marks the pipe as having reached the end-of-file (EOF).
Sets the
eof
flag totrue
, indicating no more data will be written to the pipe.get_write_ref
Retrieves the current write reference count.
Returns the number of active write references on the pipe.
get_read_ref
Retrieves the current read reference count.
Returns the number of active read references on the pipe.
incr_ref
Increments the reference count for either read or write, based on flags.
Increases the reference count depending on whether the pipe is opened for reading (
O_RDONLY
) or writing (O_WRONLY
).decr_ref
Decrements the reference count for either read or write, based on flags.
Decreases the reference count depending on whether the pipe is closed for reading (
O_RDONLY
) or writing (O_WRONLY
).check_select_read
Checks whether the pipe is ready for reading.
Returns
true
if the pipe has data to be read or has reached EOF. Otherwise, it returnsfalse
.check_select_write
Checks whether the pipe is ready for writing.
Returns
true
if there is available space in the pipe's write buffer.write_to_pipe
Writes data to the pipe from a provided memory buffer.
Attempts to write
length
bytes into the pipe. If the pipe is full and non-blocking mode is enabled, it returnsEAGAIN
. If all read ends are closed, it returnsEPIPE
.read_from_pipe
Reads data from the pipe into a provided memory buffer.
Reads up to
length
bytes. If non-blocking mode is enabled and no data is available, it returnsEAGAIN
. If EOF is reached, it returns0
.Debug Implementation for EmulatedPipe
Provides a custom
Debug
implementation for theEmulatedPipe
struct.Displays the read/write reference counts and the EOF status.
File:
types.rs
FSData Struct
Represents filesystem data, including information such as block size, total blocks, and free blocks.
This struct includes fields like
f_bsize
(block size) andf_blocks
(total number of blocks), among others. It is designed to maintain compatibility with thestat
andfstat
system calls.get_fdset
Retrieves a file descriptor set from the union argument.
Converts a raw pointer to an internal
FdSet
and returns a reference to it if valid. Otherwise, returnsNone
.get_statdatastruct
Retrieves a
stat
structure from the union argument.Returns a mutable reference to a
stat
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_fsdatastruct
Retrieves a
statfs
structure from the union argument.Returns a mutable reference to a
statfs
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_ioctlptrunion
Retrieves an
IoctlPtrUnion
from the union argument.Returns the
IoctlPtrUnion
without any additional validation.get_ioctl_int
Retrieves an integer from an
IoctlPtrUnion
.Returns the integer value if the pointer is valid. Otherwise, returns an error indicating an invalid pointer.
get_ioctl_char
Retrieves a character (u8) from an
IoctlPtrUnion
.Returns the character value if the pointer is valid. Otherwise, returns an error indicating an invalid pointer.
pack_dirents
Packs directory entries into a buffer.
Takes a vector of directory entries (
ClippedDirent
structs) and their associated names, and packs them into a buffer pointed to bybaseptr
. It assumes the names are null-terminated and padded to the next 8-byte boundary.get_sockaddr
Retrieves a
SockaddrDummy
structure from the union argument.Returns a mutable reference to a
SockaddrDummy
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_epollevent
Retrieves an
epoll_event
structure from the union argument.Returns a mutable reference to an
epoll_event
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_itimerval
Retrieves an
itimerval
structure from the union argument.Returns a mutable reference to an
itimerval
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_constitimerval
Retrieves a constant
itimerval
structure from the union argument.Returns a reference to an
itimerval
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_sem
Retrieves a
sem_t
structure (semaphore) from the union argument.Returns a mutable reference to a
sem_t
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.get_ifaddrs
Retrieves an
ifaddrs
structure (network interface address) from the union argument.Returns a mutable reference to an
ifaddrs
structure if the pointer is valid. Otherwise, returns an error indicating an invalid data pointer.The text was updated successfully, but these errors were encountered: