I/O Management in UNIX and Network Programming

csci 330 unix and network programming n.w
1 / 21
Embed
Share

Gain insights into I/O management in UNIX and network programming, exploring system calls like open, creat, read, write, close, unlink, stat, chmod, and more. Understand the difference between system calls and library functions, and learn about file management operations such as removing a file using unlink.

  • UNIX
  • Network Programming
  • I/O Management
  • System Calls
  • File Management

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CSCI 330 UNIX and Network Programming Unit VIII: I/O Management II

  2. CSCI 330 - UNIX and Network Programming 2 Unit Overview System calls for I/O management so far: open, creat, read, write, close today: unlink stat chmod dup remove file get file information change permissions duplicate file descriptor

  3. CSCI 330 - UNIX and Network Programming 3 UNIX System Call a system call is how a program requests a service from the operating system, i.e. UNIX kernel system call executes code in the kernel and makes direct use of facilities provided by the kernel versus: library function is linked to executable, becomes part of the executable

  4. CSCI 330 - UNIX and Network Programming 4 File Management open creat read write close also: unlink stat chmod dup all calls share file descriptor, i.e. number, to identify file open a file make a new file read data from a file write data to a file close a file remove file get file information change permissions duplicate file descriptor

  5. CSCI 330 - UNIX and Network Programming 5 System Call: unlink

  6. CSCI 330 - UNIX and Network Programming 6 Remove a File: unlink int unlink(const char *pathname) removes a pathname from the file system if pathname was the last link to a file, then it is deleted if pathname refers to a symbolic link, then it is removed returns zero, or -1 on error

  7. CSCI 330 - UNIX and Network Programming 7 System Call: unlink example

  8. CSCI 330 - UNIX and Network Programming 8 System Call: stat

  9. CSCI 330 - UNIX and Network Programming 9 File Status: stat family of system calls to inquire about a file int stat(const char *path, struct stat *buf) pathholds string file name int fstat(int fd, struct stat *buf) fdholds file descriptor of open file int lstat(const char *path, struct stat *buf) reports on symbolic link as is bufis pointerto stat structure, which contains information on file

  10. CSCI 330 - UNIX and Network Programming 10 Structure stat struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* file mode: contains permissions */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device ID (if special file) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for file system I/O */ blkcnt_t st_blocks; /* number of blocks allocated */ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last status change */ };

  11. CSCI 330 - UNIX and Network Programming 11 Structure stat st_modefield contains file mode, including permissions to check permissions st_mode & S_IRUSR st_mode & S_IWUSR st_mode & S_IXUSR to check file type S_ISREG(st_mode) S_ISDIR(st_mode) S_IFLNK(st_mode) owner has read permission owner has write permission owner has execute permission is it a regular file is it a directory is it a symbolic link

  12. CSCI 330 - UNIX and Network Programming 12 System Call: stat example

  13. CSCI 330 - UNIX and Network Programming 13 System Call: chmod

  14. CSCI 330 - UNIX and Network Programming 14 System Call: chmod int chmod(const char *path, mode_t mode) change permission settings for file given in pathstring new file permissions are specified in mode must be called by owner of file, or superuser returns zero, or -1 on error

  15. CSCI 330 - UNIX and Network Programming 15 System Call: fchmod int fchmod(int fd, mode_t mode) change permission settings for open file fd new file permissions are specified in mode must be called by owner of file, or superuser returns zero, or -1 on error

  16. CSCI 330 - UNIX and Network Programming 16 Permission mode mode bit mask is created by OR-ing together several of these constants: S_ISUID (04000) set-user-ID S_ISGID (02000) set-group-ID S_ISVTX (01000) sticky bit ex.: S_IRUSR | S_IWUSR | S_IXUSR S_IRUSR (00400) read by owner S_IWUSR (00200) write by owner S_IXUSR (00100) execute/search by owner S_IRUSR | S_IRGRP | S_IROTH S_IRGRP (00040) read by group S_IWGRP (00020) write by group S_IXGRP (00010) execute/search by group or: 0755 0644 S_IROTH (00004) read by others S_IWOTH (00002) write by others S_IXOTH (00001) execute/search by others

  17. CSCI 330 - UNIX and Network Programming 17 System Call: chmod example

  18. CSCI 330 - UNIX and Network Programming 18 System Call: dup

  19. CSCI 330 - UNIX and Network Programming 19 System Call: dup int dup(int oldfd) creates copy of file descriptor oldfd uses lowest-numbered unused descriptor returns the new file descriptor, or -1 on error used to claim standard I/O from inside program

  20. CSCI 330 - UNIX and Network Programming 20 System Call: dup example

  21. CSCI 330 - UNIX and Network Programming 21 Summary: IO Management open creat read write close open a file make a new file read data from a file write data to a file close a file today: unlink stat chmod dup remove file get file information change permissions duplicate file descriptor

More Related Content