<?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_14</id>
	<title>Operating Systems 2021F Lecture 14 - 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_14"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_14&amp;action=history"/>
	<updated>2026-04-06T04:46:31Z</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_14&amp;diff=23434&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on November 4, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec14-20211104.m4v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_14&amp;diff=23434&amp;oldid=prev"/>
		<updated>2021-11-04T23:55:56Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on November 4, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec14-20211104.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 4, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec14-20211104.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec14-20211104.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 14&lt;br /&gt;
----------&lt;br /&gt;
 - Happy Diwali! (for those who celebrate)&lt;br /&gt;
&lt;br /&gt;
 - grading: will upload A2 after class, midterm will be soon&lt;br /&gt;
   (by next class)&lt;br /&gt;
 - schedule will be posted when midterm grades are posted, will&lt;br /&gt;
   announce on Teams hopefully this weekend&lt;br /&gt;
&lt;br /&gt;
 - today: more about files &amp;amp; filesystems for T6, which I&amp;#039;ll post this afternoon&lt;br /&gt;
&lt;br /&gt;
 - 3rd party builds of Firefox can&amp;#039;t use the firefox branding without&lt;br /&gt;
   special agreement.  Many linux distributions can use the logos of firefox but internally they make the build names a bit different&lt;br /&gt;
