btrfs-progs: fix fi du so it works in more cases

Currently, btrfs fi du uses open_file_or_dir(), which tries to open
it's argument with O_RDWR.  Because of POSIX semantics, this fails for
non-root users when the file is read-only or is an executable that
is being run currently, or for all users (including root) when the
filesystem is read-only.  This results in a somewhat confusing 'Unknown
error -1' message when trying to check such files.  Switch to using
open_file_or_dir3() with O_RDONLY passed in the flags, as this avoids
the limitations listed above, and we have no need to write to the files
anyway (and thus shouldn't be opening them writable).

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Austin S. Hemmelgarn 2016-03-21 08:23:11 -04:00 committed by David Sterba
parent 74a5d7478a
commit 1c36022fe7
1 changed files with 1 additions and 1 deletions

View File

@ -438,7 +438,7 @@ static int du_add_file(const char *filename, int dirfd,
ret = sprintf(pathp, "/%s", filename);
pathp += ret;
fd = open_file_or_dir(path, &dirstream);
fd = open_file_or_dir3(path, &dirstream, O_RDONLY);
if (fd < 0) {
ret = fd;
goto out;