<?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_2020W_Lecture_9</id>
	<title>Operating Systems 2020W Lecture 9 - 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_2020W_Lecture_9"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_9&amp;action=history"/>
	<updated>2026-06-03T00:40:57Z</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_2020W_Lecture_9&amp;diff=22574&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video from the lecture given on February 5, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec09-20200205.m4v is now available...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_9&amp;diff=22574&amp;oldid=prev"/>
		<updated>2020-03-20T02:33:43Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video from the lecture given on February 5, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec09-20200205.m4v is now available...&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;
The video from the lecture given on February 5, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec09-20200205.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Topics==&lt;br /&gt;
&lt;br /&gt;
* standard file descriptors (stdin, stdout, stderr) vs command line arguments vs environment variables&lt;br /&gt;
* open file descriptors, /proc&lt;br /&gt;
* files, inodes&lt;br /&gt;
* directories&lt;br /&gt;
* block devices, character devices&lt;br /&gt;
* superblocks, inode blocks, data blocks&lt;br /&gt;
* filesystems&lt;br /&gt;
* vfs&lt;br /&gt;
* mount&lt;br /&gt;
* fsck&lt;br /&gt;
* sshfs&lt;br /&gt;
&lt;br /&gt;
==Readings==&lt;br /&gt;
&lt;br /&gt;
At this point, we&amp;#039;ve covered most of these chapters:&lt;br /&gt;
&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-api.pdf&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-mechanisms.pdf  (partially)&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/vm-intro.pdf&lt;br /&gt;
&lt;br /&gt;
For files and filesystems, see these chapters&lt;br /&gt;
&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/file-intro.pdf&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/file-implementation.pdf (at a high level)&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/file-journaling.pdf (at a high level)&lt;br /&gt;
&lt;br /&gt;
The textbook goes into much more detail that I will on some topics, but it is worth looking through that detail if material covered in lecture seems too abstract.&lt;br /&gt;
&lt;br /&gt;
It is worth your time, however, looking through [http://pages.cs.wisc.edu/~remzi/OSTEP/ the textbook] from the beginning and skimming sections that we haven&amp;#039;t covered.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 9&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
information overload&lt;br /&gt;
* I&amp;#039;m covering a lot of material in this course, more than I expect you to retain.  I expect there to be areas that are not completely clear at the end of the semester.  That&amp;#039;s just the nature of modern operating systems.&lt;br /&gt;
* So here are some tips:&lt;br /&gt;
  - use the textbook, it gives a different presentation&lt;br /&gt;
  - take the tutorials seriously, that is where the learning should happen&lt;br /&gt;
  - ask questions&lt;br /&gt;
  - learn the tools&lt;br /&gt;
  &lt;br /&gt;
standard file descriptors (stdin, stdout, stderr) vs command line arguments vs environment variables&lt;br /&gt;
 - remember:&lt;br /&gt;
   - standard in is file descriptor 0&lt;br /&gt;
   - standard out is fd 1&lt;br /&gt;
   - standard error is fd 2&lt;br /&gt;
&lt;br /&gt;
What is a process, really?&lt;br /&gt;
 - address space + execution context&lt;br /&gt;
 - RAM plus CPU registers&lt;br /&gt;
&lt;br /&gt;
But if this is what a process is, how can it interact with the outside world?&lt;br /&gt;
&lt;br /&gt;
When a program is first run by execve, its inputs are as follows:&lt;br /&gt;
 - command line (supplied by execve)&lt;br /&gt;
 - environment variables (supplied by execve)&lt;br /&gt;
 - data, code in the executable file (supplied by execve)&lt;br /&gt;
 - file descriptors, i.e., files opened by whomever did execve&lt;br /&gt;
    - standard in, out, err are just open file descriptors&lt;br /&gt;
      that are expected to be there by default, by convention&lt;br /&gt;
&lt;br /&gt;
What is a file descriptor, really?&lt;br /&gt;
 - it is a value passed to the kernel so the kernel knows where we want to&lt;br /&gt;
   read from or write to (using a read or write system call)&lt;br /&gt;
 - they are &amp;quot;created&amp;quot; by open system calls and disposed of using close&lt;br /&gt;
 - if you don&amp;#039;t want to do reads and writes, you could have a custom system&lt;br /&gt;
   call to do the thing you want&lt;br /&gt;
 - but most I/O on UNIX is done using reads and writes&lt;br /&gt;
&lt;br /&gt;
0, 1, and 2 are the standard file descriptors, but we can of course open more&lt;br /&gt;
than three files - so file descriptors are allocated as needed&lt;br /&gt;
&lt;br /&gt;
File descriptors are references to open files&lt;br /&gt;
 - you can think of them as indices to arrays of structs&lt;br /&gt;
   *that are in the kernel* (you can&amp;#039;t access them directly from userspace)&lt;br /&gt;
&lt;br /&gt;
What is a file?&lt;br /&gt;
&lt;br /&gt;
To understand a file, we have to discuss filesystems.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you look at files and you do an ls -l, you&amp;#039;ll see a few different&lt;br /&gt;
characters in the first column&lt;br /&gt;
 * -: regular file&lt;br /&gt;
 * d: directory  &amp;lt;--- use getdents, not read, to get data&lt;br /&gt;
 * l: symbolic link  &amp;lt;--- use lstat to get info, not fstat&lt;br /&gt;
 * c: character device  &lt;br /&gt;
 * b: block device &lt;br /&gt;
 * p: named pipe (fifo) &amp;lt;--- way of doing | in a different way&lt;br /&gt;
      (will discuss later)&lt;br /&gt;
&lt;br /&gt;
These are all &amp;quot;files&amp;quot;, so you&amp;#039;ll open them and deal with them using file descriptors.  But they are very different things.&lt;br /&gt;
&lt;br /&gt;
Character devices and block devices represent devices&lt;br /&gt;
 - real hardware or virtual hardware&lt;br /&gt;
 - ways to interact with &amp;quot;the real world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
character devices are for byte-by-byte I/O, block devices are for&lt;br /&gt;
block-by-block I/O&lt;br /&gt;
&lt;br /&gt;
(A block is a fixed unit of storage, can vary, but is typically some small power of two, e.g. 512, 1024, 4096)&lt;br /&gt;
&lt;br /&gt;
Mass storage (hard disks, SSDs) is represented using block devices&lt;br /&gt;
everything else is a character device&lt;br /&gt;
&lt;br /&gt;
pseudo-tty&amp;#039;s are character devices&lt;br /&gt;
&lt;br /&gt;
Note that block and character devices don&amp;#039;t have a &amp;quot;size&amp;quot;&lt;br /&gt;
In that column in ls, you instead see two numbers separated by commas&lt;br /&gt;
  - first is the major number&lt;br /&gt;
  - second is the minor number&lt;br /&gt;
&lt;br /&gt;
These two numbers tell the kernel how to deal with this particular device&lt;br /&gt;
file.  (separate namespace for block and character devices)&lt;br /&gt;
&lt;br /&gt;
RAM is not a device, but...&lt;br /&gt;
 - on some UNIX flavors you can access RAM through a device but it isn&amp;#039;t&lt;br /&gt;
   generally done nowadays&lt;br /&gt;
 - RAM is accessed in the form of processes that do memory allocations&lt;br /&gt;
&lt;br /&gt;
But then what&amp;#039;s a filesystem?&lt;br /&gt;
 - a set of &amp;quot;files&amp;quot;, potentially of all types&lt;br /&gt;
 - what happens when accessing each file can vary completely&lt;br /&gt;
   depending on the type of filesystem&lt;br /&gt;
&lt;br /&gt;
To try and clarify&lt;br /&gt;
 - device files each have their own special code in the kernel to handle each&lt;br /&gt;
   (these are drivers)&lt;br /&gt;
 - regular files are implemented through filesystems, where common code&lt;br /&gt;
   implements open, read, write, etc for all files in the filesystem&lt;br /&gt;
   - different filesystems can have very different implementations&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ve seen many filesystems already in this class&lt;br /&gt;
 - ext4 (the files you regularly use)&lt;br /&gt;
 - proc (for /proc)&lt;br /&gt;
 - udev (for /dev)&lt;br /&gt;
&lt;br /&gt;
If you look in /proc/filesystems, you get a list of filesystems your current system supports.&lt;br /&gt;
&lt;br /&gt;
  - ones that say &amp;quot;nodev&amp;quot; are virtual filesystems that don&amp;#039;t result in&lt;br /&gt;
  storing data to any disk, they generally are ways to access kernel&lt;br /&gt;
  data structures or other things&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s say you attach a USB stick formatted with hfs+ (an older disk format used by MacOS)&lt;br /&gt;
 - you can use the same USB storage drivers as for any USB stick&lt;br /&gt;
 - but the kernel also needs a filesystem driver that understands hfs+&lt;br /&gt;
    - otherwise you can read the raw block-level data but won&amp;#039;t&lt;br /&gt;
      be able to see it as files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Think of a block device as an array, where each element of the array&lt;br /&gt;
is a 4096 byte buffer.&lt;br /&gt;
- filesystems are ways of turning this array into a set of files and&lt;br /&gt;
  directories&lt;br /&gt;
- as you can guess, there are *lots* of ways of doing this, with different tradeoffs&lt;br /&gt;
- any OS can in principle read any filesystem with the right data&lt;br /&gt;
  - for social and economic rather than technical reasons, Linux is much&lt;br /&gt;
    better at reading MacOS and Windows filesystems than the reverse&lt;br /&gt;
&lt;br /&gt;
Roughly speaking, you can use some sets of blocks to store directories, and&lt;br /&gt;
the rest for data&lt;br /&gt;
  - so the directory blocks would contain filenames and lists of data blocks&lt;br /&gt;
    containing the data in the files&lt;br /&gt;
&lt;br /&gt;
But UNIX doesn&amp;#039;t do things this way.  It adds a level of indirection.&lt;br /&gt;
&lt;br /&gt;
So you have three kinds of blocks&lt;br /&gt;
 - directory blocks&lt;br /&gt;
 - data blocks&lt;br /&gt;
 - *inode* blocks&lt;br /&gt;
&lt;br /&gt;
 - inodes contain all the metadata of files *except* their name&lt;br /&gt;
    - size of file, owner, permissions, timestamps, and pointers&lt;br /&gt;
      to the data blocks&lt;br /&gt;
&lt;br /&gt;
 - directories then just list filenames and inode numbers&lt;br /&gt;
&lt;br /&gt;
 - (with symbolic links, the inode contains a filename)&lt;br /&gt;
&lt;br /&gt;
 - inodes enable hard links&lt;br /&gt;
&lt;br /&gt;
 - windows shortcuts are similar to symbolic links (except symbolic links on&lt;br /&gt;
   UNIX/Linux work almost everywhere a regular file would)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;mounting&amp;quot; a filesystem means associating an empty directory with a filesystem&lt;br /&gt;
 - on boot, the directory / is associated with the &amp;quot;root&amp;quot; filesystem&lt;br /&gt;
    (filesystem that is at the base of the filesystem hierarchy, nothing&lt;br /&gt;
     to do with the root user)&lt;br /&gt;
 - other filesystems are then mounted on directories in this root filesystem&lt;br /&gt;
&lt;br /&gt;
it used to be df would only output a few things&lt;br /&gt;
 - we&amp;#039;re using a lot more mounts and filesystems than we used to!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>