Page 1 of 1

Newlib: Mode bits?

Posted: Thu Aug 09, 2007 3:57 pm
by pcmattman
Now that I'm at the stage where I'm implementing drivers (and hence, their read/write implementations), I need to start thinking about the mode bits so user programs have the predicted results (for instance, not being able to write to a readonly device).

The problem is, I usually get 0x1B6 as the mode bits, and as far as I can see, this is no combination of the mode constants. Any ideas?

Posted: Thu Aug 09, 2007 4:58 pm
by Aali
0x1B6 = 0666 or in human speak, read/write access for everyone

Posted: Fri Aug 10, 2007 1:58 am
by JamesM
check linux/sys/stat.h in newlib. It has all the constants defined, as per the open-group base specification (POSIX).
http://www.opengroup.org/onlinepubs/009695399/ wrote: File mode bits:

S_IRWXU
Read, write, execute/search by owner.

S_IRUSR
Read permission, owner.
S_IWUSR
Write permission, owner.
S_IXUSR
Execute/search permission, owner.

S_IRWXG
Read, write, execute/search by group.

S_IRGRP
Read permission, group.
S_IWGRP
Write permission, group.
S_IXGRP
Execute/search permission, group.

S_IRWXO
Read, write, execute/search by others.

S_IROTH
Read permission, others.
S_IWOTH
Write permission, others.
S_IXOTH
Execute/search permission, others.
addendum: There are no posix-defined constants for these. You are free to make them up (that's why they're defined in sys/stat.h not stat.h). Linux in fact seems to change quite a few of the file constants between implementations (c.f. Linux x86 / Linux MIPSel)

JamesM