MSDOS Filesystem question related to "read-only" files
Conrad Meyer
cem at freebsd.org
Mon Nov 20 20:51:17 UTC 2017
On Mon, Nov 20, 2017 at 12:02 PM, Karl Denninger <karl at denninger.net> wrote:
> root at Test-MCP:/mnt # ls -al
> ...
> -rwxr-xr-x 1 hdmcp wheel 127979 Nov 19 22:54
> cam2-2017-11-19-22-54-47.jpg
> ...
> root at Test-MCP:/mnt # chmod u-w *
> root at Test-MCP:/mnt # ls -al
> ...
> -rwxr-xr-x 1 hdmcp wheel 127979 Nov 19 22:54
> cam2-2017-11-19-22-54-47.jpg
> ...
> Nope. The "w" is still there.
>
> No error returned from the "chmod" command (or if I call it from a C
> program) but the file mode is NOT changed whether I'm doing it as the
> superuser or as the owner of the file (and directory)
Indeed, msdosfs does not reflect the READONLY attribute back to
userspace in the form of the mode. That's a bug that could be fixed
pretty easily:
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -287,6 +287,8 @@ msdosfs_getattr(struct vop_getattr_args *ap)
vap->va_fileid = fileid;
mode = S_IRWXU|S_IRWXG|S_IRWXO;
+ if ((dep->de_Attributes & ATTR_READONLY) != 0)
+ mode &= ~(S_IWUSR|S_IWGRP|S_IWOTH);
vap->va_mode = mode &
(ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask);
vap->va_uid = pmp->pm_uid;
However, despite 'ls' showing 'w', it *does* set the READONLY
attribute on the file. Try invoking ls(1) with '-o' and looking for
the "rdonly" or "readonly" flag.
Best,
Conrad
More information about the freebsd-fs
mailing list