Hard link and disk usage

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I have an executable with size is 1 Mega in the directory /bin of a
ramdisk image.
If I make a hard link to the executable in directory /bin2 with the du
command I see that the directory /bin2 is 1 Mega (with only a file).
I don't understand the size of the directory /bin2, could anyone help
me?

Bye


Re: Hard link and disk usage

| I have an executable with size is 1 Mega in the directory /bin of a
| ramdisk image.
| If I make a hard link to the executable in directory /bin2 with the du
| command I see that the directory /bin2 is 1 Mega (with only a file).
| I don't understand the size of the directory /bin2, could anyone help
| me?

If this is in the same ramdisk filesystem, the hardlink means there is
just the one inode and just one tree of pages for the file.  But two
different directories reference the same inode.  Once a hardlink is made,
there is no distinction between them in any way; one of them can be just
as much master as the other.  Try removing the first name, and the second
one will remain, as will the file.  If you can just /bin2 with "du" it
will show as having as much space as that file takes, even though /bin
would as well.  Scan both together and it may not, depending on which
version of "du" you have.  See the -l option for recent versions of "du".

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org)  /  Do not send to the address below |
We've slightly trimmed the long signature. Click to see the full one.
Re: Hard link and disk usage
I understand that the size of a directory is just a virtual number,
adding the size of all files that are accessible within that directory.
Thus doing a hard link to an existing file in the same directory will
increase the directory size but not the used disk size. On a disk with
many hard links the size of a single directory might be much higher than
the drive capacity.

-Michael

Re: Hard link and disk usage
On Wed, 11 Apr 2007 17:19:38 +0200 Michael Schnell

| I understand that the size of a directory is just a virtual number,
| adding the size of all files that are accessible within that directory.
| Thus doing a hard link to an existing file in the same directory will
| increase the directory size but not the used disk size. On a disk with
| many hard links the size of a single directory might be much higher than
| the drive capacity.

That depends on whether the tool used to add up those numbers also takes
into account the hard links.  The "du" command I have tries to do that.
It also does it badly when hardlinks to the same file are in different
directories: it counts the whole file in the total for the first directory
but not for the next directory.  But there is no clear right way to show
this for files with hard links spanning directories.  Once the total gets
up to a parent directory covering all links to the file, then the figure
should be correct from a hard link aware "du".

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org)  /  Do not send to the address below |
We've slightly trimmed the long signature. Click to see the full one.
Re: Hard link and disk usage
As the directory entries of hard linked files does not allow for any
method to assign the file data to one of the links (they all are
perfectly identical), I feel that there is no obvious method to
calculate directory sizes in a way that the sum is in any way according
to the amount of used disk data. You _could_ divide the size of any file
by the count of links to that file to do that, but I doubt that the
resulting number is something anybody would like to know.

SO IMHO just counting the complete file sizes (to calculate the used
space when copying the directory without concern of possible hard
linking) is the way to go.

-Michael

Re: Hard link and disk usage
On Tue, 24 Apr 2007 09:29:08 +0200 Michael Schnell
| As the directory entries of hard linked files does not allow for any
| method to assign the file data to one of the links (they all are
| perfectly identical), I feel that there is no obvious method to
| calculate directory sizes in a way that the sum is in any way according
| to the amount of used disk data. You _could_ divide the size of any file
| by the count of links to that file to do that, but I doubt that the
| resulting number is something anybody would like to know.
|
| SO IMHO just counting the complete file sizes (to calculate the used
| space when copying the directory without concern of possible hard
| linking) is the way to go.

It depends on the purpose of what the size scanning is for.  If you want
to know how much space would be needed to copy directory "foo" then do
"du -s foo" and see.  That should, if all is right, give you a total of
the space needed, accounting for hardlinks _within_ "foo", assuming the
method of copying would also account for hardlinks.

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org)  /  Do not send to the address below |
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline