The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help on umask suvendu4urs Linux 6 04-11-2008 09:12 AM
umask with find braindrain Shell Programming and Scripting 4 09-25-2006 04:28 AM
Selective Umask baanprog UNIX for Advanced & Expert Users 3 08-03-2006 06:48 AM
Umask help x96riley3 AIX 1 04-04-2006 12:56 PM
umask rsh UNIX for Dummies Questions & Answers 2 12-14-2002 09:52 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-06-2002
Registered User
 

Join Date: Sep 2002
Posts: 25
umask

in this unix book that i have, it says:
the statement:

filedes = open(pathname, O_CREAT, mode);

is actually

filedes = open(pathname, O_CREAT, (~mask)&mode); /* ~ is the negation symbol */

like it's doing some type of masking.
for example,

fd = open("newfile", O_CREAT, 0644);

will actually given the mode of 0640.

how did it come up with that? what value does it mask to my mode set to come up with 0640?
why is it doing that?
thanks

Last edited by bb00y; 11-06-2002 at 01:51 AM.
Forum Sponsor
  #2  
Old 11-06-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,653
It would be more accurate to say something like the thing that the first thing that the open() system call does is:
mode=(~mask)&mode;

The "mask" is called umask. It is set with the umask() system call. And there is a umask command for users. Umask will also affect creat(), mkdir(), and mknod().

If you use bind() on a unix_domain socket you will create a socket in the filesystem. bind() is immune to umask which is actually something I find to be a little odd.

As for why, well I don't really know. However, here is my guess... I think that after people wrote a bunch of programs that did:
fd = open("newfile", O_CREAT, 0644);
or even
fd = open("newfile", O_CREAT, 0666);
they one day woke up and realized that was not great for security. So rather than rewrite all the programs, they just invented umask() to give users some control over what the mode is.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0