1 / 62

http:// codeschool.org /

Unix system calls (part 2). http:// codeschool.org /. This work is licensed under a Creative Commons Attribution- ShareAlike 3.0 Unported License. . This is one part of a larger series. You may need to view previous parts to understand this material. http:// codeschool.org /.

quasar
Télécharger la présentation

http:// codeschool.org /

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix system calls (part 2) http://codeschool.org/ This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

  2. This is one part of a larger series. You may need to view previous parts to understand this material. http://codeschool.org/ This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

  3. open (open/create a file and return a file descriptor) close (release file descriptor) read (copy bytes from a file to memory)* write (copy bytes of memory to a file)* *blocks

  4. Process syscallwrite HD OS write buffer

  5. f = open(‘/alice/tim’) write(f, ‘blabla’) write(f, ‘blablabla’) close(f)

  6. Process syscallread HD OS data and code read buffer

  7. f = open(‘/alice/tim’) data = read(f) close(f)

  8. f = open(‘/alice/tim’) data = read(f) whilelen(data) != 0: print(data) data = read(f) close(f)

  9. marker byte 0 last byte

  10. marker byte 0 last byte

  11. byte 0 last byte move with truncate

  12. move with lseek marker byte 0 last byte move with truncate

  13. descriptor description

  14. f = open(‘/alice/tim’) f2 = open(‘/alice/tim’) write(f, ‘blabla’) data = read(f2)

  15. descriptor description buffer file on disk

  16. pid442read byte 0 last byte pid75write pid580write pid46write

  17. ‘herpderp’ byte 0 last byte pid75write pid580write ‘blabla’

  18. ‘herpderp’ ‘her blap’ ‘blrpderp’ ‘hlapbderp’ byte 0 last byte pid75write pid580write ‘blabla’

  19. umask (get/set default permissions for new files/directories) oldmask = umask(newmask) f = open(‘/alice/tim’) write(f, ‘blabla’)

  20. chmod (‘change mode’: set permissions of an existing file/directory) chmod(‘/alice/tim’, mask)

  21. chmod (‘change mode’: set permissions of an existing file/directory) chown (‘change owner’: set owner of an existing file/directory) chmod(‘/alice/tim’, mask) chown(‘/alice/tim’, user, group)

  22. HD HD flash drive CD-ROM partition 1 partition 4 partition 5 partition 6 partition 2 partition 7 partition 3

  23. file 35 each file and directory in a partition is known by a unique inode number directory 21 file 4 directory 86 file 7  root directory always has inode 2 root directory 2 file 61

  24. mkdir (‘make directory’) rmdir (‘remove a file or directory’) mkdir(‘/alice/tim’) rmdir(‘/alice/tim’)

  25. link (add directory entry) link(‘/alice/ian’, ‘/ben/jill’)

  26. link (add directory entry) unlink (remove directory entry) link(‘/alice/ian’, ‘/ben/jill’) unlink(‘/alice/ian’)

  27. getdents (‘get directory entries’) f = open(‘/alice’) entries = getdents(f) whilelen(entries) != 0: print(entries) entries = getdents(f) close(f)

  28. partition 1 /alice/tim partition 2 / HD partition 3 /jessica/vincent /jessica partition 4 flash drive

  29. mount (attach partition to the unified file system) umount (‘unmount’: detach partition from the unified file system) mount(partition1, ‘/alice/tim’) umount(‘/alice/tim’)

  30. absolute path:/alice/tim relative path:alice/tim

  31. chdir (change cwd, the ‘current working directory’) chdir(‘/ben/ian’) f = open(‘/alice/tim’) f2 = open(‘alice/tim’) becomes:‘/ben/ian/alice/tim’

  32. ‘regular’ file • directory • symbolic link • character device file • block device file • pipe • socket

  33. symlink (create a symbolic link) symlink(‘/alice/tim’, ‘/jill/ken’) f = open(‘/jill/ken’) follows link to:‘/alice/tim’

  34. device registers read/write  CPU

  35. block 0 block 1 partition composed of blocks block 2 block 3 block 4 block 5  a block may only be read/written as a whole block 6 block 7 block 8 block 9

  36. block 0 block 1 inode 86 partition composed of blocks block 2 block 3 block 4 inode 86 block 5 block 6 inode 86 block 7 block 8 block 9

  37. block 0 read/write block 1 inode 86 block 2 block 3 block 4 inode 86 block 4 buffer block 5 block 6 inode 86 block 7 block 8 block 9

  38. block device file byte 0 block 0 block 1 block 2 block 3 block 4 block 5 block 6 last byte

  39. character device file read input process device input buffer write output output buffer

  40. input/output buffers are FIFO (first in, first out) data appended here data taken starting here

  41. input/output buffers are FIFO (first in, first out) device appends data here input buffer read takes data starting here

  42. input/output buffers are FIFO (first in, first out) write appends data here output buffer device takes data starting here

  43. block device buffers backed by storage character device buffers not backed by storage

  44. /dev directory of device files bf = open(‘/dev/sda1’) cf = open(‘/dev/lp0’)

  45. /dev directory of device files bf = open(‘/dev/sda1’) cf = open(‘/dev/lp0’) lseek(bf, 100) bdata = read(bf) cdata = read(cf)

  46. pseudo-device files /dev/zero returns zeroed bytes/dev/random returns random data /dev/null discards data; returns no bytes at all

  47. pipe (a FIFO as a file) write appends data here read takes data starting here

  48. process A pipe process B read write FIFO

  49. pipe read write FIFO process A process B write read FIFO pipe

  50. mknod (‘make node’: create a regular file, device file, or named pipe) mknod(‘/ryan/kim’, BLOCK, deviceNum) mknod(‘/ryan/erin’, CHR,deviceNum) mknod(‘/ryan/tina’, FIFO)

More Related