From bc2382eff9dd89ba93f38a5421fe2cd7aad625eb Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Mon, 22 Nov 2021 15:54:11 +0000 Subject: [PATCH] btrfs-progs: fi du: skip inaccessible files Filesystem du command fails and exits when it access file that has permission denied. But it can continue the command except the files. This patch prints error message just like /bin/du does and it continues if it can. Issue: #421 Reviewed-by: Nikolay Borisov Signed-off-by: Sidong Yang Signed-off-by: David Sterba --- cmds/filesystem-du.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmds/filesystem-du.c b/cmds/filesystem-du.c index 5865335d..7ea2da85 100644 --- a/cmds/filesystem-du.c +++ b/cmds/filesystem-du.c @@ -403,14 +403,14 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents) dirfd(dirstream), shared_extents, &tot, &shr, 0); - if (ret == -ENOTTY) { - ret = 0; - continue; - } else if (ret) { + if (ret) { errno = -ret; - fprintf(stderr, - "failed to walk dir/file: %s : %m\n", - entry->d_name); + fprintf(stderr, "cannot access: '%s:' %m\n", + entry->d_name); + if (ret == -ENOTTY || ret == -EACCES) { + ret = 0; + continue; + } break; }