-
Notifications
You must be signed in to change notification settings - Fork 126
fix(starry-kernel): open/openat — 15-class local POSIX compatibility fixes #719
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
8 changes: 8 additions & 0 deletions
8
test-suit/starryos/normal/qemu-smp1/bugfix/bug-open-append-trunc-einval/c/CMakeLists.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(bug-open-append-trunc-einval C) | ||
| set(CMAKE_C_STANDARD 11) | ||
| set(CMAKE_C_STANDARD_REQUIRED ON) | ||
| set(CMAKE_C_EXTENSIONS ON) | ||
| add_executable(bug-open-append-trunc-einval src/main.c) | ||
| target_compile_options(bug-open-append-trunc-einval PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS bug-open-append-trunc-einval RUNTIME DESTINATION usr/bin) |
47 changes: 47 additions & 0 deletions
47
test-suit/starryos/normal/qemu-smp1/bugfix/bug-open-append-trunc-einval/c/src/main.c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * bug-open-append-trunc-einval: O_RDWR|O_APPEND|O_TRUNC on existing file | ||
| * must succeed (truncate then append). | ||
| * | ||
| * Linux behavior: O_RDWR + O_APPEND + O_TRUNC is a valid combination. open | ||
| * succeeds; the file is truncated to 0; subsequent writes append. | ||
| * StarryOS bug: axfs-ng/highlevel/file.rs:OpenOptions::is_valid() rejects | ||
| * `(_, true) => if self.truncate && !self.create_new { return false; }` | ||
| * when O_APPEND is set with O_TRUNC and CREAT_NEW isn't — returns -1 EINVAL. | ||
| */ | ||
| #define _GNU_SOURCE | ||
| #include <errno.h> | ||
| #include <fcntl.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <sys/stat.h> | ||
| #include <unistd.h> | ||
|
|
||
| int main(void) | ||
| { | ||
| const char *file = "/tmp/bug_append_trunc"; | ||
| unlink(file); | ||
| int fd0 = open(file, O_CREAT | O_WRONLY, 0644); | ||
| if (fd0 < 0) { perror("setup"); return 1; } | ||
| write(fd0, "hello", 5); | ||
| close(fd0); | ||
|
|
||
| errno = 0; | ||
| int fd = open(file, O_RDWR | O_APPEND | O_TRUNC); | ||
| int ok = 0; | ||
| if (fd >= 0) { | ||
| struct stat st; | ||
| if (stat(file, &st) == 0 && st.st_size == 0) { | ||
| printf("PASS: open(O_RDWR|O_APPEND|O_TRUNC) -> fd=%d, size=0\n", fd); | ||
| ok = 1; | ||
| } else { | ||
| printf("FAIL: opened ok but size=%ld (expected 0)\n", (long)st.st_size); | ||
| } | ||
| close(fd); | ||
| } else { | ||
| printf("FAIL: open(O_RDWR|O_APPEND|O_TRUNC) -> -1 errno=%d (%s); expected fd>=0\n", | ||
| errno, strerror(errno)); | ||
| } | ||
|
|
||
| unlink(file); | ||
| return ok ? 0 : 1; | ||
| } |
8 changes: 8 additions & 0 deletions
8
test-suit/starryos/normal/qemu-smp1/bugfix/bug-open-creat-directory-einval/c/CMakeLists.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(bug-open-creat-directory-einval C) | ||
| set(CMAKE_C_STANDARD 11) | ||
| set(CMAKE_C_STANDARD_REQUIRED ON) | ||
| set(CMAKE_C_EXTENSIONS ON) | ||
| add_executable(bug-open-creat-directory-einval src/main.c) | ||
| target_compile_options(bug-open-creat-directory-einval PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS bug-open-creat-directory-einval RUNTIME DESTINATION usr/bin) |
64 changes: 64 additions & 0 deletions
64
test-suit/starryos/normal/qemu-smp1/bugfix/bug-open-creat-directory-einval/c/src/main.c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * bug-open-creat-directory-einval: O_CREAT|O_DIRECTORY must fail with EINVAL. | ||
| * | ||
| * man 2 open implies (and Linux enforces): you cannot create a directory with | ||
| * open(); O_CREAT|O_DIRECTORY is rejected up front with EINVAL. | ||
| * | ||
| * Linux behavior: open(<anything>, O_CREAT|O_DIRECTORY) → -1 EINVAL | ||
| * StarryOS bug: doesn't reject the combo; either returns a valid fd (for | ||
| * existing directories) or lets path-resolution errors fire (ENOTDIR for | ||
| * regular files, EEXIST when O_EXCL also set on existing path). | ||
| * | ||
| * Root cause: starry's flags_to_options (kernel/src/syscall/fs/fd_ops.rs:26-63) | ||
| * doesn't validate that CREAT and DIRECTORY are mutually exclusive. | ||
| */ | ||
| #define _GNU_SOURCE | ||
| #include <errno.h> | ||
| #include <fcntl.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <sys/stat.h> | ||
| #include <unistd.h> | ||
|
|
||
| static int probe(const char *path, const char *desc) | ||
| { | ||
| errno = 0; | ||
| int fd = open(path, O_RDONLY | O_CREAT | O_DIRECTORY, 0644); | ||
| int ok = (fd == -1 && errno == EINVAL); | ||
| if (ok) { | ||
| printf("PASS: %s -> -1 EINVAL\n", desc); | ||
| } else { | ||
| printf("FAIL: %s -> fd=%d errno=%d (%s); expected -1 EINVAL\n", | ||
| desc, fd, errno, strerror(errno)); | ||
| } | ||
| if (fd >= 0) close(fd); | ||
| return ok; | ||
| } | ||
|
|
||
| int main(void) | ||
| { | ||
| int ok = 1; | ||
|
|
||
| /* against existing regular file */ | ||
| const char *file = "/tmp/bug_creat_dir_file"; | ||
| unlink(file); | ||
| int fd = open(file, O_CREAT | O_WRONLY, 0644); | ||
| if (fd >= 0) close(fd); | ||
| ok &= probe(file, "existing regular file + O_CREAT|O_DIRECTORY"); | ||
| unlink(file); | ||
|
|
||
| /* against existing directory */ | ||
| const char *dir = "/tmp/bug_creat_dir_dir"; | ||
| rmdir(dir); | ||
| mkdir(dir, 0755); | ||
| ok &= probe(dir, "existing directory + O_CREAT|O_DIRECTORY"); | ||
| rmdir(dir); | ||
|
|
||
| /* against absent path */ | ||
| const char *absent = "/tmp/bug_creat_dir_absent_xyz"; | ||
| unlink(absent); | ||
| ok &= probe(absent, "absent path + O_CREAT|O_DIRECTORY"); | ||
| unlink(absent); | ||
|
|
||
| return ok ? 0 : 1; | ||
| } |
8 changes: 8 additions & 0 deletions
8
...tarryos/normal/qemu-smp1/bugfix/bug-open-creat-on-existing-dir-no-eisdir/c/CMakeLists.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(bug-open-creat-on-existing-dir-no-eisdir C) | ||
| set(CMAKE_C_STANDARD 11) | ||
| set(CMAKE_C_STANDARD_REQUIRED ON) | ||
| set(CMAKE_C_EXTENSIONS ON) | ||
| add_executable(bug-open-creat-on-existing-dir-no-eisdir src/main.c) | ||
| target_compile_options(bug-open-creat-on-existing-dir-no-eisdir PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS bug-open-creat-on-existing-dir-no-eisdir RUNTIME DESTINATION usr/bin) |
Oops, something went wrong.
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.
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.
💡 小建议(非阻塞):
O_PATHlast-override 块中options.read(true).write(false)—read(true)是为了 F_GETFL 正确返回访问模式位。建议加一行注释说明read(true)的目的(当前注释说 'drop access mode (no I/O)' 但 read(true) 实际上是设置访问模式位)。不过不影响正确性。