mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 19:58:50 +00:00
fsck_online: wrap Linux getdents(2) to a function
This commit is contained in:
parent
c2bdd02c65
commit
b699a613ef
1 changed files with 18 additions and 5 deletions
|
@ -67,6 +67,10 @@ struct fsck_dir {
|
||||||
#define FSCK_DIR_DONE ( 1u << 0 )
|
#define FSCK_DIR_DONE ( 1u << 0 )
|
||||||
|
|
||||||
// Forward declaration start
|
// Forward declaration start
|
||||||
|
#ifdef __linux__
|
||||||
|
static ssize_t getdents (int, void *, size_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
static int next_subdir (struct fsck_ctx *, struct fsck_dir *,
|
static int next_subdir (struct fsck_ctx *, struct fsck_dir *,
|
||||||
struct dirent const **);
|
struct dirent const **);
|
||||||
static int open_subdir (int, char const *, uint64_t *);
|
static int open_subdir (int, char const *, uint64_t *);
|
||||||
|
@ -75,22 +79,31 @@ static void print_help (void);
|
||||||
static void print_version (void);
|
static void print_version (void);
|
||||||
// Forward declaration end
|
// Forward declaration end
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
getdents (
|
||||||
|
int dirfd,
|
||||||
|
void *buf,
|
||||||
|
size_t bufsize
|
||||||
|
) {
|
||||||
|
return syscall(SYS_getdents64, dirfd, buf, bufsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(__linux__) */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
next_subdir (
|
next_subdir (
|
||||||
struct fsck_ctx *ctx,
|
struct fsck_ctx *ctx,
|
||||||
struct fsck_dir *dir,
|
struct fsck_dir *dir,
|
||||||
struct dirent const **dent_ptr
|
struct dirent const **dent_ptr
|
||||||
) {
|
) {
|
||||||
#ifdef __linux__
|
|
||||||
# define getdents(...) syscall(SYS_getdents64, __VA_ARGS__)
|
|
||||||
#endif
|
|
||||||
#define DIRENT_BUFSIZE 4096
|
|
||||||
|
|
||||||
size_t start = dir->dent_start;
|
size_t start = dir->dent_start;
|
||||||
size_t off = dir->dent_off;
|
size_t off = dir->dent_off;
|
||||||
size_t len = ctx->dent_buf_used;
|
size_t len = ctx->dent_buf_used;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (off == len) {
|
if (off == len) {
|
||||||
|
#define DIRENT_BUFSIZE 4096
|
||||||
if (start + DIRENT_BUFSIZE > ctx->dent_buf_size) {
|
if (start + DIRENT_BUFSIZE > ctx->dent_buf_size) {
|
||||||
ctx->dent_buf_size = start + DIRENT_BUFSIZE;
|
ctx->dent_buf_size = start + DIRENT_BUFSIZE;
|
||||||
ctx->dent_buf = xrealloc(ctx->dent_buf, ctx->dent_buf_size);
|
ctx->dent_buf = xrealloc(ctx->dent_buf, ctx->dent_buf_size);
|
||||||
|
|
Loading…
Add table
Reference in a new issue