• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Chapter 4 2
 

Chapter 4 2

on

  • 367 views

 

Statistics

Views

Total Views
367
Views on SlideShare
367
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Chapter 4 2 Chapter 4 2 Presentation Transcript

    • 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
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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
    • 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
    • Homework
      Write a program which receives a filename and return its inode number.
      • Inode test.txt
      • This i node number is 1234
      • Read pwd.c on page 13.