Sat 01 May 2010 03:50:37 PM UTC, original submission:
Similar to the problem with chown()'ing documented in #29514 (https://savannah.gnu.org/bugs/?29514) , there is also a problem with chmod'ing.
Upon trying to edit a file on a fat32 file system with nano 2.2.2, I get this error:
Error writing backup file /media/common/wifi.txt~: Operation not permitted, and the save aborts (the backup and "real" files on disk remain unchanged).
We can rule out a simple permissions problem:
ski@ganiodayo:~$ ls -l /media/common/wifi.txt
-rwxrwx--- 1 root plugdev 2407 2008-10-23 01:16 /media/common/wifi.txt
ski@ganiodayo:~$ id
uid=1000(ski) gid=1000(ski) groups=4(adm),20(dialout),24(cdrom),46(plugdev),104(fuse),106(lpadmin),121(admin),122(sambashare),1000(ski)
ski@ganiodayo:~$ echo foo >/media/common/wifi.txt
#gives no error
An strace provides this snippet:
open("/media/common/wifi.txt~", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
chmod("/media/common/wifi.txt~", 0100770) = -1 EPERM (Operation not permitted)
If chmod fails (as with chown in #29514), we should warn but proceed anyway - because it is entirely possible that we can write to, but can't chmod, the file. In addition to fat32, we can reproduce this bug using file access control lists (getfacl/setfacl) like so:
ski@ganiodayo:~$ sudo touch /tmp/foo /tmp/foo~
ski@ganiodayo:~$ sudo chown root:root /tmp/foo /tmp/foo~
ski@ganiodayo:~$ sudo setfacl -m u:ski:rw /tmp/foo /tmp/foo~
ski@ganiodayo:~$ cat /tmp/foo
ski@ganiodayo:~$ echo 1 >/tmp/foo
ski@ganiodayo:~$ cat /tmp/foo
1
ski@ganiodayo:~$ nano /tmp/foo #try to write "2" and exit, get EPERM
ski@ganiodayo:~$ cat /tmp/foo
1
|