nathanhi / pyfatfs

Python based FAT12/FAT16/FAT32 implementation with VFAT support
https://pypi.org/project/pyfatfs/
MIT License
31 stars 14 forks source link

Time deserialization loses high bit of minutes field #26

Closed dcoshea closed 2 years ago

dcoshea commented 2 years ago

With pyfatfs checked out from the bugfix/dentry_ordering branch as at 96ae6bc, I found that PyFatFS.setinfo(path, {"details": {"modified": value}}) seemed to work despite the "Not yet properly implemented." docstring, but only partly.

While investigating that, I found this, which I think is the root cause of the issue I was seeing:

>>> pyfatfs.DosDateTime.DosDateTime.deserialize_time(31 << 5)
datetime.time(0, 31)
>>> pyfatfs.DosDateTime.DosDateTime.deserialize_time(32 << 5)
datetime.time(0, 0)

The most significant bit of the minutes field is lost. https://wiki.osdev.org/FAT says that the minutes field is stored in 6 bits, so the bit mask used is wrong, and this trivial fix seems to help:

-        minute = (tm >> 5) & ((1 << 5) - 1)
+        minute = (tm >> 5) & ((1 << 6) - 1)
nathanhi commented 2 years ago

Fixed with v1.0.5