15 UNIX File System
Published:
Single root directory, not necessarily a single device Need to designate a disk to be the root file system For external devices’ file system, need to mount it to some place at that file system
mount -l
shows all mount points/dev/sda1 on / type ext4 students251 on /mnt/disks/aspstudents251 type zfs
dev
: a region for devicessda1
: hard disk devicetype ext4
: Metadata structure to use this device
Mounting types
/proc
An entire fake file system maintained by the kernel, where entries are PIDs, with all info about it
- This directory is mounted to a file system that is not on the disk, but on the memory
- When kernel reads, it will not go to the disk
With root permissions, you can write to these
/proc
files/proc/self
tells about the current process/proc/self/maps
shows allmmap
sproc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
Bind mount
Bind-mounts allow you to mount a directory within an existing filesystem onto somewhere else in the hierarchy, effectively creating a new entry point.
sudo mount --bind <existing-dir> <mount-point>
- Similar to a sym link
- Appears in the mount table
Berkley File System (FFS)
inode structure
- Super block: FS metadata (file system size, inode count, offset, …)
- Cylinder: further partition
- Metadata
- i-node map: which i-node is free/used
- Block map: which block is free/used
- i-nodes: array of i-nodes. Each stores a file or directory’s
- Metadata
- Pointers to data blocks
- Data blocks
Directory
A directory is a special file with
- i-node number
- Filename Two directories may point to the same i-node. There can be multiple names for a single file. i-node number is the only unique identifier. Filename is just what the directory refers to the i-node by
Directory of “2549” is referred by “testdir” in 1267, and “.” in 2549 (itself)
Hard link
echo howdy > f1
ln f1 f2 # hard link a new f2 to f1
Once hard links are created, can’t distinguish. They refer to the same i-node number in ll
f2
is not a copy or a shortcutll
also shows the link count: how many filenames are linked with the i-node Hard links are not allowed for directories- Too dangerous, unless you’re the system that creates
.
and..
Symlink
ln -s f1 s1 # sym link s1 to f1
A separate file (i-node) that is marked with a special type
- Content: just characters
f1
greptile
can ignore symlink vialstat
, but can’t ignore hard link- If a the file is removed, it will be a broken symlink
Symlink can point to a path, but you can’t create a hard link that’s from another file system, since i-node doesn’t have any meaning in a different file system