Conversation
mortbopet
reviewed
Sep 2, 2023
Owner
mortbopet
left a comment
There was a problem hiding this comment.
Some comments - bonus points if you can also come up with a unit test to verify your changes :).
Comment on lines
+199
to
+201
| return (fileFlags[fd] + 1) & 1; // LSB is 1 if the fd has read perms | ||
| } | ||
| return false; | ||
| return (fileFlags[fd] + 1) & 2; // 2nd LSB is 1 if the fd has write perms |
Owner
There was a problem hiding this comment.
Mixing arithmetic and bitwise logic is a bit too funky for me. I think these expressions can be rewritten using bit extracts and XORs.
Owner
There was a problem hiding this comment.
secondly, we should also extract out the nth LSB is X perms to an enum, e.g. something like
enum FilePermissions {
RD_PERM_FLAG = 1 << 0,
WR_PERM_FLAG = 1 << 1
};| static constexpr int O_TRUNC = 0x00000400; // 1024 | ||
| static constexpr int O_EXCL = 0x00000800; // 2048 | ||
|
|
||
| enum Permission { |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The fdInUse function passed in O_WRONLY | O_RDWR as flags and then checked fileFlags[fd] & flags == flags. This is only true if all of the bits set in flags are also set in fileFlags[fd]. Since O_WRONLY | O_RDWR are mutually exclusive the fdInUse function always returns false in this case and the write syscall fails.
I fixed the expression and passed in an enum instead to make it more explicit about what we are testing for.