Code:
- Mkdir function in Linux
-
- Prototype: int mkdir (const char * filename, mode_t Mode)
- If the return value is 0, the operation is successful. If the return value is-1, an error occurs. This function must contain header files.
- # Include <sys/STAT. h>
- # Include <sys/types. h>
-
- Mode indicates the permission of the new directory. You can use the following values:
- S_irusr
- S_iread
- Read Permission bit for the owner of the file. on Alibaba systems this bit is 0400. s_iread is an obsolete synonym provided for BSD compatibility.
- S_iwusr
- S_iwrite
- Write Permission bit for the owner of the file. Usually 0200. s_iwrite is an obsolete synonym provided for BSD compatibility.
- S_ixusr
- S_iexec
- Execute (for ordinary files) or search (for directories) Permission bit for the owner of the file. Usually 0100. s_iexec is an obsolete synonym provided for BSD compatibility.
- S_irwxu
- This is equivalent to (s_irusr | s_iwusr | s_ixusr ).
- S_irgrp
- Read Permission bit for the group owner of the file. Usually 040.
- S_iwgrp
- Write Permission bit for the group owner of the file. Usually 020.
- S_ixgrp
- Execute or search permission bit for the group owner of the file. Usually 010.
- S_irwxg
- This is equivalent to (s_irgrp | s_iwgrp | s_ixgrp ).
- S_iroth
- Read Permission bit for other users. Usually 04.
- S_iwoth
- Write Permission bit for other users. Usually 02.
- S_ixoth
- Execute or search permission bit for other users. Usually 01.
- S_irwxo
- This is equivalent to (s_iroth | s_iwoth | s_ixoth ).
- S_isuid
- This is the set-user-id on execute bit, usually 04000. See how change persona.
- S_isgid
- This is the set-group-ID on execute bit, usually 02000. See how change persona.
- S_isvtx
- This is the sticky bits, usually 01000.
Mkdir function in Linux
Header file Library:
# Include <sys/STAT. h>
# Include <sys/types. h>
Function prototype:
Int mkdir (const char * pathname, mode_t mode );
Function Description:
The mkdir () function creates a directory named after the pathname parameter in mode, and mode defines the permission for creating a new directory.
Return Value:
If the directory is successfully created, 0 is returned; otherwise,-1 is returned and an error is recorded in the global variable errno.
Mode:
S_irwxu |
00700 permission indicates that the owner of the file has the permission to read, write, and execute operations. |
S_irusr (s_iread) |
00400 permission indicates that the object owner has the readable permission. |
S_iwusr (s_iwrite) |
00200 permission indicates that the file owner has the write permission. |
S_ixusr (s_iexec) |
00100 permission indicates that the file owner has the permission to execute the file. |
S_irwxg |
00070 permission, which indicates that the file user group has the read, write, and execution permissions. |
S_irgrp |
00040 permission, which indicates that the file user group has the readable permission |
S_iwgrp |
00020 permission, which indicates that the file user group has the write permission |
S_ixgrp |
00010 permission, which indicates that the file user group has the execution permission |
S_irwxo |
00007 permission indicates that other users have the read, write, and execute permissions |
S_iroth |
00004 permission, which indicates that other users have the readable permission |
S_iwoth |
00002 permission, indicating that other users have the write permission |
S_ixoth |
00001 permission indicates that other users have the execution permission |