stat_result.st_ino from os.stat isn't constant on a network drive.

Eryk Sun eryksun at gmail.com
Wed Aug 26 05:14:10 EDT 2020


On 8/25/20, Andrew Nelson <andyfaff at gmail.com> wrote:
>
> st_ino is supposed to "uniquely identify the file for a given value of
> st_dev."

That assurance only applies to POSIX systems, not Windows.

st_ino is the file ID in Windows. Some filesystems do not support
reliable file IDs, if any at all. I would only rely on the st_ino
value if the filesystem flags include FILE_SUPPORTS_OPEN_BY_FILE_ID.
You can get the filesystem flags via GetVolumeInformationByHandleW,
using a handle for any file in the filesystem.

For example, FAT filesystems use a semi-stable file ID, which is based
on a file's byte offset in the parent directory. This offset can can
change if the filesystem is defragmented, so FAT file IDs are
unreliable. This is probably why FAT filesystems do not support
opening by file ID. Another example is the WebDAV filesystem, which
doesn't support file IDs at all, so the value is 0 for all files.

st_dev is the volume serial number (VSN) in Windows. Like the file ID,
filesystems are not required to support a VSN, in which case it may be
0 (e.g. it's 0 for WebDAV). Even if the VSN is supported, Windows does
not guarantee that the value is unique. It's a random 32-bit number,
so it's unlikely that a non-zero value isn't unique, but there's no
hard guarantee.


More information about the Python-list mailing list