-
-
Notifications
You must be signed in to change notification settings - Fork 909
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
Handle AT_EMPTY_PATH for fstatat64 #1812
Open
zhaofengli
wants to merge
1
commit into
ish-app:master
Choose a base branch
from
zhaofengli:fstat-empty-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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 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 |
---|---|---|
|
@@ -30,11 +30,31 @@ struct newstat64 stat_convert_newstat64(struct statbuf stat) { | |
return newstat; | ||
} | ||
|
||
int generic_statat(struct fd *at, const char *path_raw, struct statbuf *stat, bool follow_links) { | ||
int generic_statat(struct fd *at, const char *path_raw, struct statbuf *stat, int flags) { | ||
int err; | ||
|
||
bool empty_path = flags & AT_EMPTY_PATH_; | ||
bool follow_links = !(flags & AT_SYMLINK_NOFOLLOW_); | ||
|
||
char path[MAX_PATH]; | ||
int err = path_normalize(at, path_raw, path, follow_links ? N_SYMLINK_FOLLOW : N_SYMLINK_NOFOLLOW); | ||
if (err < 0) | ||
return err; | ||
if (empty_path && (strcmp(path_raw, "") == 0)) { | ||
if (at == AT_PWD) { | ||
at = current->fs->pwd; | ||
} | ||
|
||
err = generic_getpath(at, path); | ||
if (err < 0) | ||
return err; | ||
|
||
if (!path_is_normalized(path)) { | ||
return _ENOENT; | ||
} | ||
} else { | ||
err = path_normalize(at, path_raw, path, follow_links ? N_SYMLINK_FOLLOW : N_SYMLINK_NOFOLLOW); | ||
if (err < 0) | ||
return err; | ||
} | ||
|
||
struct mount *mount = find_mount_and_trim_path(path); | ||
memset(stat, 0, sizeof(*stat)); | ||
err = mount->fs->stat(mount, path, stat); | ||
|
@@ -49,17 +69,18 @@ static struct fd *at_fd(fd_t f) { | |
return f_get(f); | ||
} | ||
|
||
static dword_t sys_stat_path(fd_t at_f, addr_t path_addr, addr_t statbuf_addr, bool follow_links) { | ||
// The `flags` parameter accepts AT_ flags | ||
static dword_t sys_stat_path(fd_t at_f, addr_t path_addr, addr_t statbuf_addr, int flags) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function now has the exact signature of sys_fstatat64 so maybe rename to sys_fstatat64 |
||
int err; | ||
char path[MAX_PATH]; | ||
if (user_read_string(path_addr, path, sizeof(path))) | ||
return _EFAULT; | ||
STRACE("stat(at=%d, path=\"%s\", statbuf=0x%x, follow_links=%d)", at_f, path, statbuf_addr, follow_links); | ||
STRACE("stat(at=%d, path=\"%s\", statbuf=0x%x, flags=0x%x)", at_f, path, statbuf_addr, flags); | ||
struct fd *at = at_fd(at_f); | ||
if (at == NULL) | ||
return _EBADF; | ||
struct statbuf stat = {}; | ||
if ((err = generic_statat(at, path, &stat, follow_links)) < 0) | ||
if ((err = generic_statat(at, path, &stat, flags)) < 0) | ||
return err; | ||
struct newstat64 newstat = stat_convert_newstat64(stat); | ||
if (user_put(statbuf_addr, newstat)) | ||
|
@@ -68,15 +89,15 @@ static dword_t sys_stat_path(fd_t at_f, addr_t path_addr, addr_t statbuf_addr, b | |
} | ||
|
||
dword_t sys_stat64(addr_t path_addr, addr_t statbuf_addr) { | ||
return sys_stat_path(AT_FDCWD_, path_addr, statbuf_addr, true); | ||
return sys_stat_path(AT_FDCWD_, path_addr, statbuf_addr, 0); | ||
} | ||
|
||
dword_t sys_lstat64(addr_t path_addr, addr_t statbuf_addr) { | ||
return sys_stat_path(AT_FDCWD_, path_addr, statbuf_addr, false); | ||
return sys_stat_path(AT_FDCWD_, path_addr, statbuf_addr, AT_SYMLINK_NOFOLLOW_); | ||
} | ||
|
||
dword_t sys_fstatat64(fd_t at, addr_t path_addr, addr_t statbuf_addr, dword_t flags) { | ||
return sys_stat_path(at, path_addr, statbuf_addr, !(flags & AT_SYMLINK_NOFOLLOW_)); | ||
return sys_stat_path(at, path_addr, statbuf_addr, flags); | ||
} | ||
|
||
dword_t sys_fstat64(fd_t fd_no, addr_t statbuf_addr) { | ||
|
This file contains 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 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
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.
I suspect this should be calling fstat instead