PATCH: File::Stat#dev on Windows
Two files are identical when pairs of File::Stat#dev and File::Stat#ino
are same on unix. However when a volume (disk partition) is mounted on
a directory they may not identical even when the pairs are same on Windows
because File::Stat#dev is based on drive letters.
I did the following on Windows on vmware.
- attach a new virtual disk to the VM.
- create two NTFS volumes in the disk and mount them to c:\volume1 and c:\volume2 respectively.
- create two files in c:\volume1 and c:\volume2 respectively.
- File.stat(filename).dev returns 2 ('C' - 'A') for both files.
- File.stat(filename).ino returns 281474976710691 for both files. The inode number of firstly created file in NTFS seems same.
- The pairs of #dev and #ino are same even though the files aren't identical.
The attached patch do the followging:
- change _dev_t to 64-bit rb_dev_t in struct stati128.
- use FILE_ID_INFO.VolumeSerialNumber (64-bit) or BY_HANDLE_FILE_INFORMATION.dwVolumeSerialNumber (32-bit) as File::Stat#dev.
- use path_drive() only when open_special() fails.
- delete code which become unnecessary by above changes.
However, I think, there are pros and cons of the patch.
- Two files are identical when pairs of File::Stat#dev and File::Stat#ino are same as on unix
- File::Stat#dev returns too large number (32-bit or 64-bit integer).
- In manual File::Stat#dev returns an integer representing the device. However this patch makes it return volume serial number, whose concept is a bit difference from device.