exfat icon indicating copy to clipboard operation
exfat copied to clipboard

Using O_SYNC parameter in Python isn't working with exfat drive

Open egfconnor opened this issue 7 years ago • 3 comments

I copy a file in Python to removable drives using O_SYNC and it's not working for exfat formatted drives. If I format the same drive to ext4 or fat32 it works and synchronous writes happen. With exfat though it seems to use the file system cache and wait for a sync command to actually write.

Python code:

fsrc = os.open(source, os.O_RDWR)
fdst = os.open(destination, os.O_CREAT | os.O_SYNC | os.O_RDWR)

while True:
    buf = os.read(fsrc, 1048576)
    if not buf:
        break
    os.write(fdst, buf)

egfconnor avatar Dec 18 '17 16:12 egfconnor

Looks like there's no way to handle O_SYNC in FUSE.

relan avatar Dec 19 '17 18:12 relan

@relan that's unfortunate. Thanks for the quick reply though.

egfconnor avatar Dec 20 '17 13:12 egfconnor

Maybe this helps someone else but I ended up with my desired behavior by adding:

os.fsync(fdst)

after each os.write call. This effectively writes the data each loop iteration like I want.

egfconnor avatar Dec 20 '17 18:12 egfconnor