btrfs-progs: fix fi du so it works in more cases
authorAustin S. Hemmelgarn <ahferroin7@gmail.com>
Mon, 21 Mar 2016 12:23:11 +0000 (08:23 -0400)
committerDavid Sterba <dsterba@suse.com>
Wed, 30 Mar 2016 14:22:53 +0000 (16:22 +0200)
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>
cmds-fi-du.c

index 2ffd917..168fc72 100644 (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;