[wplug] umask

Mark Dalrymple wplug at badgertronics.com
Tue Apr 29 22:02:21 EDT 2003


> > (for the geeks, the umask is complemented, the bitwise ANDed with the
>> permissions the program asks for)

> If this is bitwise ANDed it would be:
> 000 010 010

Please read it again.  the umask is *complemented* (bits are
flipped), and then ANDed.  The math works.



>>  u   g  o     (user group other)
>> rwx rwx rwx   (read write execute)
>> 111 111 111   777 (octal)
>>
>> and the umask is
>> 000 010 010   022 (octal)

The complement of the umask  is
  111 101 101

Then AND that with the original, (all 1-s)
you get my original result:

>> The resulting result is
>> 111 101 101
>> or,
>> rwx r-x r-x


> So, chmod must be bitwise ANDed.

chmod doesn't use the umask:

# make a new file
% touch spoon
% ls -l spoon
-rw-r--r--  1 markd  staff  0 Apr 29 21:48 spoon

# make a umask that blocks everything
% umask 777

% chmod 666 spoon
% ls -l spoon
-rw-rw-rw-  1 markd  staff  0 Apr 29 21:48 spoon
# chmod works as expected

only new file creation uses the umask:

# how about a new file?
% touch spoon2
% ls -l spoon2
----------  1 markd  staff  0 Apr 29 21:48 spoon2
# as expected, everything blocked.



> I'm not sure, but UMASK must be bitwise ORed which gives the 111 101
> 101 result that Mark described.

bitwise OR only sets bits, it never clears them.
bitwise AND only clears bits, it never sets them. That's why
the umask complement is in there.

Cheers,
++Mark Dalrymple, markd at badgertronics.com.  http://badgertronics.com
  "s/applications/solutions/ if you are a manager."
     -- jo2y (used under the jo2y quote use license, 2003)





More information about the wplug mailing list