develooper Front page | perl.perl5.porters | Postings from December 2003

Re: [PATCH] Re: perl @ 21830

Thread Previous | Thread Next
Jody Belka
December 4, 2003 03:36
Re: [PATCH] Re: perl @ 21830
Message ID:
Steve Hay said:
> Rafael Garcia-Suarez wrote:
>>Depends. How can we test if two files are identical, link()-wise,
>>on MSWin32 ? If we can test it, we should fix by adding
>>another branch to the if() :
>>    elsif ($^O eq 'MSWin32' && $Config{d_link}) {...}
>>If we can't, we should fix the test so it's skipped on Windows.
> I can't think of any way to test it.  File::Copy uses the inode on other
> platforms to test hardlinks, but this is always returned as 1 on
> MSWin32.  The Microsoft documentation for stat() notes: "The inode, and
> therefore st_ino, has no meaning in the FAT, HPFS, or NTFS file systems."

There is a way to test this on windows. Basically, you have to get file
handles for both files using CreateFile, and then call
GetFileInformationByHandle on both of them. This function returns a
pointer to a BY_HANDLE_FILE_INFORMATION structure which contains three
important members:

    Serial number of the volume that contains the file.

    High-order part of a unique identifier associated with the file.

    Low-order part of a unique identifier associated with the file.

To quote on FileIndex from the BY_HANDLE_FILE_INFORMATION reference,

Note that this value is useful only while the file is open by at least one
process. If no processes have it open, the index may change the next time
the file is opened.

The identifier (low and high parts) and the volume serial number uniquely
identify a file on a single computer. To determine whether two open
handles represent the same file, combine this identifier and the volume
serial number for each file and compare them.

References for all of the above:

CreateFile -
GetFileInformationByHandle -


Jody Belka
knew (at) pimb (dot) org

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About