From 0330881a742f4a8d7582223706767958a4eb323f Mon Sep 17 00:00:00 2001 From: Luis Gerhorst <luis.gerhorst@fau.de> Date: Wed, 15 Dec 2021 11:25:09 +0100 Subject: [PATCH] du: Don't keep track of depth --- src/task_find.bpf.c | 16 +--------------- src/task_find.h | 4 +++- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/task_find.bpf.c b/src/task_find.bpf.c index e1f395a..d81e6f6 100644 --- a/src/task_find.bpf.c +++ b/src/task_find.bpf.c @@ -16,9 +16,8 @@ struct { } state_map SEC(".maps"); int pdpf; -unsigned long curr_depth = 0; unsigned long disk_usage = 0; -int dfd[MAX_DEPTH*2]; +int dfd[1]; void *u_descend; void *u_ascend; @@ -38,15 +37,8 @@ static long iter_dir(uint32_t d_type, size_t namelen, bool match) { goto end; } - unsigned long depth = curr_depth; - if (depth >= MAX_DEPTH) { - bpf_printk("Error: max_depth exceeded"); - err = -1; - goto end; - } int parent_dfd = dfd[0]; - /* void *name_user = u_iterdents64_buf + depth * PATHLEN; */ void *name_user = u_iterdents64_buf; if (match) { if (flags & PRINT_MATCHES) { @@ -84,21 +76,15 @@ static long iter_dir(uint32_t d_type, size_t namelen, bool match) { write(STDOUT_FILENO, u_descend, 2); } - unsigned long child_depth = depth + 1; - /* void *child_name_user = u_iterdents64_buf + child_depth * PATHLEN; */ void *child_name_user = name_user; - curr_depth = child_depth; dfd[0] = child_dfd; err = bpf_task_iterdents64(child_dfd, pdpf, child_name_user, PATHLEN); dfd[0] = parent_dfd; if (err) { bpf_printk("Error: iterdents64(%d, %d) = %d", child_dfd, pdpf, err); - goto reset_depth; } -reset_depth: - curr_depth = depth; close: if (flags & PRINT_MATCHES) { write(STDOUT_FILENO, u_ascend, 3); diff --git a/src/task_find.h b/src/task_find.h index 67e9314..548c32c 100644 --- a/src/task_find.h +++ b/src/task_find.h @@ -1,7 +1,9 @@ #ifndef __TASK_H_ #define __TASK_H_ -#define MAX_DEPTH 16 +/* legacy */ +#define MAX_DEPTH 1 + #define UBUF_SIZE 1024 #define PATHLEN 512 -- GitLab