Search code examples
unixdata-structuresbit-manipulationbitwise-operators

How can the SETUID bit be turned on by a 12-bit mask in a 11-bit field?


In Operating Systems Design and Implementation by Andrew S. Tanenbaum and Albert S. Woodhull, there's the following fragment:

In MINIX 3 every file has an 11-bit mode used for protection. Nine of these bits are the read- write-execute bits for the owner, group, and others.

And then, a few lines after, they write:

The other two protection bits, 02000 [octal 200] and 04000 [octal 400], are the SETGID (set-group-id) and SETUID (set- user-id) bits, respectively.

But Python shows that octal 400 is a 12-bit long mask:

>>> len(str(bin(0o4000))) - len('0b')

12

How can a 12-bit long mask be applied on a 11-bit field?


Solution

  • 01000 is the "sticky" bit in Unix, and Minix didn't support it at the time the book was released. It didn't add support until 2010 (the book was released in 2005).