flying-circus / pyfilesystem

Automatically exported from code.google.com/p/pyfilesystem
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

O_CREAT should be handled in fs.base.flags_to_mode #140

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I discovered a bug when mounting an OSFS exposed over FUSE (on /mnt). A 'touch 
/mnt/foo' triggers this syscall:

open("/mnt/foo", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = -1 ENOENT (No 
such file or directory)

OSFS.open will be called with a mode 'r+' and it returns ENOENT (as it should). 
The mode should be 'w' though, not 'r+'. This is because O_CREAT is not handled 
in fs.base.flags_to_mode.

I fixed it by replacing in fs.base.flags_to_mode:

if flags & os.O_TRUNC

with:

if flags & os.O_TRUNC or flags & os.O_CREAT:

(both occurrences). It fixes the bug, although I'm not entirely sure this is 
always correct.

Original issue reported on code.google.com by cyril....@gmail.com on 9 Dec 2012 at 5:46

GoogleCodeExporter commented 9 years ago
O_CREAT|O_RDONLY is not handled properly either, but I don't think there's a 
way to map this to a correct mode. I ended up writing a wrapper to os.open, 
which solves the issue in my case (FUSE).

Original comment by cyril....@gmail.com on 23 Dec 2012 at 3:16