-
Notifications
You must be signed in to change notification settings - Fork 10
Open_syscall comments and tests #264
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
Conversation
Completed with the comments in the sys_call and added a few tests for it. But, still working on the remaining ones and will update the PR within some time once the other tests are completed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good first cut. A few minor changes requested.
src/safeposix/syscalls/fs_calls.rs
Outdated
// Function Arguments | ||
// The open_syscall() receives three arguments: | ||
// 1. Path - This argument points to a pathname naming the file. | ||
// For example: "/parentdir/file1" represents a file which will be either opened if existed or will be created at the given path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// For example: "/parentdir/file1" represents a file which will be either opened if existed or will be created at the given path. | |
// For example: "/parentdir/file1" represents a file which will be either opened if it exists or will be created at the given path. |
src/safeposix/syscalls/fs_calls.rs
Outdated
match metawalkandparent(truepath.as_path()) { | ||
//If neither the file nor parent exists | ||
// Case 1: When neither the file directory nor the parent directory exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sort of weird to structure it like this because if the parent director doesn't exist, then the file clearly won't. Can you just check to make sure the parent dir exists and return an error otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just want clarity the tuple check in match statement would just be (.., None) since the second field is the parent and the first field doesn't matter. Thought metawalkparent will always return (None, None) if the parent doesn't exist since like you said if we don't find a parent we obviously don't have the file.
@namanlalitnyu A few minor github things...
This isn't a huge problem here (you've done a nice job!), but I wanted to bring them up since they are top-of-mind) |
Sure professor, thanks for the suggestions. Will do that! |
// Remove the previous file and add a new one of 0 length | ||
if let interface::RustHashEntry::Occupied(occ) = entry { | ||
occ.remove_entry(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this extra whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked, and there is not any extra whitespace here; it is just because of the indentation as the code section has moved inside the matching block.
src/safeposix/syscalls/fs_calls.rs
Outdated
let entry = FILEOBJECTTABLE.entry(inodenum); | ||
if let interface::RustHashEntry::Occupied(occ) = &entry { | ||
occ.get().close().unwrap(); | ||
// Doubt: Why are we removing the previous entry from the FileObjectTable and then inserting a new file with size 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hacky way to truncate since a new file will be size 0 instead of actually adjusting the filesize and pointer. I would comment that thats what were doing but also label it as a possible bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor changes, should be able to get this merged today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine after the return values / panics in the comment block is updated.
/// Upon successful completion of this call, a file descriptor is returned which points the file which is opened. | ||
/// Otherwise, an error with a proper errorNumber and errorMessage is returned based on the different scenarios. | ||
/// | ||
/// for more detailed description of all the commands and return values, see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't cover all the cases of open though, do we? What errors are returned and which are not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we don't cover all the errors. Manpage has a lot of them mentioned which are remaining.
Updated the comments with error values and panics in the comment block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I think this looks ready. Good job! |
Description
Fixes # (issue)
The following changes include the tests and comments in the code for the "open_syscall" file system call under RustPosix.
The tests were added to cover all the possible scenarios that might happen when calling the file system_call
open_syscall
.Type of change
How Has This Been Tested?
Inorder to run the tests, we need to run
cargo test --lib
command inside thesafeposix-rust
directory.All the tests are present under this directory:
lind_project/src/safeposix-rust/src/tests/fs_tests.rs
ut_lind_fs_open_empty_directory()
ut_lind_fs_open_nonexisting_parentdirectory_and_file()
ut_lind_fs_open_existing_parentdirectory_and_nonexisting_file()
ut_lind_fs_open_existing_file_without_flags()
ut_lind_fs_open_existing_file_with_flags()
ut_lind_fs_open_create_new_file_and_check_link_count()
ut_lind_fs_open_existing_file_with_o_trunc_flag()
ut_lind_fs_open_new_file_with_s_ifchar_flag()
Checklist: