<?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_2019F_Lecture_17</id>
	<title>Operating Systems 2019F Lecture 17 - 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_2019F_Lecture_17"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_17&amp;action=history"/>
	<updated>2026-05-18T20:02:23Z</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_2019F_Lecture_17&amp;diff=22539&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on November 8, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec17-20191108.m4v is now available]....&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_17&amp;diff=22539&amp;oldid=prev"/>
		<updated>2020-03-20T02:08:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on November 8, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec17-20191108.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;
Video from the lecture given on November 8, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec17-20191108.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 17&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
special files: files that aren&amp;#039;t directories or regular files&lt;br /&gt;
&lt;br /&gt;
Three kinds of special files:&lt;br /&gt;
* character devices&lt;br /&gt;
* block devices&lt;br /&gt;
* named pipes/FIFOs&lt;br /&gt;
&lt;br /&gt;
first letter of permission block:&lt;br /&gt;
 -   regular file  (hard links)&lt;br /&gt;
 d   directory&lt;br /&gt;
 l   symbolic link&lt;br /&gt;
&lt;br /&gt;
 b   block device&lt;br /&gt;
 c   character device      &amp;lt;--- these three are &amp;quot;special files&amp;quot;&lt;br /&gt;
 p   named pipe/FIFO&lt;br /&gt;
&lt;br /&gt;
A special file really isn&amp;#039;t a file; instead, it is an interface that&lt;br /&gt;
uses a file-like API&lt;br /&gt;
  - you use standard file system calls to do weird things&lt;br /&gt;
&lt;br /&gt;
Note that special files way predate things like /proc&lt;br /&gt;
&lt;br /&gt;
Why do we have them?&lt;br /&gt;
 * block devices represent mass storage (disks)&lt;br /&gt;
 * character devices represent most other I/O devices&lt;br /&gt;
 * pipes are inter-process communication (IPC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Why do we need block devices?&lt;br /&gt;
 - manipulate mass storage, e.g.&lt;br /&gt;
   - format disks (lay down filesystem on storage)&lt;br /&gt;
   - repair/recover filesystems on disk&lt;br /&gt;
   - low-level backup&lt;br /&gt;
&lt;br /&gt;
Normally you shouldn&amp;#039;t be playing with block devices!&lt;br /&gt;
 - because you interact with them indirectly via mounted filesystems&lt;br /&gt;
&lt;br /&gt;
The kernel implementation of block devices is a bit complex&lt;br /&gt;
 - lots of machinery for caching&lt;br /&gt;
&lt;br /&gt;
If you wanted to learn about how block devices work, look at the implementation of loopback devices, /dev/loopX&lt;br /&gt;
&lt;br /&gt;
Why &amp;quot;loopback&amp;quot;&lt;br /&gt;
 - normally you have this situation&lt;br /&gt;
&lt;br /&gt;
  filesystem    &amp;lt;-- /home/soma/foo&lt;br /&gt;
  mass storage  &amp;lt;-- /dev/sda&lt;br /&gt;
&lt;br /&gt;
So here foo is stored on /dev/sda&lt;br /&gt;
&lt;br /&gt;
-- but with a loopback filesystem&lt;br /&gt;
&lt;br /&gt;
  filesystem   &amp;lt;-- /mnt/somefile&lt;br /&gt;
  loopback     &amp;lt;-- /dev/loop0&lt;br /&gt;
  filesystem   &amp;lt;-- /home/soma/bigfile&lt;br /&gt;
  mass storage &amp;lt;-- /dev/sda&lt;br /&gt;
&lt;br /&gt;
/home/soma/bigfile is mounted on /mnt&lt;br /&gt;
storage for bigfile (and hence somefile) is actually on /dev/sda&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Loopback devices are very useful for&lt;br /&gt;
 - learning about filesystems&lt;br /&gt;
 - making ISOs (CD/DVDs)&lt;br /&gt;
 - accessing virtual disks of virtual machines&lt;br /&gt;
&lt;br /&gt;
Note the loopback device just allows us to reuse the filesystem implementations already in the kernel.  You could always pull them out and treat the file as one with a really baroque storage format&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Character devices&lt;br /&gt;
 - everything but mass storage&lt;br /&gt;
 - tapes, mouse, keyboard, ttys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
named pipes/FIFOs&lt;br /&gt;
 - examples of the producer/consumer problem&lt;br /&gt;
 - need to pause producer when consumer gets behind&lt;br /&gt;
 - need to pause consumer when producer gets behind&lt;br /&gt;
 - use buffering to allow each to run at their own pace (when not paused)&lt;br /&gt;
&lt;br /&gt;
General pattern&lt;br /&gt;
 - producer runs until it fills a buffer.  When buffer is full, pause producer&lt;br /&gt;
 - consumer runs until buffer is empty.  When buffer is empty, pause consumer&lt;br /&gt;
 - must resume producer when buffer is no longer full&lt;br /&gt;
 - must resume consumer when buffer is no longer empty&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What is the mechanism for pausing and resuming with pipes on UNIX?&lt;br /&gt;
 - put the process to sleep when it reads or writes&lt;br /&gt;
 - producers write, consumers read&lt;br /&gt;
&lt;br /&gt;
How do we make pipes?&lt;br /&gt;
 - at command line, use |&lt;br /&gt;
 - in a program, use pipe() or pipe2() and generally dup2()&lt;br /&gt;
   - consumer gets first fd, puts it on stdin (fd 0)&lt;br /&gt;
   - producer gets second fd, puts it on stdout (fd 1)  &amp;lt;--- said stdin in lecture, that is wrong&lt;br /&gt;
   - note the producer is the one to the left of |, consumer is to the right&lt;br /&gt;
 - mkfifo or mknod p&lt;br /&gt;
   - allows for &amp;quot;persistent&amp;quot; pipes that are used by multiple processes&lt;br /&gt;
     at different times, a way to do rendezvous&lt;br /&gt;
&lt;br /&gt;
eBPF versus modules&lt;br /&gt;
 - both let you inject code into a Linux kernel&lt;br /&gt;
 - eBPF is safe and restricted&lt;br /&gt;
 - modules are not safe and are not restricted&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>