linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* d_type and bind mounts
@ 2019-02-11 19:59 Tavian Barnes
  2019-02-11 20:59 ` Dave Chinner
  0 siblings, 1 reply; 2+ messages in thread
From: Tavian Barnes @ 2019-02-11 19:59 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel

It seems that readdir()/getdents() fill d_type from the underlying
filesystem, not respecting bind mounts of non-directories:

$ touch mount_point
$ sudo mount --bind /dev/null mount_point
$ find -name mount_point -type c
$ find -name mount_point -type f
./mount_point

(Requires a fairly recent GNU findutils to reproduce, older ones
always call stat().)  I've seen similar discussions about d_ino being
for the underlying file, not the mount point, which people have said
is technically a POSIX violation but also unlikely to be fixed.  Is
the same true of d_type?  And is there some workaround a program could
use to get the actual type without the overhead of a whole stat()
call?  For example, a way to tell whether a directory entry is a mount
point?

For reference, the relevant findutils bug is
https://savannah.gnu.org/bugs/?54913.

(Please keep me cc'd, I'm not subscribed to lkml or fsdevel.  Thanks!)

-- 
Tavian Barnes

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: d_type and bind mounts
  2019-02-11 19:59 d_type and bind mounts Tavian Barnes
@ 2019-02-11 20:59 ` Dave Chinner
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Chinner @ 2019-02-11 20:59 UTC (permalink / raw)
  To: Tavian Barnes; +Cc: linux-fsdevel, linux-kernel

On Mon, Feb 11, 2019 at 02:59:29PM -0500, Tavian Barnes wrote:
> It seems that readdir()/getdents() fill d_type from the underlying
> filesystem, not respecting bind mounts of non-directories:
> 
> $ touch mount_point
> $ sudo mount --bind /dev/null mount_point
> $ find -name mount_point -type c
> $ find -name mount_point -type f
> ./mount_point
> 
> (Requires a fairly recent GNU findutils to reproduce, older ones
> always call stat().)  I've seen similar discussions about d_ino being
> for the underlying file, not the mount point, which people have said

Find is using readdir to look up the directory entry, so what it
finds is the underlying filesystem dirent that is completely unaware
that the dentry cache has an overlayed mountpoint above the
filesystem.  d_type is stored in the underlying directory, so it is
reported from the on-disk information in the underlying filesystem,
not the dentry cache that is aware of the mount point at that
location.

> is technically a POSIX violation but also unlikely to be fixed.  Is
> the same true of d_type?  And is there some workaround a program could
> use to get the actual type without the overhead of a whole stat()
> call? For example, a way to tell whether a directory entry is a mount
> point?

Not that I know of, but that doesn't mean there isn't one. In
general, though, if you are looking for something overlaid on the
underlying dirent (like a mount point) then you have to trigger a
path walk to find whatever is overlaid on that location.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-11 20:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11 19:59 d_type and bind mounts Tavian Barnes
2019-02-11 20:59 ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).