HydrogenAudio

Misc. => Off-Topic => Topic started by: jcoalson on 2006-10-20 05:41:43

Title: need windows-specific help for FLAC
Post by: jcoalson on 2006-10-20 05:41:43
this is pretty far off-topic but I'm hoping someone familiar with win APIs here will see it...

flac (1.1.3) needs to be able to figure out if two filenames refer to the same file.  in POSIX this is easy, you just stat() both of them and compare st_dev and st_ino (device and inode).  but at least for me on NT4 with MSVC6 the inode is always 0.

so does anyone know what the win-specific way to do this?  I question being able to get it right by just trying to normalize the file names with the current working directory.

Josh
Title: need windows-specific help for FLAC
Post by: Egor on 2006-10-26 20:13:07
but at least for me on NT4 with MSVC6 the inode is always 0.

Quote
The inode, and therefore st_ino, has no meaning in the FAT, HPFS, or NTFS file systems.


so does anyone know what the win-specific way to do this?

hope this will be useful

GetFileInformationByHandle (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp), BY_HANDLE_FILE_INFORMATION (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp), CreateFile (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp).
Quote
nFileIndexHigh
High-order part of a unique identifier that is associated with a file. For more information, see nFileIndexLow.
nFileIndexLow
Low-order part of a unique identifier that is associated with a file.

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 that 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.

Quote
#include <Windows.h>
#include <Winbase.h>
...
HANDLE hFile = CreateFile("D:\\audio\\flac.exe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
BY_HANDLE_FILE_INFORMATION info;
GetFileInformationByHandle(hFile, &info);
CloseHandle(hFile);
printf("File info %ld-%ld\n", info.nFileIndexHigh, info.nFileIndexLow);
Title: need windows-specific help for FLAC
Post by: jcoalson on 2006-10-26 21:30:42
whew, thanks!  I'll try that.

Josh
Title: need windows-specific help for FLAC
Post by: jcoalson on 2006-11-02 04:08:04
cool, it works, just checked it in.