2

Today I took LPIC 101-500 exam and I passed but one question keeps bothering me. The question was:

Given the following permissions -rw-r----- what umask should be applied to make all files have the same permissions? My reasoning is as follows (please correct me if I'm wrong):

- indicates that this is a regular file
r - 4
w - 2
- - 0
r - 4
- - 0
- - 0
- - 0
- - 0
- - 0

which gives 640 permissions.

Now, I know that umask is essentially an inverse of permissions so this comes down to the following equation:

 777
-640
-----
 137

So my answer would be 137, however there was no answer that included this result and I probably got this answer wrong. What am I missing?

jedi
  • 439
  • You can test it easily enough...% umask 137 ; touch xx ; ls -l xx gets the result -rw-r----- 1 sweh sweh 0 Mar 16 18:45 xx – Stephen Harris Mar 16 '22 at 22:46
  • Yes, I know. I think you misunderstood my problem. This result was not a possible answer among all answers to be selected. – jedi Mar 16 '22 at 23:00
  • I now found out that there is a distinction between default mask for directories and default mask for regular files. Default mask for directories is 777 and for files 666 so my reasoning was wrong and the correct answer was 0026 – jedi Mar 16 '22 at 23:03
  • Not really; when an application (eg touch or shell >) creates a file it specifies a mode. Typically that's 0666. However an application such as gcc will create the final executable with 0777 (because we normally want x set). That mode is "AND !umask" which results in the permissions. Similarly directory creation is passed a mask; normally that's 0777 but it doesn't have to be. It's purely up to the program that's doing the creation. So if I wrote a program that did mkdir("xyzzy",0700) or open("foo",O_RDWR|O_CREAT,0700) then the permissions would be rwx------ (before umask). – Stephen Harris Mar 16 '22 at 23:49
  • 1
    The umask isn't an inverse of permissions or as some other would put it, a value via subtraction. It's a mask. What each number is doing is masking one or more of the bits. The default umask for most systems is 022 and that gives directories 755 permissions and files 644 permissions (same as directories w/o execute bit). Your answer of 137 is correct but rather than thinking of it as coming via subtraction, think of it as what it's actually doing which is masking the execute bit for the owner, the write and execute bits for the group, and read, write, and execute for everyone else. – Nasir Riley Mar 16 '22 at 23:58
  • I don’t understand what Nasir is saying, but I agree that 137 is the correct answer.  Your understanding of Unix modes and masks is good; you may need to improve your test-taking skills. See also What are the conventional file permissions per filetype before umask is applied (where I have an answer) and where do default file permissions before umask come from? (on [SU]) – G-Man Says 'Reinstate Monica' Mar 17 '22 at 03:59
  • ... or this answer I wrote which explains both how umask works (briefly) and where default permissions come from. – Stephen Kitt Mar 17 '22 at 05:39
  • The umask can't affect given permissions, so the question is posed wrongly. In other words, the umask can only affect permissions on files that are created, not files that already exist. I wonder if the question was actually asking about the permissions themselves, i.e. 640? – Kusalananda Apr 03 '22 at 17:46

1 Answers1

1

Since the answer 137 was not available in any of the possible answers I missed the fact (which I have now learned) that the default mask for regular files is 666, so 6666 - 6640 = 0026 and as far as I remember correctly, this was one of the possible answers.

jedi
  • 439