[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in handling hard links in bind-mounted directories

From: Derek Pressnall
Subject: Re: Bug in handling hard links in bind-mounted directories
Date: Wed, 12 Jan 2022 16:50:44 -0600

> Tar uses link count to decide whether a file might be a hard link to
> another file.  In this test case, link count of bleh is 1, so it skips
> hardlink detection phase.  To force hardlink detection, use the -h
> (--dereference) option:

It appears this behavior is set in the trivial_link_count variable in
create_archive(), and this variable is set to 1 if a single file name
is specified on the command line, otherwise it is set to 0 which
causes tar to track the devid/inode of all files in a hash table,
instead of just the ones that have a link count greater than 1.  My
assumption was that this logic (to track inodes for all files if more
than one file was listed) was put in place to handle cases where there
may be a bind mount (may be a bad assumption on my part though).
Based on that, though, the logic could be updated to see if there are
any bind mounts contained in the passed in file names, then set
trivial_link_count to 0 if that is true.  Otherwise leave it at 1, so
that additional memory doesn't always need to be taken up if there is
no chance of bind mounts appearing.

If I'm wrong in the purpose of trivial_link_count getting set to 0
when more than one file is provided, then what would be that purpose?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]