Re: singular hard links
Re: singular hard links
- Subject: Re: singular hard links
- From: Hex Star <email@hidden>
- Date: Sun, 2 Oct 2005 16:43:16 -0700
http://www.askdavetaylor.com/how_do_unix_linux_hard_links_work.html
from that url:
A reader writes:
So, I'm partway through your book, and I want to check on hard links.
When you say it creates another door to the same body of data, is that
literally true? For example, if all I have in my ./Documents directory
is 001.doc (size 512K), and I hard link as hardlink.doc then run ls,
do I see A or B?
A) 001.doc 512K
hardlink.doc 512K
total 1024K
B) 001.doc 512K
hardlink.doc 512K
total 512K
If it's not B, I'm not sure what the point is, other than maybe not
changing the timestamp.
Answer:
An interesting question! The main point of hardlinks is to allow a
single data entity to be shared by multiple entries in the file
system. If I saved this posting as "001.html" on my server, then
created a hard link to the same file from "002.html", then I could
subsequently delete "001.html" and "002.html" would be unaffected,
with the same contents within. It's only when all links to a data
entity are removed that the data gets hooked into the free list and is
essentially recycled for later reuse.
In terms of your specific question, the system will view the two files
as having separate content. This can be demonstrated thusly:
$ du
249 .
$ ls -l
total 248
-rw-r--r-- 1 dtint vuser 247034 Aug 24 03:24 some.data
Now let's create some hard links. Notice "ls" reports 248 blocks in
this directory
$ ln some.data link2
$ ln some.data link3
$ ln some.data link4
$ ls -l
total 992
-rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 link2
-rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 link3
-rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 link4
-rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 some.data
As expected, "ls" now reports 992 blocks in use, seeing each of the
new hard linked
files as new data. But... notice what "du" reports, since it actually
looks deeper into
the file system:
$ du
249 .
As you can see, some elements of the file system see hard links as new
and separate data entities (e.g. "ls"), while others dig further into
the file system to ascertain actual data blocks used and associated
with the current location (e.g., "du"). This makes sense because
otherwise if you had lots of hard links you could theoretically end up
in a situation where you have greater than 100% disk space
utilization, which would clearly be a bit confusing at best!
On 10/2/05, Gerriet M. Denkmann <email@hidden> wrote:
> When I do:
> touch /tmp/a1
> ln /tmp/a1 /tmp/a2
> rm /tmp/a2
>
> I get a hard link with a link count (NSFileReferenceCount) of 1.
>
> When I do:
> touch //tmp/b1
>
> I get a normal file which also has a link count of 1.
>
> Why should I care? Well, firstly because I am curious, and also:
> -[NSDocument writeWithBackupToFile: ofType:saveOperation:
> NSSaveOperation ] fails for singular hard links.
>
> So I would like to detect this case beforehand.
>
>
> Kind regards,
>
> Gerriet.
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden