<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2021F_Lecture_16</id>
	<title>Operating Systems 2021F Lecture 16 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2021F_Lecture_16"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_16&amp;action=history"/>
	<updated>2026-04-06T06:18:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_16&amp;diff=23447&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on November 11, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec16-20211111.m4v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_16&amp;diff=23447&amp;oldid=prev"/>
		<updated>2021-11-11T17:02:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on November 11, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec16-20211111.m4v...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on November 11, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec16-20211111.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec16-20211111.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Class zoom meetings-&amp;gt;Cloud Recordings tab)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 16&lt;br /&gt;
----------&lt;br /&gt;
 - interviews&lt;br /&gt;
    - there will be more, just figuring my schedule&lt;br /&gt;
      for next week&lt;br /&gt;
    - yes, final will replace midterm if you do better&lt;br /&gt;
 - A3 will be posted by tomorrow, will be going over it a bit today&lt;br /&gt;
&lt;br /&gt;
Today: filesystems&lt;br /&gt;
&lt;br /&gt;
Filesystem&lt;br /&gt;
 - collection of files &amp;amp; directories&lt;br /&gt;
 - namespace for inode numbers&lt;br /&gt;
 - way to transform a block device into a place&lt;br /&gt;
   you can store files&lt;br /&gt;
 - data structure that is accessed using the file API&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From the kernel&amp;#039;s perspective&lt;br /&gt;
 - has file system call interface&lt;br /&gt;
   (open, read, write, etc)&lt;br /&gt;
   (also for directories)&lt;br /&gt;
 - when it gets a pathname, where does it look to get the data?&lt;br /&gt;
   - it figures out which filesystem is responsible for the&lt;br /&gt;
     containing directory&lt;br /&gt;
   - it then asks that filesystem to do the file operations&lt;br /&gt;
 - this abstraction is knows as the &amp;quot;VFS&amp;quot; (virtual filesystem) layer&lt;br /&gt;
&lt;br /&gt;
/proc/filesystems lists all the different kinds of filesystems your Linux system knows about currently&lt;br /&gt;
 - the ones with &amp;quot;nodev&amp;quot; beside them are ones that have no corresponding storage device&lt;br /&gt;
    - means that while you access them with file-related system calls,&lt;br /&gt;
      what you&amp;#039;re getting back isn&amp;#039;t from a storage device, it&lt;br /&gt;
      is something else&lt;br /&gt;
    - known as pseudo filesystems it seems?&lt;br /&gt;
&lt;br /&gt;
df: dump filesystems&lt;br /&gt;
 - show currently mounted filesystems&lt;br /&gt;
&lt;br /&gt;
mount: add a filesystem to our current file hierarchy&lt;br /&gt;
  - mountpoint: where those files should go,&lt;br /&gt;
    normally an empty directory&lt;br /&gt;
    (if not empty, those files will be hidden)&lt;br /&gt;
&lt;br /&gt;
df .&lt;br /&gt;
 - tells me the filesystem responsible for the current directory&lt;br /&gt;
&lt;br /&gt;
df -a&lt;br /&gt;
 - show ALL the filesystems&lt;br /&gt;
   - including ones with no corresponding device&lt;br /&gt;
     (pseudo filesystems)&lt;br /&gt;
&lt;br /&gt;
Pseudo filesystems like /proc tend to have some weird info that give them away&lt;br /&gt;
 - inode numbers are weird&lt;br /&gt;
 - file sizes make no sense (are often zero)&lt;br /&gt;
 - timestamps aren&amp;#039;t consistent&lt;br /&gt;
&lt;br /&gt;
The above is all true because those fields are just made up when you access the files, they aren&amp;#039;t &amp;quot;stored&amp;quot; anywhere&lt;br /&gt;
 - file metadata for pseudo filesystems isn&amp;#039;t that significant&lt;br /&gt;
&lt;br /&gt;
mount&lt;br /&gt;
 - get full information on mounted filesystems (with no args)&lt;br /&gt;
 - or you can use it to add filesystems to file hierarchy&lt;br /&gt;
&lt;br /&gt;
mounting a real filesystem&lt;br /&gt;
 - have access to data on a block device&lt;br /&gt;
&lt;br /&gt;
mounting a pseudo filesystem&lt;br /&gt;
 - have access to some new capability, typically kernel data structures&lt;br /&gt;
   or runtime data that doesn&amp;#039;t need to be stored on disk&lt;br /&gt;
 - essentially all data is in RAM or generated algorithmically&lt;br /&gt;
    - just depends on the filesystem type&lt;br /&gt;
&lt;br /&gt;
/run&lt;br /&gt;
 - it is a &amp;quot;tmpfs&amp;quot; - temporary filesystem&lt;br /&gt;
    - data is temporary&lt;br /&gt;
 - no corresponding block device&lt;br /&gt;
 - it is a &amp;quot;RAM disk&amp;quot; - full filesystem, but&lt;br /&gt;
   *data is lost when system reboots*&lt;br /&gt;
 - used for PID files and lock files mainly&lt;br /&gt;
    - PIDs will change when system is rebooted&lt;br /&gt;
    - locks shouldn&amp;#039;t be held across reboot&lt;br /&gt;
 - note here &amp;quot;tmpfs&amp;quot; is the filesystem type,&lt;br /&gt;
   /run is the mountpoint&lt;br /&gt;
&lt;br /&gt;
Notice that /tmp is NOT in tmpfs&lt;br /&gt;
 - it is in the filesystem of the root filesystem, normally ext4&lt;br /&gt;
 - BUT files in /tmp are erased on every reboot&lt;br /&gt;
    - but that happens due to a boot time script&lt;br /&gt;
&lt;br /&gt;
If you boot with a live CD&lt;br /&gt;
 - data in /run would already be lost&lt;br /&gt;
 - data in /tmp should still be there&lt;br /&gt;
&lt;br /&gt;
/var/tmp is like /tmp, except it is NOT erased when rebooted&lt;br /&gt;
&lt;br /&gt;
In your VM, the root filesystem is mounted as follows:&lt;br /&gt;
&lt;br /&gt;
  /dev/mapper/vg0-lv--0 on / type ext4 (rw,relatime)&lt;br /&gt;
&lt;br /&gt;
the &amp;quot;ext4&amp;quot; means that it is of type ext4.&lt;br /&gt;
&lt;br /&gt;
So, why isn&amp;#039;t /tmp a tmpfs?&lt;br /&gt;
 - historic/distribution reasons (I know some distributions&lt;br /&gt;
   that do put /tmp/ on tmpfs)&lt;br /&gt;
 - can store a lot more in /tmp normally than you could&lt;br /&gt;
   in /tmpfs (as its storage is limited by RAM/virtual memory)&lt;br /&gt;
