-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc] implement pathconf/fpathconf #87165
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 9 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f428a36
intiial attempt
changkhothuychung 480690f
remove fpathconf
changkhothuychung c585630
add fpathconf
changkhothuychung b9436a3
fstatvfs
changkhothuychung a9d69b4
Merge branch 'main' into pathconf-impl
changkhothuychung dc6b994
Merge branch 'main' into pathconf-impl
changkhothuychung 001e9a2
some fix
changkhothuychung ff19692
some fix and add test
changkhothuychung 1b83f13
some fix
changkhothuychung 4a6c986
refactor
changkhothuychung 445bef6
some fix
changkhothuychung fa71f67
some fix
changkhothuychung 751e22c
some changes
changkhothuychung 2d66e87
some fix
changkhothuychung 94349c2
move utils to linux
changkhothuychung f57f003
move header to linux
changkhothuychung 65ff5e6
aplly new patch
changkhothuychung 5f96eb8
Merge branch 'main' into pathconf-impl
SchrodingerZhu 6af318b
fix build issue
SchrodingerZhu e7c690b
Merge pull request #1 from SchrodingerZhu/zyf-patch
changkhothuychung 0ab4d2c
Merge branch 'main' into pathconf-impl
changkhothuychung 04ab180
fix header files
changkhothuychung ef770b2
fix dependency
changkhothuychung 7a28909
some fixes
changkhothuychung 722bb11
some fix
changkhothuychung 1e092d2
Merge branch 'main' into pathconf-impl
SchrodingerZhu 2f5614b
apply patch
changkhothuychung 3fb2a75
Merge branch 'pathconf-impl' of https://github.com/changkhothuychung/…
changkhothuychung 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//===-- Implementation header for fpathconf ---------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_UNISTD_FSYNC_H | ||
#define LLVM_LIBC_SRC_UNISTD_FSYNC_H | ||
SchrodingerZhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
long fpathconf(int fd, int name); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_UNISTD_FSYNC_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
//===-- Linux implementation of fpathconf ---------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
#include "src/__support/common.h" | ||
|
||
#include "src/errno/libc_errno.h" | ||
#include <sys/syscall.h> // For syscall numbers. | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
static long filesizebits(const struct statfs &s) { | ||
switch (s.f_type) { | ||
case JFFS2_SUPER_MAGIC: | ||
case MSDOS_SUPER_MAGIC: | ||
case NCP_SUPER_MAGIC: | ||
return 32; | ||
} | ||
return 64; | ||
} | ||
|
||
static long link_max(const struct statfs &s) { | ||
switch (s.f_type) { | ||
case EXT2_SUPER_MAGIC: | ||
return 32000; | ||
case MINIX_SUPER_MAGIC: | ||
return 250; | ||
case MINIX2_SUPER_MAGIC: | ||
return 65530; | ||
case REISERFS_SUPER_MAGIC: | ||
return 0xffff - 1000; | ||
case UFS_MAGIC: | ||
return 32000; | ||
} | ||
return LINK_MAX; | ||
} | ||
|
||
static long _2_symlinks(const struct statfs &s) { | ||
switch (s.f_type) { | ||
case ADFS_SUPER_MAGIC: | ||
case BFS_MAGIC: | ||
case CRAMFS_MAGIC: | ||
case EFS_SUPER_MAGIC: | ||
case MSDOS_SUPER_MAGIC: | ||
case QNX4_SUPER_MAGIC: | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
static long fpathconfig(const struct fstatfs &s, int name) { | ||
switch (name) { | ||
case _PC_LINK_MAX: | ||
return link_max(s); | ||
|
||
case _PC_FILESIZEBITS: | ||
return filesizebits(s); | ||
|
||
case _PC_2_SYMLINKS: | ||
return _2_symlinks(s); | ||
|
||
case _PC_REC_MIN_XFER_SIZE: | ||
return s.f_bsize; | ||
|
||
case _PC_ALLOC_SIZE_MIN: | ||
case _PC_REC_XFER_ALIGN: | ||
return s.f_frsize; | ||
|
||
case _PC_MAX_CANON: | ||
return _POSIX_MAX_CANON; | ||
|
||
case _PC_MAX_INPUT: | ||
return _POSIX_MAX_INPUT; | ||
|
||
case _PC_NAME_MAX: | ||
return s.f_namemax; | ||
|
||
case _PC_PATH_MAX: | ||
return _POSIX_PATH_MAX; | ||
|
||
case _PC_PIPE_BUF: | ||
return _POSIX_PIPE_BUF; | ||
|
||
case _PC_CHOWN_RESTRICTED: | ||
return _POSIX_CHOWN_RESTRICTED; | ||
|
||
case _PC_NO_TRUNC: | ||
return _POSIX_NO_TRUNC; | ||
|
||
case _PC_VDISABLE: | ||
return _POSIX_VDISABLE; | ||
|
||
case _PC_ASYNC_IO: | ||
case _PC_PRIO_IO: | ||
case _PC_REC_INCR_XFER_SIZE: | ||
case _PC_REC_MAX_XFER_SIZE: | ||
case _PC_SYMLINK_MAX: | ||
case _PC_SYNC_IO: | ||
return -1; | ||
|
||
default: | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
} | ||
|
||
LLVM_LIBC_FUNCTION(long, fpathconf, (int fd, int name)) { | ||
struct fstatfs sb; | ||
if (cpp::optional<LinuxStatFs> result = linux_fstatfs(fd)) | ||
return fpathconfig(sb, name); | ||
changkhothuychung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return -1; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
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,123 @@ | ||
//===-- Linux implementation of pathconf ----------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/unistd/pread.h" | ||
|
||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
#include "src/__support/common.h" | ||
#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON | ||
changkhothuychung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "src/errno/libc_errno.h" | ||
#include <stdint.h> // For uint64_t. | ||
#include <sys/fstatvfs.h> | ||
#include <sys/syscall.h> // For syscall numbers. | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
static long filesizebits(const struct statfs &s) { | ||
switch (s.f_type) { | ||
case JFFS2_SUPER_MAGIC: | ||
case MSDOS_SUPER_MAGIC: | ||
case NCP_SUPER_MAGIC: | ||
return 32; | ||
} | ||
return 64; | ||
} | ||
|
||
static long link_max(const struct statfs &s) { | ||
switch (s.f_type) { | ||
case EXT2_SUPER_MAGIC: | ||
return 32000; | ||
case MINIX_SUPER_MAGIC: | ||
return 250; | ||
case MINIX2_SUPER_MAGIC: | ||
return 65530; | ||
case REISERFS_SUPER_MAGIC: | ||
return 0xffff - 1000; | ||
case UFS_MAGIC: | ||
return 32000; | ||
} | ||
return LINK_MAX; | ||
} | ||
|
||
static long _2_symlinks(const struct statfs &s) { | ||
switch (s.f_type) { | ||
case ADFS_SUPER_MAGIC: | ||
case BFS_MAGIC: | ||
case CRAMFS_MAGIC: | ||
case EFS_SUPER_MAGIC: | ||
case MSDOS_SUPER_MAGIC: | ||
case QNX4_SUPER_MAGIC: | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
static long pathconfig(const struct statfs &s, int name) { | ||
switch (name) { | ||
case _PC_LINK_MAX: | ||
return link_max(s); | ||
|
||
case _PC_FILESIZEBITS: | ||
return filesizebits(s); | ||
|
||
case _PC_2_SYMLINKS: | ||
return _2_symlinks(s); | ||
|
||
case _PC_REC_MIN_XFER_SIZE: | ||
return s.f_bsize; | ||
|
||
case _PC_ALLOC_SIZE_MIN: | ||
case _PC_REC_XFER_ALIGN: | ||
return s.f_frsize; | ||
|
||
case _PC_MAX_CANON: | ||
return _POSIX_MAX_CANON; | ||
|
||
case _PC_MAX_INPUT: | ||
return _POSIX_MAX_INPUT; | ||
|
||
case _PC_NAME_MAX: | ||
return s.f_namemax; | ||
|
||
case _PC_PATH_MAX: | ||
return _POSIX_PATH_MAX; | ||
|
||
case _PC_PIPE_BUF: | ||
return _POSIX_PIPE_BUF; | ||
|
||
case _PC_CHOWN_RESTRICTED: | ||
return _POSIX_CHOWN_RESTRICTED; | ||
|
||
case _PC_NO_TRUNC: | ||
return _POSIX_NO_TRUNC; | ||
|
||
case _PC_VDISABLE: | ||
return _POSIX_VDISABLE; | ||
|
||
case _PC_ASYNC_IO: | ||
case _PC_PRIO_IO: | ||
case _PC_REC_INCR_XFER_SIZE: | ||
case _PC_REC_MAX_XFER_SIZE: | ||
case _PC_SYMLINK_MAX: | ||
case _PC_SYNC_IO: | ||
return -1; | ||
|
||
default: | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
} | ||
|
||
LLVM_LIBC_FUNCTION(long, pathconf, (char *path, int name)) { | ||
if (cpp::optional<LinuxStatFs> result = linux_statfs(const char *path);) { | ||
return pathconfig(result.value(), name); | ||
} | ||
changkhothuychung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return -1; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
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,20 @@ | ||
//===-- Implementation header for pathconf ----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_UNISTD_PREAD_H | ||
#define LLVM_LIBC_SRC_UNISTD_PREAD_H | ||
SchrodingerZhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <unistd.h> | ||
changkhothuychung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
long pathconf(char *path, int name); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_UNISTD_PREAD_H |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.