&lt;br /&gt;
(For the final I&amp;#039;ll probably try to message on Teams to schedule interviews)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Files &amp;amp; filesystems&lt;br /&gt;
 - a file is a mapping between a hierarchical key (the filename) with an arbitrarily-sized value (the contents of the file)&lt;br /&gt;
 - there&amp;#039;s also metadata associated with each file&lt;br /&gt;
    - permissions, ownership, timestamps, etc&lt;br /&gt;
 - metadata is associated with the value, not the key&lt;br /&gt;
    - goes with file contents, not the file name&lt;br /&gt;
&lt;br /&gt;
So files (in UNIX-like systems) are actually a mapping between a name and&lt;br /&gt;
a data structure that represents the value and associated metadata&lt;br /&gt;
  - that data structure is known as an &amp;quot;inode&amp;quot;&lt;br /&gt;
    (I think the i stands for indirection but I&amp;#039;m not sure.)&lt;br /&gt;
&lt;br /&gt;
stat system call returns the metadata associated with an inode&lt;br /&gt;
 - there&amp;#039;s also a command line wrapper around stat&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
  File: foo&lt;br /&gt;
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file&lt;br /&gt;
Device: fd00h/64768d	Inode: 45220577    Links: 1&lt;br /&gt;
Access: (0644/-rw-r--r--)  Uid: ( 1000/    soma)   Gid: ( 1000/    soma)&lt;br /&gt;
Access: 2021-11-04 10:13:10.897903575 -0400&lt;br /&gt;
Modify: 2021-11-04 10:13:10.897903575 -0400&lt;br /&gt;
Change: 2021-11-04 10:13:10.897903575 -0400&lt;br /&gt;
 Birth: 2021-11-04 10:13:10.897903575 -0400&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From the stat man page:&lt;br /&gt;
    struct stat {&lt;br /&gt;
        dev_t     st_dev;         /* ID of device containing file */&lt;br /&gt;
        ino_t     st_ino;         /* Inode number */&lt;br /&gt;
        mode_t    st_mode;        /* File type and mode&lt;br /&gt;
	                             (permission bits) */&lt;br /&gt;
        nlink_t   st_nlink;       /* Number of hard links */&lt;br /&gt;
        uid_t     st_uid;         /* User ID of owner */&lt;br /&gt;
        gid_t     st_gid;         /* Group ID of owner */&lt;br /&gt;
        dev_t     st_rdev;        /* Device ID (if special file) */&lt;br /&gt;
        off_t     st_size;        /* Total size, in bytes */&lt;br /&gt;
        blksize_t st_blksize;     /* Block size for filesystem I/O */&lt;br /&gt;
        blkcnt_t  st_blocks;      /* Number of 512B blocks allocated */&lt;br /&gt;
&lt;br /&gt;
        struct timespec st_atim;  /* Time of last access */&lt;br /&gt;
        struct timespec st_mtim;  /* Time of last modification */&lt;br /&gt;
        struct timespec st_ctim;  /* Time of last status change */&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key concepts that we haven&amp;#039;t covered:&lt;br /&gt;
 - blocks&lt;br /&gt;
 - multiple timestamps&lt;br /&gt;
 - hard links (NOT symbolic links)&lt;br /&gt;
 - device IDs&lt;br /&gt;
 - inode number&lt;br /&gt;
&lt;br /&gt;
(Mentioned mounting, will discuss more soon)&lt;br /&gt;
&lt;br /&gt;
So why three time stamps?&lt;br /&gt;
 - Access: when last read&lt;br /&gt;
 - Modify: when last written (data change)&lt;br /&gt;
 - Change: when inode last changed   &amp;lt;--- chmod&lt;br /&gt;
           (metadata change)&lt;br /&gt;
 - Birth: file creation (mostly not specified/used on UNIX)&lt;br /&gt;
    - not in the stat struct?&lt;br /&gt;
&lt;br /&gt;
A quirk of UNIX files&lt;br /&gt;
 - a file access (read) results in a disk write (to update the accessed&lt;br /&gt;
   time stamp value in the inode)&lt;br /&gt;
 - on modern systems, this is often a bad idea (too much SSD writing)&lt;br /&gt;
    - so depending on how the filesystem was mounted,&lt;br /&gt;
      accessed timestamp may be approximate or just wrong&lt;br /&gt;
&lt;br /&gt;
If something is done &amp;quot;lazily&amp;quot; in CS, it means it is put off as long as possible&lt;br /&gt;
 - try to minimize the work since if it is put off long enough it may&lt;br /&gt;
   not need to be done&lt;br /&gt;
&lt;br /&gt;
So with reading, if you do 100 reads from a file, technically it should be writing the same inode to disk 100 times&lt;br /&gt;
 - but if we&amp;#039;re lazy and only do the write, say, every few seconds,&lt;br /&gt;
   we&amp;#039;d only do one write to the inode for the accessed timestamp&lt;br /&gt;
&lt;br /&gt;
Buffering I/O is a way to be lazy&lt;br /&gt;
  - reduces number of writes in exchange for higher latency in some circumstances&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
inode numbers&lt;br /&gt;
 - unique ID for an inode&lt;br /&gt;
 - filenames are really name -&amp;gt; inode number mappings&lt;br /&gt;
 - inode numbers are unique *within a given filesystem*&lt;br /&gt;
    - each filesystem has its own inode number namespace&lt;br /&gt;
   (the inode numbers on your usb disk filesystem have nothing&lt;br /&gt;
    to do with the inodes in your SSD filesystem)&lt;br /&gt;
&lt;br /&gt;
If you give the -i option to ls, it will show you inode numbers.&lt;br /&gt;
&lt;br /&gt;
A filename is better thought of as a pathname&lt;br /&gt;
 - it is the combination of names of every containing directory&lt;br /&gt;
   plus the final name&lt;br /&gt;
&lt;br /&gt;
A directory is a data structure (really, a type of inode) which maps names to inode numbers&lt;br /&gt;
&lt;br /&gt;
When you&amp;#039;re in a directory, &amp;quot;.&amp;quot; refers to this directory&lt;br /&gt;
 - &amp;quot;.&amp;quot; is a filename like any other that refers to an inode&lt;br /&gt;
&lt;br /&gt;
Hard link count&lt;br /&gt;
 - number of names an inode has&lt;br /&gt;
   - basically, a reference count&lt;br /&gt;
 - regular files will normally have a link count of 1&lt;br /&gt;
   - for its filename&lt;br /&gt;
 - directories will have a link count of at least 2&lt;br /&gt;
   - the directory name in the containing folder&lt;br /&gt;
   - the &amp;quot;.&amp;quot; link in its own directory&lt;br /&gt;
   - every subdirectory has a parent link, those increase&lt;br /&gt;
     the link count too&lt;br /&gt;
&lt;br /&gt;
So in every directory there are always two entries&lt;br /&gt;
 - &amp;quot;.&amp;quot;  &amp;lt;-- this directory (like &amp;quot;self&amp;quot; in an OO language)&lt;br /&gt;
 - &amp;quot;..&amp;quot; &amp;lt;-- the parent (containing) directory&lt;br /&gt;
&lt;br /&gt;
By default . is not in your path&lt;br /&gt;
 - considered a security vulnerability&lt;br /&gt;
 - imagine a web server where you can upload files to a special directory&lt;br /&gt;
 - sysadmin is working in the directory, attacker has uploaded a file &amp;quot;ls&amp;quot;&lt;br /&gt;
 - now when the sysadmin types &amp;quot;ls&amp;quot; they could get the attacker&amp;#039;s ls, not&lt;br /&gt;
   /bin/ls&lt;br /&gt;
&lt;br /&gt;
What does it mean to delete a file on a UNIX-like system?&lt;br /&gt;
 - you don&amp;#039;t!&lt;br /&gt;
 - you just &amp;quot;unlink&amp;quot; files&lt;br /&gt;
    - remove directory entries&lt;br /&gt;
 - when an inode ref count goes to 0, it is considered deleted&lt;br /&gt;
   and is de-allocated&lt;br /&gt;
&lt;br /&gt;
In general files are never immediately deleted&lt;br /&gt;
 - just like with a program, if you de-allocate a data structure it is&lt;br /&gt;
   still there in memory&lt;br /&gt;
 - and yes, this is lazy&lt;br /&gt;
&lt;br /&gt;
If you want data to be erased from disk when you delete, use an&lt;br /&gt;
encrypted filesystem&lt;br /&gt;
 - because the key for the file will be written over when it is deleted&lt;br /&gt;
 - (encrypted data with lost key is considered erased if your encryption&lt;br /&gt;
    is any good)&lt;br /&gt;
&lt;br /&gt;
inode ref count is the hard link count&lt;br /&gt;
&lt;br /&gt;
Note that any commands that try to overwrite the data on disk won&amp;#039;t work,&lt;br /&gt;
especially on an SSD.&lt;br /&gt;
  - need to explain filesystems a bit first to see why&lt;br /&gt;
  - data will be overwritten, but eventually (could be very long)&lt;br /&gt;
&lt;br /&gt;
So what&amp;#039;s a filesystem?&lt;br /&gt;
 - an &amp;quot;on disk&amp;quot; data structure for storing files&lt;br /&gt;
   (i.e., inodes and associated data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand filesystems, you have to understand how disks store data&lt;br /&gt;
&lt;br /&gt;
What does a &amp;quot;disk&amp;quot; store?  What does it appear to the OS as?&lt;br /&gt;
&lt;br /&gt;
 - array of fixed-sized blocks&lt;br /&gt;
 - block number: which block&lt;br /&gt;
 - block contents: 512, 1024, 4096, 8192, or another power of two&lt;br /&gt;
   chunk of bytes&lt;br /&gt;
&lt;br /&gt;
This is why UNIX has block devices &amp;amp; character devices&lt;br /&gt;
 - block device: you access data on them a block at a time&lt;br /&gt;
 - character device: you access data one character (byte) at a time&lt;br /&gt;
&lt;br /&gt;
So a filesystem is a data structure for storing inodes &amp;amp; file data in blocks of some fixed size&lt;br /&gt;
 - some blocks are inode blocks&lt;br /&gt;
 - rest are data blocks&lt;br /&gt;
&lt;br /&gt;
(Non-UNIX filesystems will divide these into directory and data blocks)&lt;br /&gt;
&lt;br /&gt;
Each devices has a native block size&lt;br /&gt;
 - nowadays 4K or 8K&lt;br /&gt;
 - so, decided by the OS (firmware) on the disk&lt;br /&gt;
    - yes, disks of any kind are really their own computers&lt;br /&gt;
&lt;br /&gt;
The filesystem block size should be a multiple of the device block size&lt;br /&gt;
 - because we always read or write an entire block at once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Character devices are for anything that isn&amp;#039;t mass storage&lt;br /&gt;
 - so keyboards, mouse/touchpad, terminals&lt;br /&gt;
   - typically things for interacting with humans&lt;br /&gt;
&lt;br /&gt;
look at /dev to see what different kinds of devices you have&lt;br /&gt;
&lt;br /&gt;
you can&amp;#039;t delete an inode directly, you can just remove its names&lt;br /&gt;
 - unlink all its names&lt;br /&gt;
&lt;br /&gt;
When we &amp;quot;read&amp;quot; a file, we are just accessing data in its underlying block device&lt;br /&gt;
&lt;br /&gt;
Instead of using a real block device, we can use a simulated one&lt;br /&gt;
for playing with filesystems&lt;br /&gt;
 - turn a file into a block device&lt;br /&gt;
 - can then make filesystems in it that can be mounted&lt;br /&gt;
&lt;br /&gt;
this is all stuff for tutorial 6, so don&amp;#039;t worry if you&amp;#039;re lost&lt;br /&gt;
 - you may want to come back to what I&amp;#039;ve done here&lt;br /&gt;
 - we&amp;#039;ll do it again a few times&lt;br /&gt;
&lt;br /&gt;
symbolic links are filenames that refer filenames, not inodes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>