In both cifs_get_inode_info() and fill_in_inode(), the cifs client checks for the presence of the ATTR_READONLY bit, and turns off the "w" bits in the mode if it's present. Unfortunately, if it does *not* detect this bit then it doesn't reenable any sort of write permissions on the file. To reproduce this: 1) use CIFS to mount a samba share that does not have unix extensions enabled (making sure that file_mode allows write bits) 2) On the server, create a file in this directory, make sure at least one write bit is set in the mode 3) stat this file on the client 4) on the server remove the write bits from the mode (chmod 0444 testfile) 5) stat the file on the client, write bits should be removed from the mode 6) add the write bits back (chmod 0666 testfile) 7) stat the file again on the client, the write bits are not reenabled There is virtually no way to get write permissions back on the inode short of renaming the file on the server, stat'ing the original filename on the client (and letting that fail), and then moving the file back. I'll be posting a patch shortly to address this...
Created attachment 2322 [details] patch to enable any mode bits allowed by mnt_file_mode if ATTR_READONLY isn't set I'm not certain that this is the right logic here, but it seems reasonable: If unix extensions were not negotiated, ATTR_READONLY is not set on the file, and no write bits are set in the mode, then we assume that the ATTR_READONLY flag was previously on for this file. We then turn on any permission bits allowed by the mnt_file_mode. If this isn't a safe assumption (I've really not delved too deeply into the CIFS code, so this might not be), then another option might be to track ATTR_READONLY in some cifs-private area of the inode... This patch was actually done by Alan Tyson at HP, but he asked that I push this upstream for him. I'll also post this to the linux-cifs-client mailing list...
It's, of course, also possible reproduce this with a windows server, but rather than changing the file mode on the server, you'll right click on the file in the explorer and check and uncheck the 'Read Only' checkbox.
Patch posted to linux-cifs-client@samba.org and LKML: Subject: [PATCH] CIFS: reset file mode when CIFS client notices that ATTR_READONLY is no longer set
Merged into cifs-2.6.git tree (so it should reach mm soon) Will push to mainline after a bit in -mm tree If you consider it a serious problem, we can try to merge it to mainline faster