Linux mkdir function can't authorize full permission?

Permissions set by system calls like mkdir and open are always masked against the current process's umask . You can change the current umask using the umask() function; make sure to set it back when you're done.

Up vote 0 down vote favorite share g+ share fb share tw.

I am testing the mkdir function to create a new directory: folder = mkdir(". /linux", 511); or folder = mkdir(". /linux", 0777); or folder = mkdir(".

/linux", S_IRWXU | S_IRWXG | S_IRWXO); As you can see, I try to authorize the full permission to the directory but here's what comes up with ls -l | grep linux: drwxr-xr-x 2 manuzhang manuzhang 4096 2012-01-04 06:53 linux why can't I authorize write permission for group and others? Updates: weird thing, as you guys told me I tried umask. It works with either umask(S_IWGRP) or umask(S_IWOTH) but fails with umask(S_IWGRP | S_IWOTH), any ideas?

C linux permissions mkdir link|improve this question edited Jan 4 at 1:32 asked Jan 3 at 23:01manuzhang369112 56% accept rate.

Without looking up mkdir(), the "511" looks odd to me, since it doesn't assign the same permissions to group and other as it does to user. Also, you give two uses of mkdir(), and one test example, not attributed to either. What version did you use before the ls test?

– David Thornley Jan 3 at 23:06 The man (2) page for mkdir says that the mode is as supplied, ANDed with 777, so that should work. Could you provide a few more details? What distro, and release of linux are you using?

I'm hoping this is a fully standard glibc you're using as well? – tjarratt Jan 3 at 23:11 1 @DavidThornley 511 = 0777 – Daniel Fischer Jan 3 at 23:14 2 Not an answer to your question, but you should use mkdir(". /linux", 0777) rather than mkdir(".

/linux", 511). – Keith Thompson Jan 3 at 23:25 @tjarratt Ubuntu EGLIBC 2.13-0ubuntu13 – manuzhang Jan 3 at 23:27.

Permissions set by system calls like mkdir and open are always masked against the current process's umask. You can change the current umask using the umask() function; make sure to set it back when you're done.

2 I think doing a chmod after the mkdir is a cleaner solution. – Keith Thompson Jan 3 at 23:26.

From man 2 mkdir: The argument mode specifies the permissions to use. It is modified by the process's umask in the usual way: the permissions of the created directory are (mode & ~umask & 0777). I suggest you look at your umask - it is probably set to 0022.

Try a chmod post-mkdir.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions