The FileIndex consists of two parts: the low 48 bits are the file record number and contain the actual index in the MFT; the high 16 bits are the socalled sequence number: each time the entry in the MFT is reused for another file, the sequence number is increased by one.
The GnuWin32 implementation of stat can be found in io/hxstat64.c and associated files in the LibGw32C package. It uses a series of functions in order to deal with large files (> 4GB), and the problems described above. If these adaptations are not relevant, you had probably best use the standard stat function from msvcrt.dll and separately create an inode number as follows:
#include <sys/stat.h>
#include <io.h>
#include <stdint.h>
#include <windows.h>
#define LODWORD(l) ((DWORD)((DWORDLONG)(l)))
#define HIDWORD(l) ((DWORD)(((DWORDLONG)(l)>>32)&0xFFFFFFFF))
#define MAKEDWORDLONG(a,b) ((DWORDLONG)(((DWORD)(a))|(((DWORDLONG)((DWORD)(b)))<<32)))
#define INOSIZE (8*sizeof(ino_t)) #define SEQNUMSIZE (16)
ino_t getino (char *path) { BY_HANDLE_FILE_INFORMATION FileInformation; HANDLE hFile; uint64_t ino64, refnum; ino_t ino; /* obtain handle to file "path" FILE_FLAG_BACKUP_SEMANTICS is used to open directories */ if (!path || !*path) /* path = NULL */ return 0; if (access (path, F_OK)) /* path does not exist */ return -1; hFile = CreateFile (path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_READONLY, NULL); ZeroMemory (&FileInformation, sizeof(FileInformation)); GetFileInformationByHandle (hFile, &FileInformation); ino64 = (uint64_t) MAKEDWORDLONG ( FileInformation.nFileIndexLow, FileInformation.nFileIndexHigh); refnum = ino64 & ((~(0ULL)) >> SEQNUMSIZE); /* remove sequence number */ /* transform 64-bits ino into 16-bits by hashing */ ino = (ino_t) ( ( (LODWORD(refnum)) ^ ((LODWORD(refnum)) >> INOSIZE) ) ^ ( (HIDWORD(refnum)) ^ ((HIDWORD(refnum)) >> INOSIZE) ) ); CloseHandle (hFile); return ino; }
An inode for fstat can be implemented similarly, by obtaining the handle from the file descriptor:
/* obtain handle to file descriptor "fd" */ hFile = _get_osfhandle (fd);
Kees Zeelenberg
----- Original Message ----- From: "Torsten Kurbad" <[EMAIL PROTECTED]>
To: <gnuwin32-users@lists.sourceforge.net>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, April 14, 2005 5:55 PM
Subject: [GnuWin32-Users] How does coreutils/stat "calculate" an inode on win32 filesystems?
Hello,
we are having a weird problem here:
While developing a portable python application (runs on Linux, MacOS X, and
Win32) we came across the fact, that the MS Visual C libraries always return
"0" as inode value for statbuf->st_ino (and so does python). Nevertheless,
the "stat" command of the win32 coreutils returns a value != 0 for the inode
number and behaves exactly like stat on Posix-Systems. We'd need exactly
that behavior for our project, but we are not quite geniuses in
C-programming... ;o)
Thus, can someone give a hint, where to find the appropriate function in coreutils that returns a valid inode number?
Thanks in advance! Best regards, Torsten
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ GnuWin32-Users mailing list GnuWin32-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gnuwin32-users
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ GnuWin32-Users mailing list GnuWin32-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gnuwin32-users