nathanhi / pyfatfs

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

Removal of last entry in directory leaves remnants #4

Closed nathanhi closed 3 years ago

nathanhi commented 3 years ago

If the last directory entry in a directory is removed via PyFatFS.remove(), then this entry is not properly overwritten in the filesystem, leaving a broken directory entry in place:

import fs
with fs.open_fs("/dev/sda1") as my_fs:
    my_fs.removetree("/EFI")
$ sudo mount /dev/sda1 /mnt; sudo ls -laR /mnt; sudo umount /mnt
/mnt:
ls: cannot access '/mnt/EFI': Input/output error
total 20
drwxr-xr-x 3 root root 4096 Jan  1  1970 .
drwxr-xr-x 1 root root  276 Dez 19 09:46 ..
d????????? ? ?    ?       ?            ? EFI
ls: cannot open directory '/mnt/EFI': Input/output error

Suspected cause is that with an empty byte_repr data size the erase function does not properly work and cannot align to the next biggest byte size of the directory cluster and thus does not erase the actual directory entry.