kern/94516: [patch] Add UF_HIDDEN file flag; map it to Windows "hidden" attribute for msdosfs, ntfs

Mark Day mday at apple.com
Thu Mar 16 15:08:32 UTC 2006


>Number:         94516
>Category:       kern
>Synopsis:       [patch] Add UF_HIDDEN file flag; map it to Windows "hidden" attribute for msdosfs, ntfs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 16 15:08:29 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Mark Day <mday at apple.com>
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
Apple Computer, Inc.
>Environment:
System: FreeBSD daybreak.apple.com 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Tue Mar 14 18:11:52 PST 2006 root at daybreak.apple.com:/usr/obj/usr/src-hidden/sys/DAYBREAK i386

>Description:
This adds a file flag which can be used as a hint to applications
(especially GUIs) that a particular file or directory should not be
displayed to the user by default.  For Windows file systems, this would
be mapped to their native "hidden" attribute.  For Macintosh file
systems, this would be mapped to the "invisible" bit of the Finder Info.

The patch includes a libc change to strtofflags(3) and fflagstostr(3)
mapping the bit to the name "hidden" so it can be accessed via ls(1)
and chflags(1).

The patch also maps the Windows "read-only" attribute bit to the
UF_IMMUTABLE file flag (for both msdosfs and ntfs).

This change originated in Mac OS X (in a version not yet released).
The patch is offered to help keep the file flags in FreeBSD and
Mac OS X in sync.
>How-To-Repeat:
In the Windows GUI, select a file on a FAT or NTFS volume.
Right-click on the file and select "Properties" from the menu.
Check the box titled "Hidden".
Take that disk to a FreeBSD machine and do "ls -lo" on it.
With this patch, "hidden" will be displayed.
>Fix:
See patch below.

--- hidden.diff begins here ---
diff -Naur src/bin/chflags/chflags.1 src-hidden/bin/chflags/chflags.1
--- src/bin/chflags/chflags.1	Fri Mar 10 12:37:19 2006
+++ src-hidden/bin/chflags/chflags.1	Wed Mar 15 00:50:47 2006
@@ -104,6 +104,8 @@
 set the user immutable flag (owner or super-user only)
 .It Cm uunlnk , uunlink
 set the user undeletable flag (owner or super-user only)
+.It Ar hidden
+set the user hidden flag (owner or super-user only)
 .El
 .Pp
 Putting the letters
diff -Naur src/lib/libc/gen/strtofflags.c src-hidden/lib/libc/gen/strtofflags.c
--- src/lib/libc/gen/strtofflags.c	Mon Sep 12 19:52:41 2005
+++ src-hidden/lib/libc/gen/strtofflags.c	Wed Mar 15 00:50:47 2006
@@ -71,7 +71,8 @@
 	{ "nodump",		UF_NODUMP,	1 },
 	{ "noopaque",		UF_OPAQUE,	0 },
 	{ "nouunlnk",		UF_NOUNLINK,	0 },
-	{ "nouunlink",		UF_NOUNLINK,	0 }
+	{ "nouunlink",		UF_NOUNLINK,	0 },
+	{ "nohidden",		UF_HIDDEN,	0 }
 };
 #define longestflaglen	12
 #define nmappings	(sizeof(mapping) / sizeof(mapping[0]))
diff -Naur src/lib/libc/sys/chflags.2 src-hidden/lib/libc/sys/chflags.2
--- src/lib/libc/sys/chflags.2	Sat Jul  3 22:30:09 2004
+++ src-hidden/lib/libc/sys/chflags.2	Wed Mar 15 00:50:47 2006
@@ -85,6 +85,8 @@
 The file may not be renamed or deleted.
 .It UF_OPAQUE
 The directory is opaque when viewed through a union stack.
+.It UF_HIDDEN
+The file or directory is not intended to be displayed to the user.
 .It SF_ARCHIVED
 The file may be archived.
 .It SF_IMMUTABLE
