dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: NTFS hard links !!

  1. #1
    Join Date
    Jul 2007
    Posts
    41

    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 !

  2. #2
    Join Date
    Jul 2007
    Posts
    41

    Re: NTFS hard links !!

    Hello ??

    Any thoughts ??

  3. #3
    Join Date
    Dec 2005
    Posts
    642

    Lightbulb Re: NTFS hard links !!

    Quote 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

  4. #4
    Join Date
    Jul 2007
    Posts
    41

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)