Skip to content
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

Should the behavior of "O_RDONLY|O_TRUNC" be undefined? #39

Closed
yujunz opened this issue Dec 23, 2019 · 1 comment · Fixed by #40
Closed

Should the behavior of "O_RDONLY|O_TRUNC" be undefined? #39

yujunz opened this issue Dec 23, 2019 · 1 comment · Fixed by #40

Comments

@yujunz
Copy link

yujunz commented Dec 23, 2019

Alibaba Cloud NAS failed in pjdfstest/tests/open/07.t as following

/root/pjdfstest/tests/open/07.t ............. 
not ok 5 - tried '-u 65534 -g 65534 open pjdfstest_f24a42815d59c16a4bde54e6559d0390 O_RDONLY,O_TRUNC', expected EACCES, got 0
not ok 7 - tried '-u 65533 -g 65534 open pjdfstest_f24a42815d59c16a4bde54e6559d0390 O_RDONLY,O_TRUNC', expected EACCES, got 0
not ok 9 - tried '-u 65533 -g 65533 open pjdfstest_f24a42815d59c16a4bde54e6559d0390 O_RDONLY,O_TRUNC', expected EACCES, got 0
Failed 3/23 subtests

However the The Single UNIX ® Specification, Version 2 suggests the result of such case is undefined.

O_TRUNC
If the file exists and is a regular file, and the file is successfully opened O_RDWR or O_WRONLY, its length is truncated to 0 and the mode and owner are unchanged. It will have no effect on FIFO special files or terminal device files. Its effect on other file types is implementation-dependent. The result of using O_TRUNC with O_RDONLY is undefined.

When I try to check the actual effect on the file, it turns out the file system DOES return EACCES if the file size is non-zero. See the constructed test case trunc.t for details.

In fact, when file size is 0, O_TRUNC will have no effect at all. It is reasonable to treat it as an undefined behavior. It might be more meaningful to test against a non-empty file instead of an empty one and check the size after the operation.

What do you think? @pjd

@pjd
Copy link
Owner

pjd commented Dec 27, 2019 via email

yujunz pushed a commit to juicedata/pjdfstest that referenced this issue Dec 29, 2019
@pjd pjd closed this as completed in #40 Jan 14, 2020
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 a pull request may close this issue.

2 participants