linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Steigerwald <martin@lichtvoll.de>
To: fdmanana@gmail.com
Cc: "dsterba@suse.cz" <dsterba@suse.cz>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: number of hardlinks for directory in ls -lid always 1?
Date: Fri, 27 Mar 2015 11:13:18 +0100	[thread overview]
Message-ID: <5158437.uj9bTtxEzW@merkaba> (raw)
In-Reply-To: <CAL3q7H5ycuGP=LFsC0Pm7uhO5OxrjzLfEXq-wkVZMHd9rJ5Bkw@mail.gmail.com>

Am Freitag, 20. März 2015, 12:59:14 schrieb Filipe David Manana:
> On Fri, Mar 20, 2015 at 12:39 PM, David Sterba <dsterba@suse.cz> wrote:
> > On Thu, Mar 19, 2015 at 09:47:15PM +0000, Filipe David Manana wrote:
> >> On Thu, Mar 19, 2015 at 1:21 PM, David Sterba <dsterba@suse.cz> 
wrote:
> >> > On Wed, Mar 18, 2015 at 03:23:50PM +0100, Martin Steigerwald wrote:
> >> >> It explains that having a correct hardlink number for directory is
> >> >> not
> >> >> mandatory, but it doesn´t explain why BTRFS always has 1 in there
> >> >> instead of the actual count of hardlinks. Is this an performance
> >> >> optimization for BTRFS or are there any other reasons why BTRFS
> >> >> does it this way?>> > 
> >> > I believe it's for performance reasons. New inodes do not update
> >> > the
> >> > parent directory metadata wrt link counts, compared to other
> >> > filesystems that do that.
> >> 
> >> Weird. Because creating a new inode implies adding the dentry to the
> >> parent directory, which implies updating the directory's i_size.
> > 
> > I wonder why the link count is not maintained then. The directory
> > inode
> > is modified anyway, add a few ifs here and there will not make things
> > worse and we could get rid of this special behaviour, plus find could
> > use the link count reliably.
> > 
> > It can be turned on in a fully backward compatible way:
> > 
> > * new directories/subvolumes will get dir nlink set to 2
> > * if mkdir/rmdir/move sees a parent link count of 1, no change
> > * otherwise inc/dec the link count for new subdirectoris/subvolumes
> > 
> > Jeff Liu reported a problem, without further details
> > http://article.gmane.org/gmane.comp.file-systems.btrfs/14628
> > 
> > so I still might be missing something.
> 
> Maybe this was all before delayed inodes were introduced, where
> updating inode items always implied touching the btrees.

Interesting.

Well this came up due to an exercise to find all hardlinks to /usr/local 
in a Linux training. And one participant of the training did this on a 
SLES 11 SP 3 VM with BTRFS.

I did some search and indeed see nothing about link count for directories 
related to POSIX standard. Incrementing link count only seems to be 
mentioned for files:

http://pubs.opengroup.org/onlinepubs/009695399/functions/link.html

Even when people tend to rely on this behavior for forensics as in:

http://digital-forensics.sans.org/blog/2009/06/19/directory-link-counts-and-hidden-directories/

Ciao,
-- 
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de
GPG: 03B0 0D6C 0040 0710 4AFA  B82F 991B EAAC A599 84C7

      reply	other threads:[~2015-03-27 10:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17 13:33 number of hardlinks for directory in ls -lid always 1? Martin Steigerwald
2015-03-17 16:07 ` David Sterba
2015-03-18 13:31   ` Martin Steigerwald
2015-03-18 13:52     ` David Sterba
2015-03-18 14:23       ` Martin Steigerwald
2015-03-19 13:21         ` David Sterba
2015-03-19 21:47           ` Filipe David Manana
2015-03-19 23:02             ` Kai Krakow
2015-03-20 10:44             ` David Sterba
2015-03-20 12:39             ` David Sterba
2015-03-20 12:59               ` Filipe David Manana
2015-03-27 10:13                 ` Martin Steigerwald [this message]

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=5158437.uj9bTtxEzW@merkaba \
    --to=martin@lichtvoll.de \
    --cc=dsterba@suse.cz \
    --cc=fdmanana@gmail.com \
    --cc=linux-btrfs@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 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).