Skip to content
Snippets Groups Projects
Commit 0330881a authored by Luis Gerhorst's avatar Luis Gerhorst
Browse files

du: Don't keep track of depth

parent 80456adb
Branches bpftask
No related tags found
No related merge requests found
......@@ -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);
......
#ifndef __TASK_H_
#define __TASK_H_
#define MAX_DEPTH 16
/* legacy */
#define MAX_DEPTH 1
#define UBUF_SIZE 1024
#define PATHLEN 512
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment