3. System Callmkdir NAME mkdir - create a directory SYNOPSIS #include <sys/stat.h> #include <sys/types.h> intmkdir(const char *pathname, mode_t mode); DESCRIPTION mkdir() attempts to create a directory named pathname. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately
4. System Call rmdir NAME rmdir - delete a directory SYNOPSIS #include <unistd.h> intrmdir(const char *pathname); DESCRIPTION rmdir() deletes a directory, which must be empty. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
5. System Call unlink NAME unlink - delete a name and possibly the file it refers to SYNOPSIS #include <unistd.h> int unlink(const char *pathname); DESCRIPTION unlink() deletes a name from the file system. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse. If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed. If the name referred to a symbolic link the link is removed. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
6. System Calllink NAME link - make a new name for a file SYNOPSIS #include <unistd.h> int link(const char *oldpath, const char *newpath); DESCRIPTION link() creates a new link (also known as a hard link) to an existing file. If newpath exists it will not be overwritten. This new name may be used exactly as the old one for any operation; both names refer to the same file (and so have the same permissions and ownership) and it is impossible to tell which name was the "original". RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
7. System Callrename NAME rename - change the name or location of a file SYNOPSIS #include <stdio.h> int rename(const char *oldpath, const char *newpath); DESCRIPTION rename() renames a file, moving it between directories if required. Any other hard links to the file (as created using link(2)) are unaf- fected. Open file descriptors for oldpath are also unaffected. If newpath already exists it will be atomically replaced (subject to a few conditions; see ERRORS below), so that there is no point at which another process attempting to access newpath will find it missing. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
8. System Callchdir NAME chdir, fchdir - change working directory SYNOPSIS #include <unistd.h> intchdir(const char *path); intfchdir(intfd); DESCRIPTION chdir() changes the current working directory of the calling process to the directory specified in path. fchdir() is identical to chdir(); the only difference is that the directory is given as an open file descriptor. RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
9. What is current directory? Each running program on Unix has a current directory of the process. Internally, the process keeps a variable that store the inode number of the current directory. Change to a new directory is to change the value of that variable
10.
11.
12. Algorithm of pwd Note the inode number for “.” call it n chdir .. (use chdir) Find the name of the link with inoden (use opendir, readdir, closedir) repeat (until reach the top of the tree) Note: In the root directory, “.” and “..” point to the same inode