![Page 1: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/1.jpg)
Advanced Programming in the UNIX Environment
Week 04, Segment 1: The Unix Filesystem
Department of Computer Science Stevens Institute of Technology
Jan Schaumann [email protected]
https://stevens.netmeister.org/631/
![Page 2: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/2.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
• a disk can be divided into logical partitions
CS631 - Advanced Programming in the UNIX Environment
2
![Page 3: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/3.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
• a disk can be divided into logical partitions
CS631 - Advanced Programming in the UNIX Environment
3
physical blocksize
entire diskNetBSD portion of disk
first NetBSD partitionsecond NetBSD partition
![Page 4: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/4.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
• on each logical partition you may create a file system containing the cylinder groups
CS631 - Advanced Programming in the UNIX Environment
4
![Page 5: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/5.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
• each cylinder group contains a list of inodes (i-list) as well as the actual directory- and data blocks
CS631 - Advanced Programming in the UNIX Environment
5
![Page 6: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/6.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
6
![Page 7: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/7.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
7
• data blocks containing the actual data (i.e., contents of the file) are referenced from the inode
#123
![Page 8: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/8.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
8
• a directory entry is really just a hard link mapping a “filename” to an inode
#123
#123
![Page 9: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/9.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
9
• a directory entry is really just a hard link mapping a “filename” to an inode
• you can have many such mappings to the same inode
#123
#123
#123
![Page 10: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/10.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
10
• directories are special "files" containing a list of hard links
![Page 11: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/11.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
11
• each directory contains at least two entries:
• "." -- this directory
• ".." -- the parent directory
![Page 12: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/12.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
CS631 - Advanced Programming in the UNIX Environment
12
![Page 13: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/13.jpg)
Jan Schaumann 2020-09-17
Inodes
CS631 - Advanced Programming in the UNIX Environment
13
• The inode number in a directory entry must point to an inode on the same file system (no hardlinks across filesystems).
![Page 14: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/14.jpg)
Jan Schaumann 2020-09-17
Inodes
CS631 - Advanced Programming in the UNIX Environment
14
• The inode number in a directory entry must point to an inode on the same file system (no hardlinks across filesystems).
• The inode contains most of the information found in the struct stat.
• Every inode has a link count (st_nlink): it shows how many “things” point to this inode. Only if this link count is 0 (and no process has the file open) are the data blocks freed.
![Page 15: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/15.jpg)
Jan Schaumann 2020-09-17
Inodes
CS631 - Advanced Programming in the UNIX Environment
15
• To move a file within a single filesystem, we can just ”move” the directory entry (actually done by creating a new entry, and deleting the old one).
![Page 16: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/16.jpg)
Jan Schaumann 2020-09-17
Inodes
CS631 - Advanced Programming in the UNIX Environment
16
• To move a file within a single filesystem, we can just ”move” the directory entry (actually done by creating a new entry, and deleting the old one).
![Page 17: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/17.jpg)
Jan Schaumann 2020-09-17
Inodes
CS631 - Advanced Programming in the UNIX Environment
17
• To move a file within a single filesystem, we can just ”move” the directory entry (actually done by creating a new entry, and deleting the old one).
![Page 18: Advanced Programming in the UNIX EnvironmentJan Schaumann 2020-09-17 Inodes CS631 - Advanced Programming in the UNIX Environment 14 • The inode number in a directory entry must point](https://reader036.vdocument.in/reader036/viewer/2022070213/610e1e3ecf7ac25efa13a3d7/html5/thumbnails/18.jpg)
Jan Schaumann 2020-09-17
The Unix Filesystem
Visualizing the Unix Filesystem helps us understand the concept of hard links, what directories "look like", and how operations on a directory are independent of the files and their data.
Coming up: creating, removing, and renaming links (hard and symbolic)
CS631 - Advanced Programming in the UNIX Environment
18
link(2) unlink(2) rename(2) symlink(2) / readlink(2)