Skip to contentSkip to conversation

btrfs-progs: filesystem: du: skip file that permission denied

RFC PATCH Superseded Sidong Yang 2 participants 3 messages Nov 21, 2021 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 btrfs-progs: filesystem: du: skip file that permission denied

This patch handles issue #421. Filesystem du command fails and exit when it access file that has permission denied. But it can continue the command except the files. This patch recovers ret value when permission denied.

---
 cmds/filesystem-du.c | 3 +++
 1 file changed, 3 insertions(+)
cmds/filesystem-du.c +3 -0
index 5865335d..64a1f7f5 100644
@@ -406,6 +406,9 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents)
 				if (ret == -ENOTTY) {
 					ret = 0;
 					continue;
+				} else if (ret == -EACCES) {
+					ret = 0;
+					continue;
 				} else if (ret) {
 					errno = -ret;
 					fprintf(stderr,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 15 lines · Sidong Yang

This patch handles issue #421. Filesystem du command fails and exit when it access file that has permission denied. But it can continue the command except the files. This patch recovers ret value when permission denied.

---
 cmds/filesystem-du.c | 3 +++
 1 file changed, 3 insertions(+)
cmds/filesystem-du.c +0 -0
index 5865335d..64a1f7f5 100644

cmds/filesystem-du.c static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents) · line 409

Quoted 4 lines
cmds/filesystem-du.c +1 -0
@@ -406,6 +406,9 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents)
 				if (ret == -ENOTTY) {
 					ret = 0;
 					continue;
+				} else if (ret == -EACCES) {

This can be added to the above condition with || ret == -EACCESS. Avoids code duplication.

Quoted 6 lines
cmds/filesystem-du.c +2 -0
+					ret = 0;
+					continue;
 				} else if (ret) {
 					errno = -ret;
 					fprintf(stderr,
#2 lore raw
Quoted 13 lines · Nikolay Borisov
Quoted 10 lines · Sidong Yang

This patch handles issue #421. Filesystem du command fails and exit when it access file that has permission denied. But it can continue the command except the files. This patch recovers ret value when permission denied.

---
 cmds/filesystem-du.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 12 lines

cmds/filesystem-du.c static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents) · line 409

Quoted 9 lines
cmds/filesystem-du.c +1 -0
index 5865335d..64a1f7f5 100644
@@ -406,6 +406,9 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents)
 				if (ret == -ENOTTY) {
 					ret = 0;
 					continue;
+				} else if (ret == -EACCES) {

This can be added to the above condition with || ret == -EACCESS. Avoids code duplication.

Thanks! It would be better.

Quoted 7 lines
Quoted 7 lines
cmds/filesystem-du.c +2 -0
+					ret = 0;
+					continue;
 				} else if (ret) {
 					errno = -ret;
 					fprintf(stderr,