Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate Interface Directory/Reorganize necessary files #45

Closed
rennergade opened this issue Sep 30, 2024 · 2 comments · Fixed by #52, #53, #54, #55 or #56
Closed

Eliminate Interface Directory/Reorganize necessary files #45

rennergade opened this issue Sep 30, 2024 · 2 comments · Fixed by #52, #53, #54, #55 or #56
Assignees

Comments

@rennergade
Copy link
Contributor

rennergade commented Sep 30, 2024

Removed Functions Documentation

Index of Removed Functions

File: file.rs: PR #53
File: misc.rs: PR #54
File: pipe.rs: PR #55
File: types.rs: PR #56

File: file.rs

removefile

  • Purpose:
    Deletes a file from the filesystem.
  • 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.
@Yaxuan-w
Copy link
Member

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.

@ChinmayShringi
Copy link
Contributor

@Yaxuan-w, I have updated the draft for the functions along with a short description of what they did. Please let me know if I missed anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment