-
Notifications
You must be signed in to change notification settings - Fork 11
Update getdents_syscall tests and comments #286
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e34d61
add tests and comments
rupeshkoushik07 09f5d65
change sem comment
rupeshkoushik07 b2c5127
update
rupeshkoushik07 794e522
update comments
rupeshkoushik07 b2a8428
update tests
rupeshkoushik07 9f7c8fe
resolve conflicts
rupeshkoushik07 c487808
update format
rupeshkoushik07 0e5bf82
update format
rupeshkoushik07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -935,8 +935,8 @@ impl Cage { | |
| /// O_WRONLY flags. | ||
| /// There are generally two cases which occur when this syscall happens: | ||
| /// Case 1: If the file to be opened doesn't exist, then due to O_CREAT flag, | ||
| /// a new file is created at the given location and a new file descriptor is | ||
| /// created and returned. | ||
| /// a new file is created at the given location and a new file descriptor is | ||
| /// created and returned. | ||
| /// Case 2: If the file already exists, then due to O_TRUNC flag, the file | ||
| /// size gets reduced to 0, and the existing file descriptor is returned. | ||
| /// | ||
|
|
@@ -3611,16 +3611,56 @@ impl Cage { | |
| } | ||
|
|
||
| //------------------GETDENTS SYSCALL------------------ | ||
| /// ## `getdents_syscall` | ||
| /// | ||
| /// ### Description | ||
| /// This function reads directory entries from a directory file descriptor | ||
| /// and returns them in a buffer. Reading directory entries using multiple read calls can be less efficient because it | ||
| /// involves reading the data in smaller chunks and then parsing it. | ||
| /// getdents can often be faster by reading directory entries in a more optimized way. | ||
| /// * The function first checks if the provided buffer size is sufficient to store at least one | ||
| /// `ClippedDirent` structure. | ||
| /// * The function validates the provided file descriptor to ensure it represents a | ||
| /// valid file. | ||
| /// * The function checks if the file descriptor refers to a directory. | ||
| /// * The function iterates over the directory entries in the | ||
| /// `filename_to_inode_dict` of the directory inode. | ||
| /// * For each entry, the function constructs a `ClippedDirent` structure, which | ||
| /// contains the inode number, offset, and record length. | ||
| /// * It packs the constructed directory entries into the provided buffer (`dirp`). | ||
| /// * Updates the file position to the next directory entry to be read. | ||
| /// | ||
| /// ### Function Arguments | ||
| /// * `fd`: A file descriptor representing the directory to read. | ||
| /// * `dirp`: A pointer to a buffer where the directory entries will be written. | ||
| /// * `bufsize`: The size of the buffer in bytes. | ||
| /// | ||
| /// ### Returns | ||
| /// * The number of bytes written to the buffer on success. | ||
| /// | ||
| /// ### Errors | ||
| /// * `EINVAL(22)`: If the buffer size is too small or if the file descriptor is invalid. | ||
| /// * `ENOTDIR(20)`: If the file descriptor does not refer to a existing directory. | ||
| /// * `ESPIPE(29)`: If the file descriptor does not refer to a file. | ||
| /// * `EBADF(9)` : If the file descriptor is invalid. | ||
| /// ### Panics | ||
| /// * There are no panics in this syscall. | ||
|
|
||
| pub fn getdents_syscall(&self, fd: i32, dirp: *mut u8, bufsize: u32) -> i32 { | ||
| let mut vec: Vec<(interface::ClippedDirent, Vec<u8>)> = Vec::new(); | ||
|
|
||
| // make sure bufsize is at least greater than size of a ClippedDirent struct | ||
| // ClippedDirent is a simplified version of the traditional dirent structure used in POSIX systems | ||
| // By using a simpler structure, SafePosix can store and retrieve directory entries more efficiently, | ||
| // potentially improving performance compared to using the full dirent structure. | ||
| if bufsize <= interface::CLIPPED_DIRENT_SIZE { | ||
| return syscall_error(Errno::EINVAL, "getdents", "Result buffer is too small."); | ||
| } | ||
|
|
||
| let checkedfd = self.get_filedescriptor(fd).unwrap(); | ||
| let checkedfd = match self.get_filedescriptor(fd) { | ||
| Ok(fd) => fd, | ||
| Err(_) => return syscall_error(Errno::EBADF, "getdents", "Invalid file descriptor."), | ||
| }; | ||
| let mut unlocked_fd = checkedfd.write(); | ||
| if let Some(filedesc_enum) = &mut *unlocked_fd { | ||
| match filedesc_enum { | ||
|
|
@@ -3650,7 +3690,7 @@ impl Cage { | |
| // convert filename to a filename vector of u8 | ||
| let mut vec_filename: Vec<u8> = filename.as_bytes().to_vec(); | ||
| vec_filename.push(b'\0'); // make filename null-terminated | ||
|
|
||
| // Push DT_UNKNOWN as d_type. This is a placeholder for now, as the actual file type is not yet determined. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some weird whitespace here, have you done a cargo fmt?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes even with cargo fmt the whitespace is there |
||
| vec_filename.push(DT_UNKNOWN); // push DT_UNKNOWN as d_type (for now) | ||
| temp_len = | ||
| interface::CLIPPED_DIRENT_SIZE + vec_filename.len() as u32; // get length of current filename vector for padding calculation | ||
|
|
@@ -3686,6 +3726,8 @@ impl Cage { | |
| count += 1; | ||
| } | ||
| // update file position | ||
| // keeps track of the current position within the directory. It indicates which directory entry the | ||
| // function should read next. | ||
| normalfile_filedesc_obj.position = interface::rust_min( | ||
| position + count, | ||
| dir_inode_obj.filename_to_inode_dict.len(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.