ITEM: I2964L

umask permissions


Question:

How does the umask setting affect file creation?

Response:

umask is a file creation mask which is subtracted out of the
file creation permissions.  File creation permissions for
files is 666, and for directories it is 777.  Therefore, you
are never able to create a file with the execute permission set.
That is unless you write your own code.  An example of this is
below.

How does umask work?

File creation permission = r w x  r w x  r w x
                           4 2    4 2    4 2     =  6 6 6

Directory creation perm  = r w x  r w x  r w x
                           4 2 1  4 2 1  4 2 1   =  7 7 7

Umask value of 022 for file

       4 2    4 2    4 2         666        creation permissions
   -   0 0 0  0 2 0  0 2 0     - 022      - umask
   -----------------------     -----      ----------------------
       4 2 0  4 0 0  4 0 0       644        file permissions
       r w -  r - -  r - -

Umask value of 022 for directory

       4 2 1  4 2 1  4 2 1       777
   -   0 0 0  0 2 0  0 2 0     - 022
   -----------------------     -----
       4 2 1  4 0 1  4 0 1       755
       r w x  r - x  r - x

Umask value of 033 for file

       4 2    4 2    4 2         666     This shows not simple sub on files.
   -   0 0 0  0 2 1  0 2 1     - 033     You are actually subtracting from 7
   -----------------------     -----     and throwing away the execute bit!
       4 2 0  4 0 0  4 0 0       633  \<- It is simple sub on directories!
       r w -  r - -  r - -

Umask value of 033 for directory

       4 2 1  4 2 1  4 2 1       777
   -   0 0 0  0 2 1  0 2 1     - 033
   -----------------------     -----
       4 2 1  4 0 0  4 0 0       744
       r w x  r - -  r - -

Umask value of 345 for file

       4 2    4 2    4 2         666
   -   0 2 1  4 0 0  4 0 1     - 345
   -----------------------     -----
       4 0 0  0 2 0  0 2 0       321  \<- Again, not a simple subtraction!
       r - -  - w -  - w -

Umask value of 345 for directory

       4 2 1  4 2 1  4 2 1       777
   -   0 2 1  4 0 0  4 0 1     - 345
   -----------------------     -----
       4 0 0  0 2 1  0 2 0       432
       r - -  - w x  - w -

The above examples describe how the umask works. 

A sample piece of code, that might work to create files with
the execute permissions set is as follows:

  main (int argc, char ** argv)
  {
        int     mode = strtol (argv[1], 0, 8);
        int     fd = creat (argv[2], mode);
        if (fd == -1) {
                perror ("creat");
                exit (1);
        }
        exit (0);
  }

You can compile this code (cc -o creat creat.c) and use it as a
touch command.  You need to pass this code the file creation permissions.
It will use this and the umask to create the file. The AIX Systems
Center does not intend to support this piece of code, it is sample code
only and should be tested prior to use in a production environment.



Support Line: umask permissions ITEM: I2964L
Dated: April 1994 Category: N/A
This HTML file was generated 99/06/24~13:30:45
Comments or suggestions? Contact us