-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Fix write syscall #296
base: master
Are you sure you want to change the base?
Fix write syscall #296
Conversation
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.
Some comments - bonus points if you can also come up with a unit test to verify your changes :).
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 |
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.
Mixing arithmetic and bitwise logic is a bit too funky for me. I think these expressions can be rewritten using bit extracts and XORs.
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.
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
};
@@ -84,6 +84,11 @@ class SystemIO : public QObject { | |||
static constexpr int O_TRUNC = 0x00000400; // 1024 | |||
static constexpr int O_EXCL = 0x00000800; // 2048 | |||
|
|||
enum Permission { |
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.
enum class
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.