@@ -100,8 +102,9 @@
 .Dq UF_APPEND ,
 .Dq UF_NOUNLINK ,
 .Dq UF_NODUMP ,
+.Dq UF_OPAQUE ,
 and
-.Dq UF_OPAQUE
+.Dq UF_HIDDEN
 flags may be set or unset by either the owner of a file or the super-user.
 .Pp
 The
diff -Naur src/sys/fs/msdosfs/msdosfs_vnops.c src-hidden/sys/fs/msdosfs/msdosfs_vnops.c
--- src/sys/fs/msdosfs/msdosfs_vnops.c	Wed Feb  1 00:25:25 2006
+++ src-hidden/sys/fs/msdosfs/msdosfs_vnops.c	Wed Mar 15 00:50:47 2006
@@ -351,6 +351,10 @@
 	vap->va_flags = 0;
 	if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
 		vap->va_flags |= SF_ARCHIVED;
+	if (dep->de_Attributes & ATTR_READONLY)
+		vap->va_flags |= UF_IMMUTABLE;
+	if (dep->de_Attributes & ATTR_HIDDEN)
+		vap->va_flags |= UF_HIDDEN;
 	vap->va_gen = 0;
 	vap->va_blocksize = pmp->pm_bpcluster;
 	vap->va_bytes =
@@ -421,12 +425,20 @@
 			if (vap->va_flags & SF_SETTABLE)
 				return EPERM;
 		}
-		if (vap->va_flags & ~SF_ARCHIVED)
+		if (vap->va_flags & ~(SF_ARCHIVED|UF_IMMUTABLE|UF_HIDDEN))
 			return EOPNOTSUPP;
 		if (vap->va_flags & SF_ARCHIVED)
 			dep->de_Attributes &= ~ATTR_ARCHIVE;
 		else if (!(dep->de_Attributes & ATTR_DIRECTORY))
 			dep->de_Attributes |= ATTR_ARCHIVE;
+		if (vap->va_flags & UF_IMMUTABLE)
+			dep->de_Attributes |= ATTR_READONLY;
+		else
+			dep->de_Attributes &= ~ATTR_READONLY;
+		if (vap->va_flags & UF_HIDDEN)
+			dep->de_Attributes |= ATTR_HIDDEN;
+		else
+			dep->de_Attributes &= ~ATTR_HIDDEN;
 		dep->de_flag |= DE_MODIFIED;
 	}
 
diff -Naur src/sys/fs/ntfs/ntfs_vnops.c src-hidden/sys/fs/ntfs/ntfs_vnops.c
--- src/sys/fs/ntfs/ntfs_vnops.c	Tue Jan 17 17:29:02 2006
+++ src-hidden/sys/fs/ntfs/ntfs_vnops.c	Wed Mar 15 00:50:47 2006
@@ -196,7 +196,11 @@
 	vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
 	vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
 	vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
-	vap->va_flags = ip->i_flag;
+	vap->va_flags = 0;
+	if (fp->f_fflag & NTFS_FFLAG_RDONLY)
+		vap->va_flags |= UF_IMMUTABLE;
+	if (fp->f_fflag & NTFS_FFLAG_HIDDEN)
+		vap->va_flags |= UF_HIDDEN;
 	vap->va_gen = 0;
 	vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
 	vap->va_type = vp->v_type;
diff -Naur src/sys/sys/stat.h src-hidden/sys/sys/stat.h
--- src/sys/sys/stat.h	Tue Mar 22 01:19:18 2005
+++ src-hidden/sys/sys/stat.h	Wed Mar 15 00:50:47 2006
@@ -282,6 +282,8 @@
 #define	UF_APPEND	0x00000004	/* writes to file may only append */
 #define UF_OPAQUE	0x00000008	/* directory is opaque wrt. union */
 #define UF_NOUNLINK	0x00000010	/* file may not be removed or renamed */
+#define UF_HIDDEN	0x00008000	/* hint that this item should not be */
+					/* displayed in a GUI */
 /*
  * Super-user changeable flags.
  */
--- hidden.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list