Skip to content

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

Merged
merged 7 commits into from
Jun 20, 2024
Merged

Open_syscall comments and tests #264

merged 7 commits into from
Jun 20, 2024

Conversation

namanlalitnyu
Copy link
Contributor

@namanlalitnyu namanlalitnyu commented Jun 14, 2024

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

  • This change just contains the tests for an existing file system call.

How Has This Been Tested?

Inorder to run the tests, we need to run cargo test --lib command inside the safeposix-rust directory.

All the tests are present under this directory: lind_project/src/safeposix-rust/src/tests/fs_tests.rs

  • Test A - ut_lind_fs_open_empty_directory()
  • Test B - ut_lind_fs_open_nonexisting_parentdirectory_and_file()
  • Test C - ut_lind_fs_open_existing_parentdirectory_and_nonexisting_file()
  • Test D - ut_lind_fs_open_existing_file_without_flags()
  • Test E - ut_lind_fs_open_existing_file_with_flags()
  • Test F - ut_lind_fs_open_create_new_file_and_check_link_count()
  • Test G - ut_lind_fs_open_existing_file_with_o_trunc_flag()
  • Test H - ut_lind_fs_open_new_file_with_s_ifchar_flag()

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been added to a pull request and/or merged in other modules (native-client, lind-glibc, lind-project)

@namanlalitnyu
Copy link
Contributor Author

namanlalitnyu commented Jun 14, 2024

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.

Copy link
Member

@JustinCappos JustinCappos left a 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.

// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

match metawalkandparent(truepath.as_path()) {
//If neither the file nor parent exists
// Case 1: When neither the file directory nor the parent directory exists
Copy link
Member

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?

Copy link
Contributor

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.

@JustinCappos
Copy link
Member

@namanlalitnyu A few minor github things...

  1. feel free to resolve conversations after you think you've addressed something.

  2. it's better to address a question with a comment in the code (when this makes sense) instead of only on the issue. When we read the code later, we've lost the q/a.

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)

@namanlalitnyu
Copy link
Contributor Author

@namanlalitnyu A few minor github things...

  1. feel free to resolve conversations after you think you've addressed something.
  2. it's better to address a question with a comment in the code (when this makes sense) instead of only on the issue. When we read the code later, we've lost the q/a.

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();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this extra whitespace

Copy link
Contributor Author

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.

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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment.

Copy link
Contributor

@rennergade rennergade left a 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.

Copy link
Member

@JustinCappos JustinCappos left a 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
Copy link
Member

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?

Copy link
Contributor Author

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.

@namanlalitnyu namanlalitnyu requested a review from rennergade June 20, 2024 15:29
@namanlalitnyu
Copy link
Contributor Author

Looks fine after the return values / panics in the comment block is updated.

Updated the comments with error values and panics in the comment block.

Copy link
Contributor

@yashaswi2000 yashaswi2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rennergade
Copy link
Contributor

I think this looks ready. Good job!

@rennergade rennergade merged commit 546acc5 into develop Jun 20, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants