From: Michael Tokarev <mjt@tls.msk.ru>
To: "Pádraig Brady" <P@draigBrady.com>
Cc: Linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Detecting bind-mounts
Date: Fri, 05 Nov 2010 23:30:11 +0300 [thread overview]
Message-ID: <4CD46953.1010902@msgid.tls.msk.ru> (raw)
In-Reply-To: <4CD44D60.5050105@msgid.tls.msk.ru>
05.11.2010 21:30, Michael Tokarev wrote:
> 05.11.2010 13:24, Pádraig Brady wrote:
>> On 04/11/10 20:45, Michael Tokarev wrote:
> []
>>> There are 2 (mostly) different kinds of applications. One
>>> is cp/tar/find with --same-filesystem option (or equivalent),
>>> that should not cross mountpoints. And one more, apps like
>>> mountpoint(1) from sysvinit - a utility to determine if a
>>> given path is a mountpoint.
>>>
>>> Neither of the two work when two directores on the same
>>> filesystem are bind-mounted.
> []
>> The `stat` command recently got support for
>> printing the mount point for a file:
>> http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commit;h=ddf6fb86
>>
>> `stat` will output the alias for a bind mounted file
>> while `df` will output the initial mount point of its backing device
>> So you could do something like:
>>
>> file=.
>> df_mnt=$(df -P "$file" | sed -n '2s/.* \([^ ]*$\)/\1/p')
>> stat_mnt=$(stat -c%m "$file")
>> test "$df_mnt" = "$stat_mnt" || echo "bind mount"
>
> This is incorrect in two ways.
>
> First of all, stat(1), even after that commit you quote,
> still compares st_dev fields, which are the same for this
> and parent directory in case of bind mount. So this version
> of stat(1) does _not_ detect a bind mount, unfortunately.
And this statement, in turn, is untrue. I apologize for the
misinformation, it wasn't intentional. The mentioned commit
adds the ability to detect bind mounts indeed. but...
> Second, I asked for a low-level way to detect such a mount.
> I know how to do it not as efficient as stat(2) and not as
> reliable but much simpler than you propose above, in shell
> or in C, and I already provided that way in my original
> email: we just parse /proc/mounts file, this is faster and
> more reliable than the above shell fragment which calls a
> few external commands.
.. the way used by stat(1) is to enumerate /proc/mounts --
which is what I were able to come with initially. It is slow
and unreliable. Hence I asked if a faster way exist.
/mjt
next prev parent reply other threads:[~2010-11-05 20:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-04 20:45 Detecting bind-mounts Michael Tokarev
2010-11-05 10:24 ` Pádraig Brady
2010-11-05 18:30 ` Michael Tokarev
2010-11-05 20:30 ` Michael Tokarev [this message]
2010-11-06 0:32 ` Pádraig Brady
2010-11-06 0:47 ` Michael Tokarev
2010-11-06 10:57 ` Pádraig Brady
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CD46953.1010902@msgid.tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=P@draigBrady.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.