&lt;br /&gt;
(I&amp;#039;ll discuss lock files later)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Different operating systems have their own native filesystems&lt;br /&gt;
 - MSDOS: fat, vfat, fat32&lt;br /&gt;
 - Windows: NTFS&lt;br /&gt;
 - MacOS: HFS, HFS+, APFS&lt;br /&gt;
 - FreeBSD: UFS, zfs&lt;br /&gt;
 - IRIX: xfs&lt;br /&gt;
 - Linux: ext2, ext3, *ext4*, btrfs, squashfs&lt;br /&gt;
&lt;br /&gt;
LOTS of filesystem types&lt;br /&gt;
&lt;br /&gt;
These are all regular filesystems used for regular disks,&lt;br /&gt;
originally developed for magnetic hard drives, not SSDs&lt;br /&gt;
 - except APFS?&lt;br /&gt;
&lt;br /&gt;
Why so many?&lt;br /&gt;
 - some support different file sizes&lt;br /&gt;
 - different performance characteristics&lt;br /&gt;
 - reliability/durability&lt;br /&gt;
 - licensing&lt;br /&gt;
 - stubbornness/Not Invented Here&lt;br /&gt;
&lt;br /&gt;
Key difference&lt;br /&gt;
 - some are designed for UNIX-like systems (POSIX compliant)&lt;br /&gt;
 - others are not!&lt;br /&gt;
 - POSIX-compliant ones use inodes, others generally do not&lt;br /&gt;
&lt;br /&gt;
Remember a filesystem is just a data structure&lt;br /&gt;
 - so the filesystem type is the kind of data structure&lt;br /&gt;
&lt;br /&gt;
Note that some filesystems have specialized purposes&lt;br /&gt;
 - squashfs is designed to be compressed and read only&lt;br /&gt;
&lt;br /&gt;
Why would you want a read only filesystem?&lt;br /&gt;
 - storage medium is read only (e.g. optical media)&lt;br /&gt;
   iso9660, etc&lt;br /&gt;
 - for starting up the system &amp;lt;--- we&amp;#039;ll get to this&lt;br /&gt;
&lt;br /&gt;
Look up the youtube channel &amp;quot;technology connections&amp;quot;, whole&lt;br /&gt;
series on optical media&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So now let&amp;#039;s make and use a filesystem&lt;br /&gt;
&lt;br /&gt;
What do we need?&lt;br /&gt;
 - a block device&lt;br /&gt;
&lt;br /&gt;
What will we get?&lt;br /&gt;
 - files stored on the block device&lt;br /&gt;
&lt;br /&gt;
Challenge&lt;br /&gt;
 - we don&amp;#039;t have any devices we can physically connect to our VM&lt;br /&gt;
&lt;br /&gt;
Workaround&lt;br /&gt;
 - we&amp;#039;ll make a file that will behave like a block device&lt;br /&gt;
&lt;br /&gt;
To make an empty file, use dd, e.g.&lt;br /&gt;
  dd if=/dev/zero of=fakeblks bs=4096 count=100000&lt;br /&gt;
&lt;br /&gt;
if: input file&lt;br /&gt;
of: output file&lt;br /&gt;
bs: block size&lt;br /&gt;
count: count&lt;br /&gt;
&lt;br /&gt;
So reads count blocks of size bs from input file to output file&lt;br /&gt;
 - note it does exactly one read system call and one write system call&lt;br /&gt;
   for each block transferred&lt;br /&gt;
    - we read count*blocksize from if&lt;br /&gt;
    - we write count*blocksize to of&lt;br /&gt;
&lt;br /&gt;
(Note we are reading from /dev/zero, so we are reading from an infinite source of zero bytes)&lt;br /&gt;
&lt;br /&gt;
Note that you can&amp;#039;t just use touch&lt;br /&gt;
 - it will just make a file of size zero&lt;br /&gt;
&lt;br /&gt;
You could use truncate&lt;br /&gt;
 - but we&amp;#039;ll get to that&lt;br /&gt;
&lt;br /&gt;
To look at the contents of a binary file, you can use od&lt;br /&gt;
 - with the -a option, translates each byte to its corresponding&lt;br /&gt;
   named character&lt;br /&gt;
&lt;br /&gt;
If we run od on the file before and after running mkfs.ext4,&lt;br /&gt;
we can see what bytes were modified in the file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The kernel has many possibilities in determining how to service a given file operation request&lt;br /&gt;
 - if it is for a file on a regular filesystem,&lt;br /&gt;
   it uses that filesystem&amp;#039;s code to interpret data&lt;br /&gt;
   read from or written to the mounted block device&lt;br /&gt;
&lt;br /&gt;
 - if it is for a pseudo filesystem,&lt;br /&gt;
   it runs the code in the kernel that implements the file&lt;br /&gt;
   operations&lt;br /&gt;
     - they can do essentially anything&lt;br /&gt;
&lt;br /&gt;
 - if it is for a character device&lt;br /&gt;
    - runs the code for the character device&lt;br /&gt;
&lt;br /&gt;
/dev/zero is a character device that always returns null bytes&lt;br /&gt;
 - specifically, when you do a &amp;quot;read&amp;quot; system call, it&lt;br /&gt;
   fills the buffer given to it with all zero bytes&lt;br /&gt;
 - will do this as many times as asked&lt;br /&gt;
&lt;br /&gt;
There&amp;#039;s also /dev/urandom and /dev/random&lt;br /&gt;
 - infinite random bytes&lt;br /&gt;
    - but /dev/random is VERY slow&lt;br /&gt;
      because it tries to return &amp;quot;real&amp;quot; random bytes&lt;br /&gt;
&lt;br /&gt;
A filesystem is a data structure.  So, we need ways to&lt;br /&gt;
 - create/initialize the data structure: mkfs&lt;br /&gt;
 - validate and ideally repair the data structure: fsck&lt;br /&gt;
&lt;br /&gt;
Why bother validating and repairing filesystem data structures?&lt;br /&gt;
 - we don&amp;#039;t normally do that for hash tables or binary trees?&lt;br /&gt;
   - but they only stick around for short periods of time&lt;br /&gt;
   - if they get messed up, we just restart the program&lt;br /&gt;
&lt;br /&gt;
But filesystems are meant to last for years, and hardware &amp;amp; software can fail over that time&lt;br /&gt;
 - cosmic rays&lt;br /&gt;
 - manufacturing defects&lt;br /&gt;
 - code bugs...&lt;br /&gt;
&lt;br /&gt;
So filesystems are designed to be repairable&lt;br /&gt;
 - should be able to recover overall structure&lt;br /&gt;
 - ideally, preserve what data you can when things are damaged&lt;br /&gt;
&lt;br /&gt;
fsck tries its best to repair filesystems&lt;br /&gt;
 - but it relies on how the filesystem is structured&lt;br /&gt;
   in order to do its work&lt;br /&gt;
&lt;br /&gt;
Do pseudo filesystems have fsck?&lt;br /&gt;
 - no, because it wouldn&amp;#039;t make sense,&lt;br /&gt;
   no persistent state to fix&lt;br /&gt;
&lt;br /&gt;
note that fsck is specific to each filesystem&lt;br /&gt;
 - every data structure needs its own specialized repair mechanisms&lt;br /&gt;
&lt;br /&gt;
What allows filesystems to be repaired?&lt;br /&gt;
 - lots of redundancy!&lt;br /&gt;
&lt;br /&gt;
&amp;quot;pointers&amp;quot; in filesystems are always bidirectional&lt;br /&gt;
 - so if one is missing we can recover it&lt;br /&gt;
 - (like a doubly linked list)&lt;br /&gt;
&lt;br /&gt;
Some data tells us how the rest of the data is organized&lt;br /&gt;
 - this is the &amp;quot;superblock&amp;quot;&lt;br /&gt;
    (think of it as the root node of a tree)&lt;br /&gt;
 - store multiple copies of the superblock because&lt;br /&gt;
   if this is lost we lose everything&lt;br /&gt;
&lt;br /&gt;
Remember filesystems are data structures for organizing blocks&lt;br /&gt;
 - a block is fixed sized, nowadays generally 4K, but some small&lt;br /&gt;
   power of 2&lt;br /&gt;
 - locations in filesystems are in terms of block numbers,&lt;br /&gt;
   not addresses&lt;br /&gt;
     e.g., block 2000, not address 265101561&lt;br /&gt;
&lt;br /&gt;
We always access the data structure by reading or writing entire&lt;br /&gt;
ranges of blocks, not ranges of bytes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>