System Callmkdir<br />NAME<br />mkdir - create a directory<br />SYNOPSIS<br />       #include <sys/stat.h><br />       #in...
System Call rmdir<br />NAME<br />rmdir - delete a directory<br />SYNOPSIS<br />       #include <unistd.h><br />intrmdir(co...
System Call unlink<br />NAME<br />       unlink - delete a name and possibly the file it refers to<br />SYNOPSIS<br />    ...
System Calllink<br />NAME<br />       link - make a new name for a file<br />SYNOPSIS<br />       #include <unistd.h><br /...
System Callrename<br />NAME<br />       rename - change the name or location of a file<br />SYNOPSIS<br />       #include ...
System Callchdir<br />NAME<br />chdir, fchdir - change working directory<br />SYNOPSIS<br />       #include <unistd.h><br ...
What is current directory?<br />Each running program on Unix has a current directory of the process. <br />Internally, the...
Algorithm of pwd<br />Note the inode number for “.” call it n<br />chdir .. (use chdir)<br />Find the name of the link wit...
Homework<br />Write a program which receives a filename and return its inode number.<br /><ul><li>Inode test.txt
Upcoming SlideShare
Loading in …5
×

Chapter 4 2

396 views
330 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
396
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Chapter 4 2

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

×