Subject: tools/compat/getmode.c and nbmknod.
To: None <>
From: Simon Burge <>
List: tech-toolchain
Date: 01/08/2004 23:34:41
The getmode() function takes two args - the first is the new rwx
permission bits and the second is the original mode bits to modify.  The
current compat getmode() just returns effectively the first argument,
ignoring all the original bits.  This might have worked for whatever
other host tools used getmode()/setmode(), but fails badly for tools
version of mknod because the second arg that mknod passes to getmode()
includes the file type bits which are then ignored!

The following patch uses the RWX bits (plus the set{u,g}id and sticky
bits - this set of bits is "ALLPERMS" which is defined for tools in
compat_defs.h) from the modifier (first arg) and the rest of the bits
from the original mode bits (the second arg) and seems to do the right
thing for the testing I've done so far - nbinstall still works and
nbmknod now actually works.

Anyone see anything wrong this?  I'll commit it in a day or three if

Simon Burge                                   <>
NetBSD Development, Support and Service:

Index: getmode.c
RCS file: /cvsroot/src/tools/compat/getmode.c,v
retrieving revision 1.4
diff -d -p -u -r1.4 getmode.c
--- getmode.c	8 Jan 2004 12:16:09 -0000	1.4
+++ getmode.c	8 Jan 2004 12:25:02 -0000
@@ -52,6 +52,12 @@ setmode(const char *str)
 getmode(const void *mp, mode_t mode)
+	mode_t m; 
-	return *((const mode_t *)mp);
+	m = *((const mode_t *)mp);
+	mode &= ~ALLPERMS;	/* input mode less RWX permissions */
+	m &= ALLPERMS;		/* new RWX permissions */
+	return m | mode;