4

I am looking for a list that specifies the conventional file permission of all the different file-types before the umask is applied.

I read in man 1p touch that the default for a regular file is:

    S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH

I will also go off on a limb and surmise the default for a directory and symlink is:

   S_IRWXU | S_IRWXG | S_IRWXO

However I cannot find in the man pages for stat.h or mknod.h / mknod what the default permissions of Sockets, FIFOs, Block devices, and Char devices are. Are they they same as regular files? Or have I missed a man page that explains this?

3

You seem to have got it pretty well figured out; it is discussed a bit more here.  The one point that you may have missed is that you found the statement in the man page for touch(1) and not creat(2), because (with the possible exception of symbolic links), there are no system-level defaults — each program has its own individual default.  It just so happens that most (if not all) programs follow the same rules.

1

The permissions for files (subject to umask) are set in the open call when the file is first created. In fopen, the permissions are set to 0666, but that deals with stream I/O. Depending on the application which creates the files, they may use the low-level open/read/write — or not.

Special devices would be created using mknod, again with the application specifying the initial permissions. For instance, the mkfifo commands used with Linux and OSX have an option for setting the permission. Likewise the [mknod][6] command has an option for setting the permission. The manuals for these do not specify the initial permissions.

Interestingly, POSIX's description of mkfifo does not indicate any particular set of permissions either (aside from documenting an option for setting them).

Given that lack of specificity, there is a possibility that some implementations of these commands do not use 0666 for permissions, but whether that hypothetical implementation is looser or more stringent is unclear. If you examine the contents of /dev, you generally will not find special devices that are world-writable. That might be enforced by a given implementation. For instance, if a special device had execute permission, this might not be a good thing, since their content is (normally) not like a regular file, and unexpected things might happen if it was "executed".

Without documentation, any answer about conventional permissions would have to be confined to observations of specific implementations. The 0666 permissions are widely used for non-executable files, but there is no guarantee that this is a universal truth.

Permissions of a symbolic link, on the other hand, are decidedly system-specific. The symlink(7) manual page for Linux says they are always 0777:

On Linux, the permissions of a symbolic link are not used in any operations; the permissions are always 0777 (read, write, and execute for all user categories), and can't be changed.

On other systems it may be possible, e.g., the BSDs such as FreeBSD and OSX document a -h option which can be used to modify the permissions, although the corresponding symlink(2) call's documentation (FreeBSD, OSX) does not mention initial permissions.

Further reading:

0

In most systems, the disc files' default privilege before the umask is applied is the same as regular files. (0666)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.