Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Deleting a read-only hard link

6 views
Skip to first unread message

Ivo Beltchev

unread,
Nov 2, 2009, 3:55:59 PM11/2/09
to
Hi

I have 2 files, lets say FILE1 and FILE2. I want to have a hard link
FILE3 that points to one or the other (and switch between them from time
to time).

I switch the link from FILE1 to FILE2 by deleting FILE3 and creating a
new hard link also called FILE3 that points to FILE2.

Now the problem is when FILE1 is read-only. I can't delete my hard link
without making it writable first. But that will make the original file
also writable.

Is there any trick to do what I want without messing up the
read-onlyness of the original files?

One way is to restore the attributes of FILE1, but in the general case I
don't know where it is, and it may even be deleted. Is there a way to
locate the original file from a hard link? Or more accurately - is there
a way to locate another hard link to the same file if one exists?

Thanks
Ivo

P.S. I tried this in Explorer - I created a read-only file, created a
hard link to it, then deleted the hard link and emptied the Recycle Bin.
The original file was then writable.

Alexander Grigoriev

unread,
Nov 2, 2009, 11:17:36 PM11/2/09
to
Your best bet is to use a symbolic link instead.

"Ivo Beltchev" <i...@home.com> wrote in message
news:Olu6i7$WKHA...@TK2MSFTNGP04.phx.gbl...

Ivo Beltchev

unread,
Nov 3, 2009, 3:38:59 AM11/3/09
to
So there is no way to "undo" the creation of a hard link for read-only
files?

Symbolic links won't work for me. I want to be able to replace the
original files (by deleting them and re-creating them) without affecting
the hard link. As far as I understand, a symbolic link will be updated
when the source file is replaced.

Basically I want a transparent "copy on write" scheme with as few quirks
and side effects as possible. Currently I am copying the files normally
(CopyFile) but I want to make it faster when possible because the files
can be quite large.

Pavel A.

unread,
Nov 3, 2009, 7:26:44 AM11/3/09
to
AFAIK transparent "copy on write" can't be done with hard or symbolic links.
For this you need something like a filesystem filter driver.

--pa


"Ivo Beltchev" <i...@ivo.com> wrote in message
news:OjNrXEGX...@TK2MSFTNGP04.phx.gbl...

Alexander Grigoriev

unread,
Nov 3, 2009, 10:02:32 AM11/3/09
to

No. Symbolic link is a reparse point. It may even point to nowhere, to
non-existing file. You can delete the original file as you wish, the link
won't change.

If you want faster copy, forget CopyFile, especially under XP and Vista.
Win7 might have gotten better file copy implementation. Write your own
non-buffered (FILE_FLAG_NO_BUFFERING), large chunks copy routine. DON'T use
FILE_FLAG_WRITE_THROUGH. You'll be able to get then half of the disk
sustained transfer rate, without nasty side effects of file cache bloat
(which kills XP CopyFile).

"Ivo Beltchev" <i...@ivo.com> wrote in message
news:OjNrXEGX...@TK2MSFTNGP04.phx.gbl...

0 new messages