-
November 30th, 2007, 09:12 PM
#1
NTFS hard links !!
Here is a gist of the problem:
I have a program which reads every file. But if a file also has a hardlink to it, my program will end up reading the file twice ! I want to prevent that, but I dont know how to go about it !!
Details:
An NTFS hard link can be created by using the CreateHardLink() API. But the way hardlinks are implemented I do not know how to solve my problem.
If you have the time you can read a little about hard links here:
http://msdn2.microsoft.com/en-us/library/aa365006.aspx
A little bit about how hard links are implemented:
http://www.microsoft.com/msj/1198/ntfs/ntfs.aspx (scroll to the bottom where they talk about hardlinks and read about how they are stored in the MFT).
Is there any API that would allow me to find out whether a file is actually a hard link ? (For e.g: GetFileAttribute() tells me about symbolic links)
This is how I would do it on a UNIX system:
The original file and all hard links to it have the same inode number. So I would store the inode number of the first file, then for every other file check if its inode number already exists, if so then its a hard link and I can ignore it, or else store the inode number.
But in NTFS there is no concept of inode number.
The only thing I got is: GetFileInformationByHandle() which give me the number of links to a file.
Thanks for reading my query.
Any kind of help will be appreciated !
-
December 2nd, 2007, 01:38 PM
#2
-
December 2nd, 2007, 01:51 PM
#3
Re: NTFS hard links !!
Originally Posted by the_learner
But in NTFS there is no concept of inode number.
Yes there is. It's called a File Reference Number. To get it you need to call NtQueryInformationFile for FILE_INTERNAL_INFORMATION. It's documented in the Windows Driver Kit.
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. -- Robert Firth
-
December 2nd, 2007, 02:01 PM
#4
Re: NTFS hard links !!
thanks googler !!! I will have a look... !!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|