<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Krithikasaravanan</id>
	<title>Soma-notes - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Krithikasaravanan"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Krithikasaravanan"/>
	<updated>2026-06-02T22:28:04Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_20&amp;diff=21325</id>
		<title>Operating Systems 2017F Lecture 20</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_20&amp;diff=21325"/>
		<updated>2017-11-29T02:17:52Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec20-28Nov2017.mp4 Class Video]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 20&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
When we run &amp;quot;ls&amp;quot; on an sshfs-mounted filesystem&lt;br /&gt;
* ls makes system calls (open, getdents) to the local Linux kernel&lt;br /&gt;
* the local kernel sees filesystem is FUSE, calls FUSE routines for open, getdents (via vfs abstraction)&lt;br /&gt;
* FUSE calls the sshfs process that mounted the filesystem&lt;br /&gt;
* sshfs process sends request to remote system&lt;br /&gt;
  - via socket system calls&lt;br /&gt;
* remote sshd process receives request (via system calls)&lt;br /&gt;
* remote sshd process accesses local filesystem&lt;br /&gt;
  - makes open, getdents system calls&lt;br /&gt;
  - remote kernel checks vfs, calls ext4 routines to access data&lt;br /&gt;
* remote sshd process responds to request (via system calls)&lt;br /&gt;
* local sshfs process receives response (via system calls)&lt;br /&gt;
* local sshfs process responds to FUSE request&lt;br /&gt;
* FUSE passes data back to vfs layer, then back to requesting process&lt;br /&gt;
&lt;br /&gt;
Normal file access permission check&lt;br /&gt;
 - compare uid, gid of file with uid, gid of process&lt;br /&gt;
&lt;br /&gt;
But really...&lt;br /&gt;
 - compares it with fsuid, fsgid of process&lt;br /&gt;
    - which is normally same as euid, egid of process&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
&lt;br /&gt;
Assignment 4 will be autograded and in fill in the blank form. This will not be like the final exam. &amp;lt;br&amp;gt;&lt;br /&gt;
You should think about who is doing what?  Otherwise FUSE won&#039;t make much sense &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Inode numbers completely changed when you use ssh. It starts with 1 from &amp;quot;.&amp;quot; (root) and increments from there. &amp;lt;br&amp;gt;&lt;br /&gt;
Inodes come from filesystem you are acessing &amp;lt;br&amp;gt;&lt;br /&gt;
He used df to find filesystem info &amp;lt;br&amp;gt;&lt;br /&gt;
The used Commands: mount | grep ubuntu and mount | grep vda1 to find type of filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
In the SSH there is the filesystem type &amp;quot;fuse.sshfs&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
When you run strace on ls on the two terminals (ssh connection and the local one) you see similar output &amp;lt;br&amp;gt;&lt;br /&gt;
When we run &amp;quot;ls&amp;quot; on an ssh-mounted filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* ls makes system calls (open, getdents) to the local Linux kernel &amp;lt;br&amp;gt;&lt;br /&gt;
* the local kernel sees the filesystem is FUSE, calls DUSE routines for open, getdents (via vfs abstraction) &amp;lt;br&amp;gt;&lt;br /&gt;
* FUSE calls the sshfs process that mounted the filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* sshfs process sends request to remote system &amp;lt;br&amp;gt;&lt;br /&gt;
- via socket system calls&amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process receives request (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process receives requests (via system calls)&amp;lt;br&amp;gt;&lt;br /&gt;
- makes open, getdents sytem calls &amp;lt;br&amp;gt;&lt;br /&gt;
- rmeote kernel checks vfs, calls ext4 routines to access data &amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process responds to requests  (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* local sshfs process receives response  (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* local sshfs process responds to FUSE request  (via system calls)&amp;lt;br&amp;gt;&lt;br /&gt;
* FUSE passes data back to vfs layer, then back to requesting process &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; If you look as lsmod | less you see a ton of modules. Some of the modules are not necessary to mount the root filesystem.&amp;lt;br&amp;gt;&lt;br /&gt;
ls /lib/modules there are directories that store the kernel modules &amp;lt;br&amp;gt;&lt;br /&gt;
You have to have a filesystem that you mount initially that has a bunch of modules in it. Thus, there is an initial root file system that is necessary to load everything else &amp;lt;br&amp;gt;&lt;br /&gt;
This is the initial RAM disk. This filesystem loads the modules needed for the real filesystem. &amp;lt;br&amp;gt;&lt;br /&gt;
To remove a file I need to remove the hardlink from the directory where the hardlink exists &amp;lt;br&amp;gt;&lt;br /&gt;
The password files maps usernames to user id&#039;s (Linux does not care about your username) &amp;lt;br&amp;gt;&lt;br /&gt;
Normal file access permission check br&amp;gt;&lt;br /&gt;
- compare uid, gid of file with uid, gid of process &amp;lt;br&amp;gt;&lt;br /&gt;
But really: &amp;lt;br&amp;gt;&lt;br /&gt;
- compares it with fsuid, fsgid of process &amp;lt;br&amp;gt;&lt;br /&gt;
- which is normally same as euid, egid of process &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Sshfs&amp;lt;br&amp;gt;&lt;br /&gt;
* Inode values are different in remote vm vs local vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Values increment from 1 in local vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Who&#039;s supplying the inode values?&amp;lt;br&amp;gt;&lt;br /&gt;
** Ext4 filesystem in local vm&amp;lt;br&amp;gt;&lt;br /&gt;
** Fuse.sshfs filesystem in remote vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Filesystem determines the interpretation of inode values&amp;lt;br&amp;gt;&lt;br /&gt;
* Inodes have no meaning outside its filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* Local to its filesystem =&amp;gt; hardlinks are different too&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;strace ls&amp;quot; in both output the same thing&amp;lt;br&amp;gt;&lt;br /&gt;
* Vfs not built into original unix filesystems&amp;lt;br&amp;gt;&lt;br /&gt;
* Try &amp;quot;strace&amp;quot;ing the sshfs call, see how its interacts with fuse&amp;lt;br&amp;gt;&lt;br /&gt;
* Don&#039;t need to know exact system calls, but you should know when it has to make system calls and why&amp;lt;br&amp;gt;&lt;br /&gt;
** Needs to access files over the network&amp;lt;br&amp;gt;&lt;br /&gt;
* Understand why you can&#039;t do this with regular library calls&amp;lt;br&amp;gt;&lt;br /&gt;
* Removing the root filesystem will trigger a kernel panic&amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel will prevent you from unmounting filesystems that contain other filesystems&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel modules located in &amp;quot;/lib/modules/&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* Initial filesystem is loaded into kernel&amp;lt;br&amp;gt;&lt;br /&gt;
** Fake filesystem, throw away after loaded, not persistent&amp;lt;br&amp;gt;&lt;br /&gt;
** Ram disk = filesystem stored in ram&amp;lt;br&amp;gt;&lt;br /&gt;
** Gets the system up to the point where the kernel can load the real filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
** Bootloader has to load both kernel and the initial ram disk into ram&amp;lt;br&amp;gt;&lt;br /&gt;
** Ram disks located in &amp;quot;/boot = initrd.img&amp;lt;...&amp;gt;&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel version specific&amp;lt;br&amp;gt;&lt;br /&gt;
** Generated as part of installation of kernel&amp;lt;br&amp;gt;&lt;br /&gt;
* Cpio: copies files to and from archives&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* What determines whether you can access a file?&amp;lt;br&amp;gt;&lt;br /&gt;
** The filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* How to map from user id to username?&amp;lt;br&amp;gt;&lt;br /&gt;
** Recall that&amp;lt;br&amp;gt;&lt;br /&gt;
- Kernel knows nothing about usernames&amp;lt;br&amp;gt;&lt;br /&gt;
- This is a userspace process&amp;lt;br&amp;gt;&lt;br /&gt;
- Looks in local password file&amp;lt;br&amp;gt;&lt;br /&gt;
* What determines whether an operation is allowed?&amp;lt;br&amp;gt;&lt;br /&gt;
** Checks to see who owns the file&amp;lt;br&amp;gt;&lt;br /&gt;
** Compare uid, gid of file with uid, gid of process&amp;lt;br&amp;gt;&lt;br /&gt;
* In remote system, sftp does file access checks&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_20&amp;diff=21324</id>
		<title>Operating Systems 2017F Lecture 20</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_20&amp;diff=21324"/>
		<updated>2017-11-29T02:17:08Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec20-28Nov2017.mp4 Class Video]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 20&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
When we run &amp;quot;ls&amp;quot; on an sshfs-mounted filesystem&lt;br /&gt;
* ls makes system calls (open, getdents) to the local Linux kernel&lt;br /&gt;
* the local kernel sees filesystem is FUSE, calls FUSE routines for open, getdents (via vfs abstraction)&lt;br /&gt;
* FUSE calls the sshfs process that mounted the filesystem&lt;br /&gt;
* sshfs process sends request to remote system&lt;br /&gt;
  - via socket system calls&lt;br /&gt;
* remote sshd process receives request (via system calls)&lt;br /&gt;
* remote sshd process accesses local filesystem&lt;br /&gt;
  - makes open, getdents system calls&lt;br /&gt;
  - remote kernel checks vfs, calls ext4 routines to access data&lt;br /&gt;
* remote sshd process responds to request (via system calls)&lt;br /&gt;
* local sshfs process receives response (via system calls)&lt;br /&gt;
* local sshfs process responds to FUSE request&lt;br /&gt;
* FUSE passes data back to vfs layer, then back to requesting process&lt;br /&gt;
&lt;br /&gt;
Normal file access permission check&lt;br /&gt;
 - compare uid, gid of file with uid, gid of process&lt;br /&gt;
&lt;br /&gt;
But really...&lt;br /&gt;
 - compares it with fsuid, fsgid of process&lt;br /&gt;
    - which is normally same as euid, egid of process&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
&lt;br /&gt;
Assignment 4 will be autograded and in fill in the blank form. This will not be like the final exam. &amp;lt;br&amp;gt;&lt;br /&gt;
You should think about who is doing what?  Otherwise FUSE won&#039;t make much sense &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Inode numbers completely changed when you use ssh. It starts with 1 from &amp;quot;.&amp;quot; (root) and increments from there. &amp;lt;br&amp;gt;&lt;br /&gt;
Inodes come from filesystem you are acessing &amp;lt;br&amp;gt;&lt;br /&gt;
He used df to find filesystem info &amp;lt;br&amp;gt;&lt;br /&gt;
The used Commands: mount | grep ubuntu and mount | grep vda1 to find type of filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
In the SSH there is the filesystem type &amp;quot;fuse.sshfs&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
When you run strace on ls on the two terminals (ssh connection and the local one) you see similar output &amp;lt;br&amp;gt;&lt;br /&gt;
When we run &amp;quot;ls&amp;quot; on an ssh-mounted filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* ls makes system calls (open, getdents) to the local Linux kernel &amp;lt;br&amp;gt;&lt;br /&gt;
* the local kernel sees the filesystem is FUSE, calls DUSE routines for open, getdents (via vfs abstraction) &amp;lt;br&amp;gt;&lt;br /&gt;
* FUSE calls the sshfs process that mounted the filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* sshfs process sends request to remote system &amp;lt;br&amp;gt;&lt;br /&gt;
- via socket system calls&amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process receives request (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process receives requests (via system calls)&amp;lt;br&amp;gt;&lt;br /&gt;
- makes open, getdents sytem calls &amp;lt;br&amp;gt;&lt;br /&gt;
- rmeote kernel checks vfs, calls ext4 routines to access data &amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process responds to requests  (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* local sshfs process receives response  (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* local sshfs process responds to FUSE request  (via system calls)&amp;lt;br&amp;gt;&lt;br /&gt;
* FUSE passes data back to vfs layer, then back to requesting process &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; If you look as lsmod | less you see a ton of modules. Some of the modules are not necessary to mount the root filesystem.&amp;lt;br&amp;gt;&lt;br /&gt;
ls /lib/modules there are directories that store the kernel modules &amp;lt;br&amp;gt;&lt;br /&gt;
You have to have a filesystem that you mount initially that has a bunch of modules in it. Thus, there is an initial root file system that is necessary to load everything else &amp;lt;br&amp;gt;&lt;br /&gt;
This is the initial RAM disk. This filesystem loads the modules needed for the real filesystem. &amp;lt;br&amp;gt;&lt;br /&gt;
To remove a file I need to remove the hardlink from the directory where the hardlink exists &amp;lt;br&amp;gt;&lt;br /&gt;
The password files maps usernames to user id&#039;s (Linux does not care about your username) &amp;lt;br&amp;gt;&lt;br /&gt;
Normal file access permission check br&amp;gt;&lt;br /&gt;
- compare uid, gid of file with uid, gid of process &amp;lt;br&amp;gt;&lt;br /&gt;
But really: &amp;lt;br&amp;gt;&lt;br /&gt;
- compares it with fsuid, fsgid of process &amp;lt;br&amp;gt;&lt;br /&gt;
- which is normally same as euid, egid of process &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Sshfs&amp;lt;br&amp;gt;&lt;br /&gt;
* Inode values are different in remote vm vs local vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Values increment from 1 in local vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Who&#039;s supplying the inode values?&amp;lt;br&amp;gt;&lt;br /&gt;
** Ext4 filesystem in local vm&amp;lt;br&amp;gt;&lt;br /&gt;
** Fuse.sshfs filesystem in remote vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Filesystem determines the interpretation of inode values&amp;lt;br&amp;gt;&lt;br /&gt;
* Inodes have no meaning outside its filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* Local to its filesystem =&amp;gt; hardlinks are different too&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;strace ls&amp;quot; in both output the same thing&amp;lt;br&amp;gt;&lt;br /&gt;
* Vfs not built into original unix filesystems&amp;lt;br&amp;gt;&lt;br /&gt;
* Try &amp;quot;strace&amp;quot;ing the sshfs call, see how its interacts with fuse&amp;lt;br&amp;gt;&lt;br /&gt;
* Don&#039;t need to know exact system calls, but you should know when it has to make system calls and why&amp;lt;br&amp;gt;&lt;br /&gt;
** Needs to access files over the network&amp;lt;br&amp;gt;&lt;br /&gt;
* Understand why you can&#039;t do this with regular library calls&amp;lt;br&amp;gt;&lt;br /&gt;
* Removing the root filesystem will trigger a kernel panic&amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel will prevent you from unmounting filesystems that contain other filesystems&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel modules located in &amp;quot;/lib/modules/&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* Initial filesystem is loaded into kernel&amp;lt;br&amp;gt;&lt;br /&gt;
** Fake filesystem, throw away after loaded, not persistent&amp;lt;br&amp;gt;&lt;br /&gt;
** Ram disk = filesystem stored in ram&amp;lt;br&amp;gt;&lt;br /&gt;
** Gets the system up to the point where the kernel can load the real filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
** Bootloader has to load both kernel and the initial ram disk into ram&amp;lt;br&amp;gt;&lt;br /&gt;
** Ram disks located in &amp;quot;/boot = initrd.img&amp;lt;...&amp;gt;&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel version specific&amp;lt;br&amp;gt;&lt;br /&gt;
** Generated as part of installation of kernel&amp;lt;br&amp;gt;&lt;br /&gt;
* Cpio: copies files to and from archives&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* What determines whether you can access a file?&amp;lt;br&amp;gt;&lt;br /&gt;
** The filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* How to map from user id to username?&amp;lt;br&amp;gt;&lt;br /&gt;
** Recall that&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel knows nothing about usernames&amp;lt;br&amp;gt;&lt;br /&gt;
* This is a userspace process&amp;lt;br&amp;gt;&lt;br /&gt;
* Looks in local password file&amp;lt;br&amp;gt;&lt;br /&gt;
* What determines whether an operation is allowed?&amp;lt;br&amp;gt;&lt;br /&gt;
** Checks to see who owns the file&amp;lt;br&amp;gt;&lt;br /&gt;
** Compare uid, gid of file with uid, gid of process&amp;lt;br&amp;gt;&lt;br /&gt;
* In remote system, sftp does file access checks&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21298</id>
		<title>Operating Systems 2017F Lecture 16</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21298"/>
		<updated>2017-11-24T08:38:56Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 7, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec16-09Nov2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec16/newgetpid.zip Code for download]&lt;br /&gt;
&lt;br /&gt;
==newgetpid.c==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot; line&amp;gt;&lt;br /&gt;
/* Code derived from:&lt;br /&gt;
  https://appusajeev.wordpress.com/2011/06/18/writing-a-linux-character-device-driver/&lt;br /&gt;
  and&lt;br /&gt;
  http://pete.akeo.ie/2011/08/writing-linux-device-driver-for-kernels.html&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;linux/module.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/fs.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/device.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/init.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/kernel.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/sched.h&amp;gt;&lt;br /&gt;
#include &amp;lt;asm/uaccess.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define dbg(format, arg...) do { if (debug) pr_info(CLASS_NAME &amp;quot;: %s: &amp;quot; format, __FUNCTION__, ## arg); } while (0)&lt;br /&gt;
#define err(format, arg...) pr_err(CLASS_NAME &amp;quot;: &amp;quot; format, ## arg)&lt;br /&gt;
#define info(format, arg...) pr_info(CLASS_NAME &amp;quot;: &amp;quot; format, ## arg)&lt;br /&gt;
#define warn(format, arg...) pr_warn(CLASS_NAME &amp;quot;: &amp;quot; format, ## arg)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define DEVICE_NAME &amp;quot;newgetpid&amp;quot;&lt;br /&gt;
#define CLASS_NAME &amp;quot;comp3000&amp;quot;&lt;br /&gt;
&lt;br /&gt;
static struct class* newgetpid_class = NULL;&lt;br /&gt;
static struct device* newgetpid_device = NULL;&lt;br /&gt;
static int newgetpid_major;&lt;br /&gt;
&lt;br /&gt;
static int newgetpid_open(struct inode *the_inode, struct file *f)&lt;br /&gt;
{&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static ssize_t newgetpid_read(struct file *f, char *buf, size_t len, loff_t *offset)&lt;br /&gt;
{&lt;br /&gt;
        size_t i, msglen;&lt;br /&gt;
        pid_t thepid;&lt;br /&gt;
&lt;br /&gt;
        char message[100];&lt;br /&gt;
        &lt;br /&gt;
        if (*offset &amp;gt; 0) {&lt;br /&gt;
                return 0;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        thepid = task_tgid_vnr(current);&lt;br /&gt;
&lt;br /&gt;
        snprintf(message, 100, &amp;quot;Your PID is %d!\n&amp;quot;, thepid);&lt;br /&gt;
        &lt;br /&gt;
        msglen = strlen(message);&lt;br /&gt;
&lt;br /&gt;
        if (len &amp;lt; msglen) {&lt;br /&gt;
                msglen = len;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        for (i = 0; i &amp;lt; msglen; i++) {&lt;br /&gt;
                put_user(message[i], buf++);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        *offset = i;&lt;br /&gt;
&lt;br /&gt;
        return i;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int newgetpid_release(struct inode *the_inode, struct file *f)&lt;br /&gt;
{&lt;br /&gt;
        printk(KERN_ALERT &amp;quot;Newgetpid device closed\n&amp;quot;);&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
static struct file_operations newgetpid_fops = {&lt;br /&gt;
        .open = newgetpid_open,&lt;br /&gt;
        .read = newgetpid_read,&lt;br /&gt;
        .release = newgetpid_release,&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
static char *newgetpid_devnode(struct device *dev, umode_t *mode)&lt;br /&gt;
{&lt;br /&gt;
        if (mode)&lt;br /&gt;
	        *mode = 0444;&lt;br /&gt;
        return NULL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int __init newgetpid_init(void)&lt;br /&gt;
{&lt;br /&gt;
        int retval;&lt;br /&gt;
  &lt;br /&gt;
        newgetpid_major = register_chrdev(0, DEVICE_NAME, &amp;amp;newgetpid_fops);&lt;br /&gt;
        if (newgetpid_major &amp;lt; 0) {&lt;br /&gt;
                err(&amp;quot;failed to register device: error %d\n&amp;quot;, newgetpid_major);&lt;br /&gt;
                retval = newgetpid_major;&lt;br /&gt;
                goto failed_chrdevreg;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        newgetpid_class = class_create(THIS_MODULE, CLASS_NAME);&lt;br /&gt;
        if (IS_ERR(newgetpid_class)) {&lt;br /&gt;
                err(&amp;quot;failed to register device class &#039;%s&#039;\n&amp;quot;, CLASS_NAME);&lt;br /&gt;
                retval = PTR_ERR(newgetpid_class);&lt;br /&gt;
                goto failed_classreg;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
	newgetpid_class-&amp;gt;devnode = newgetpid_devnode;&lt;br /&gt;
&lt;br /&gt;
        newgetpid_device = device_create(newgetpid_class, NULL, MKDEV(newgetpid_major, 0),&lt;br /&gt;
                                    NULL, DEVICE_NAME);&lt;br /&gt;
&lt;br /&gt;
        if (IS_ERR(newgetpid_device)) {&lt;br /&gt;
                err(&amp;quot;failed to create device &#039;%s&#039;\n&amp;quot;, DEVICE_NAME);&lt;br /&gt;
                retval = PTR_ERR(newgetpid_device);&lt;br /&gt;
                goto failed_devreg;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        info(&amp;quot;Newgetpid device registered using major %d.\n&amp;quot;, newgetpid_major);&lt;br /&gt;
        &lt;br /&gt;
        return 0;&lt;br /&gt;
        &lt;br /&gt;
 failed_devreg:&lt;br /&gt;
        class_unregister(newgetpid_class);&lt;br /&gt;
        class_destroy(newgetpid_class);&lt;br /&gt;
 failed_classreg:&lt;br /&gt;
        unregister_chrdev(newgetpid_major, DEVICE_NAME);&lt;br /&gt;
 failed_chrdevreg:&lt;br /&gt;
        return -1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void __exit newgetpid_exit(void)&lt;br /&gt;
{&lt;br /&gt;
        device_destroy(newgetpid_class, MKDEV(newgetpid_major, 0));&lt;br /&gt;
        class_unregister(newgetpid_class);&lt;br /&gt;
        class_destroy(newgetpid_class);&lt;br /&gt;
        unregister_chrdev(newgetpid_major, &amp;quot;newgetpid&amp;quot;);&lt;br /&gt;
        info(&amp;quot;Unloading Newgetpid module.\n&amp;quot;);&lt;br /&gt;
        return;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
module_init(newgetpid_init);&lt;br /&gt;
module_exit(newgetpid_exit);&lt;br /&gt;
&lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);&lt;br /&gt;
MODULE_AUTHOR(&amp;quot;Anil Somayaji &amp;lt;soma@scs.carleton.ca&amp;gt;&amp;quot;);&lt;br /&gt;
MODULE_DESCRIPTION(&amp;quot;A write newgetpid character device module&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Makefile==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=make line&amp;gt;&lt;br /&gt;
obj-m := newgetpid.o&lt;br /&gt;
KDIR := /lib/modules/$(shell uname -r)/build&lt;br /&gt;
PWD := $(shell pwd)&lt;br /&gt;
default:&lt;br /&gt;
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
What determines what files you can and cannot create?&amp;lt;br&amp;gt;&lt;br /&gt;
* Ssh privileges &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Anything that you can do as an ssh user you can do in the vm, just doing file operations&amp;lt;br&amp;gt;&lt;br /&gt;
* Sshfs means when you do read and write system calls for programs in a directory it also does it on the remote machine&amp;lt;br&amp;gt;&lt;br /&gt;
* Ssh is a good tool to access remote files locally, we will use it to edit modules&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Ones/newgetpid program:&amp;lt;br&amp;gt;&lt;br /&gt;
* We want to extend its functionality in a specific way&amp;lt;br&amp;gt;&lt;br /&gt;
* We want to access info about the process that made the system call&amp;lt;br&amp;gt;&lt;br /&gt;
* Let&#039;s get current processes id&amp;lt;br&amp;gt;&lt;br /&gt;
** Normally we would use getpid&amp;lt;br&amp;gt;&lt;br /&gt;
** But we can&#039;t make system calls in kernel space&amp;lt;br&amp;gt;&lt;br /&gt;
** But we can call the function that the system call uses or just copy the functionality&amp;lt;br&amp;gt;&lt;br /&gt;
* Code for this is in &amp;quot;kernel/sys.c&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Syscall_define0:&amp;lt;br&amp;gt;&lt;br /&gt;
* Macro that expands&amp;lt;br&amp;gt;&lt;br /&gt;
* Defines system calls with &amp;quot;getpid&amp;quot; and takes no arguments&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Can use the code inside the function but not the function itself in the kernel&amp;lt;br&amp;gt;&lt;br /&gt;
* Getpid returns a pid_t&amp;lt;br&amp;gt;&lt;br /&gt;
* Instead of get_ones returning all those ones we want it to return the pid&amp;lt;br&amp;gt;&lt;br /&gt;
* Lets try to get it to output a basic string with the pid&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How does printk work?&amp;lt;br&amp;gt;&lt;br /&gt;
* Printk sends its output to the kernel log&amp;lt;br&amp;gt;&lt;br /&gt;
* We changed the name to &amp;quot;newgetpid&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* How do we convert int to string to print the pid?&amp;lt;br&amp;gt;&lt;br /&gt;
** Make a buffer, let&#039;s call it &amp;quot;message&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why does the pid keep incrementing each time we call &amp;quot;cat /dev/newgetpid&amp;quot;?&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;Cat&amp;quot; spawns a process so every time we do a fork we get a new pid&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why can we use snprintf but not printf?&amp;lt;br&amp;gt;&lt;br /&gt;
* We include &amp;quot;linux/kernel.h&amp;quot; which defines snprintf but not printf&amp;lt;br&amp;gt;&lt;br /&gt;
* Printf assumes we have a standard output to print to&amp;lt;br&amp;gt;&lt;br /&gt;
* Snprintf only needs character arrays for it to work&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Read functionality uses an API&amp;lt;br&amp;gt;&lt;br /&gt;
* Adding new functionality like &amp;quot;write&amp;quot; is easy, just look at the standard API and original kernel source&amp;lt;br&amp;gt;&lt;br /&gt;
* All device files have their own custom read and write functions&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why do we use goto&#039;s?&amp;lt;br&amp;gt;&lt;br /&gt;
* C has no exception handling functionality so we implement our own&amp;lt;br&amp;gt;&lt;br /&gt;
* Jumps to error paths: failed_devreg, failed_classreg, failed_chrdevreg (very important in the kernel)&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel needs to be able to handle it&#039;s own errors&amp;lt;br&amp;gt;&lt;br /&gt;
* Needs to free up allocated resources, &amp;quot;undo&amp;quot; everything&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;.&amp;quot; is the current directory&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;..&amp;quot; is the parent directory&amp;lt;br&amp;gt;&lt;br /&gt;
** Introduces another hardlink&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* In order to build kernel modules, you need to have the headers associated with the current kernel you&#039;re running&lt;br /&gt;
* Modules are specified to a particular version of the kernel&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21297</id>
		<title>Operating Systems 2017F Lecture 16</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21297"/>
		<updated>2017-11-24T08:37:53Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 7, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec16-09Nov2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec16/newgetpid.zip Code for download]&lt;br /&gt;
&lt;br /&gt;
==newgetpid.c==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot; line&amp;gt;&lt;br /&gt;
/* Code derived from:&lt;br /&gt;
  https://appusajeev.wordpress.com/2011/06/18/writing-a-linux-character-device-driver/&lt;br /&gt;
  and&lt;br /&gt;
  http://pete.akeo.ie/2011/08/writing-linux-device-driver-for-kernels.html&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;linux/module.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/fs.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/device.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/init.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/kernel.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/sched.h&amp;gt;&lt;br /&gt;
#include &amp;lt;asm/uaccess.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define dbg(format, arg...) do { if (debug) pr_info(CLASS_NAME &amp;quot;: %s: &amp;quot; format, __FUNCTION__, ## arg); } while (0)&lt;br /&gt;
#define err(format, arg...) pr_err(CLASS_NAME &amp;quot;: &amp;quot; format, ## arg)&lt;br /&gt;
#define info(format, arg...) pr_info(CLASS_NAME &amp;quot;: &amp;quot; format, ## arg)&lt;br /&gt;
#define warn(format, arg...) pr_warn(CLASS_NAME &amp;quot;: &amp;quot; format, ## arg)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define DEVICE_NAME &amp;quot;newgetpid&amp;quot;&lt;br /&gt;
#define CLASS_NAME &amp;quot;comp3000&amp;quot;&lt;br /&gt;
&lt;br /&gt;
static struct class* newgetpid_class = NULL;&lt;br /&gt;
static struct device* newgetpid_device = NULL;&lt;br /&gt;
static int newgetpid_major;&lt;br /&gt;
&lt;br /&gt;
static int newgetpid_open(struct inode *the_inode, struct file *f)&lt;br /&gt;
{&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static ssize_t newgetpid_read(struct file *f, char *buf, size_t len, loff_t *offset)&lt;br /&gt;
{&lt;br /&gt;
        size_t i, msglen;&lt;br /&gt;
        pid_t thepid;&lt;br /&gt;
&lt;br /&gt;
        char message[100];&lt;br /&gt;
        &lt;br /&gt;
        if (*offset &amp;gt; 0) {&lt;br /&gt;
                return 0;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        thepid = task_tgid_vnr(current);&lt;br /&gt;
&lt;br /&gt;
        snprintf(message, 100, &amp;quot;Your PID is %d!\n&amp;quot;, thepid);&lt;br /&gt;
        &lt;br /&gt;
        msglen = strlen(message);&lt;br /&gt;
&lt;br /&gt;
        if (len &amp;lt; msglen) {&lt;br /&gt;
                msglen = len;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        for (i = 0; i &amp;lt; msglen; i++) {&lt;br /&gt;
                put_user(message[i], buf++);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        *offset = i;&lt;br /&gt;
&lt;br /&gt;
        return i;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int newgetpid_release(struct inode *the_inode, struct file *f)&lt;br /&gt;
{&lt;br /&gt;
        printk(KERN_ALERT &amp;quot;Newgetpid device closed\n&amp;quot;);&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
static struct file_operations newgetpid_fops = {&lt;br /&gt;
        .open = newgetpid_open,&lt;br /&gt;
        .read = newgetpid_read,&lt;br /&gt;
        .release = newgetpid_release,&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
static char *newgetpid_devnode(struct device *dev, umode_t *mode)&lt;br /&gt;
{&lt;br /&gt;
        if (mode)&lt;br /&gt;
	        *mode = 0444;&lt;br /&gt;
        return NULL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int __init newgetpid_init(void)&lt;br /&gt;
{&lt;br /&gt;
        int retval;&lt;br /&gt;
  &lt;br /&gt;
        newgetpid_major = register_chrdev(0, DEVICE_NAME, &amp;amp;newgetpid_fops);&lt;br /&gt;
        if (newgetpid_major &amp;lt; 0) {&lt;br /&gt;
                err(&amp;quot;failed to register device: error %d\n&amp;quot;, newgetpid_major);&lt;br /&gt;
                retval = newgetpid_major;&lt;br /&gt;
                goto failed_chrdevreg;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        newgetpid_class = class_create(THIS_MODULE, CLASS_NAME);&lt;br /&gt;
        if (IS_ERR(newgetpid_class)) {&lt;br /&gt;
                err(&amp;quot;failed to register device class &#039;%s&#039;\n&amp;quot;, CLASS_NAME);&lt;br /&gt;
                retval = PTR_ERR(newgetpid_class);&lt;br /&gt;
                goto failed_classreg;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
	newgetpid_class-&amp;gt;devnode = newgetpid_devnode;&lt;br /&gt;
&lt;br /&gt;
        newgetpid_device = device_create(newgetpid_class, NULL, MKDEV(newgetpid_major, 0),&lt;br /&gt;
                                    NULL, DEVICE_NAME);&lt;br /&gt;
&lt;br /&gt;
        if (IS_ERR(newgetpid_device)) {&lt;br /&gt;
                err(&amp;quot;failed to create device &#039;%s&#039;\n&amp;quot;, DEVICE_NAME);&lt;br /&gt;
                retval = PTR_ERR(newgetpid_device);&lt;br /&gt;
                goto failed_devreg;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        info(&amp;quot;Newgetpid device registered using major %d.\n&amp;quot;, newgetpid_major);&lt;br /&gt;
        &lt;br /&gt;
        return 0;&lt;br /&gt;
        &lt;br /&gt;
 failed_devreg:&lt;br /&gt;
        class_unregister(newgetpid_class);&lt;br /&gt;
        class_destroy(newgetpid_class);&lt;br /&gt;
 failed_classreg:&lt;br /&gt;
        unregister_chrdev(newgetpid_major, DEVICE_NAME);&lt;br /&gt;
 failed_chrdevreg:&lt;br /&gt;
        return -1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void __exit newgetpid_exit(void)&lt;br /&gt;
{&lt;br /&gt;
        device_destroy(newgetpid_class, MKDEV(newgetpid_major, 0));&lt;br /&gt;
        class_unregister(newgetpid_class);&lt;br /&gt;
        class_destroy(newgetpid_class);&lt;br /&gt;
        unregister_chrdev(newgetpid_major, &amp;quot;newgetpid&amp;quot;);&lt;br /&gt;
        info(&amp;quot;Unloading Newgetpid module.\n&amp;quot;);&lt;br /&gt;
        return;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
module_init(newgetpid_init);&lt;br /&gt;
module_exit(newgetpid_exit);&lt;br /&gt;
&lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);&lt;br /&gt;
MODULE_AUTHOR(&amp;quot;Anil Somayaji &amp;lt;soma@scs.carleton.ca&amp;gt;&amp;quot;);&lt;br /&gt;
MODULE_DESCRIPTION(&amp;quot;A write newgetpid character device module&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Makefile==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=make line&amp;gt;&lt;br /&gt;
obj-m := newgetpid.o&lt;br /&gt;
KDIR := /lib/modules/$(shell uname -r)/build&lt;br /&gt;
PWD := $(shell pwd)&lt;br /&gt;
default:&lt;br /&gt;
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
What determines what files you can and cannot create? -&amp;gt; Ssh privileges &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Anything that you can do as an ssh user you can do in the vm, just doing file operations&amp;lt;br&amp;gt;&lt;br /&gt;
* Sshfs means when you do read and write system calls for programs in a directory it also does it on the remote machine&amp;lt;br&amp;gt;&lt;br /&gt;
* Ssh is a good tool to access remote files locally, we will use it to edit modules&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Ones/newgetpid program:&amp;lt;br&amp;gt;&lt;br /&gt;
* We want to extend its functionality in a specific way&amp;lt;br&amp;gt;&lt;br /&gt;
* We want to access info about the process that made the system call&amp;lt;br&amp;gt;&lt;br /&gt;
* Let&#039;s get current processes id&amp;lt;br&amp;gt;&lt;br /&gt;
** Normally we would use getpid&amp;lt;br&amp;gt;&lt;br /&gt;
** But we can&#039;t make system calls in kernel space&amp;lt;br&amp;gt;&lt;br /&gt;
** But we can call the function that the system call uses or just copy the functionality&amp;lt;br&amp;gt;&lt;br /&gt;
* Code for this is in &amp;quot;kernel/sys.c&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Syscall_define0:&amp;lt;br&amp;gt;&lt;br /&gt;
* Macro that expands&amp;lt;br&amp;gt;&lt;br /&gt;
* Defines system calls with &amp;quot;getpid&amp;quot; and takes no arguments&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Can use the code inside the function but not the function itself in the kernel&amp;lt;br&amp;gt;&lt;br /&gt;
* Getpid returns a pid_t&amp;lt;br&amp;gt;&lt;br /&gt;
* Instead of get_ones returning all those ones we want it to return the pid&amp;lt;br&amp;gt;&lt;br /&gt;
* Lets try to get it to output a basic string with the pid&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How does printk work?&amp;lt;br&amp;gt;&lt;br /&gt;
* Printk sends its output to the kernel log&amp;lt;br&amp;gt;&lt;br /&gt;
* We changed the name to &amp;quot;newgetpid&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* How do we convert int to string to print the pid?&amp;lt;br&amp;gt;&lt;br /&gt;
** Make a buffer, let&#039;s call it &amp;quot;message&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why does the pid keep incrementing each time we call &amp;quot;cat /dev/newgetpid&amp;quot;?&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;Cat&amp;quot; spawns a process so every time we do a fork we get a new pid&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why can we use snprintf but not printf?&amp;lt;br&amp;gt;&lt;br /&gt;
* We include &amp;quot;linux/kernel.h&amp;quot; which defines snprintf but not printf&amp;lt;br&amp;gt;&lt;br /&gt;
* Printf assumes we have a standard output to print to&amp;lt;br&amp;gt;&lt;br /&gt;
* Snprintf only needs character arrays for it to work&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Read functionality uses an API&amp;lt;br&amp;gt;&lt;br /&gt;
* Adding new functionality like &amp;quot;write&amp;quot; is easy, just look at the standard API and original kernel source&amp;lt;br&amp;gt;&lt;br /&gt;
* All device files have their own custom read and write functions&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why do we use goto&#039;s?&amp;lt;br&amp;gt;&lt;br /&gt;
* C has no exception handling functionality so we implement our own&amp;lt;br&amp;gt;&lt;br /&gt;
* Jumps to error paths: failed_devreg, failed_classreg, failed_chrdevreg (very important in the kernel)&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel needs to be able to handle it&#039;s own errors&amp;lt;br&amp;gt;&lt;br /&gt;
* Needs to free up allocated resources, &amp;quot;undo&amp;quot; everything&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;.&amp;quot; is the current directory&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;..&amp;quot; is the parent directory&amp;lt;br&amp;gt;&lt;br /&gt;
** Introduces another hardlink&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* In order to build kernel modules, you need to have the headers associated with the current kernel you&#039;re running&lt;br /&gt;
* Modules are specified to a particular version of the kernel&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21288</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21288"/>
		<updated>2017-11-21T19:21:30Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== [Notes] ==&lt;br /&gt;
&lt;br /&gt;
Sample &lt;br /&gt;
sample&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
Where&#039;s main?&lt;br /&gt;
* lots of program shave &amp;quot;main&amp;quot; functions - a function that runs first and controls the execution of the program&amp;lt;br&amp;gt;&lt;br /&gt;
* Do these have &amp;quot;main&amp;quot; functions?&amp;lt;br&amp;gt;&lt;br /&gt;
** Linux kernel modules&amp;lt;br&amp;gt;&lt;br /&gt;
** FUSE applications?&amp;lt;br&amp;gt;&lt;br /&gt;
** the linux kernel?&amp;lt;br&amp;gt;&lt;br /&gt;
** node web applications?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In many systems, &amp;quot;main&amp;quot; just sets up even handlers&amp;lt;br&amp;gt;&lt;br /&gt;
* the event loop can be implicit or explicit&amp;lt;br&amp;gt;&lt;br /&gt;
** or there may be no loop at all, just handlers and &amp;quot;interrupts&amp;quot; some kind&amp;lt;br&amp;gt;&lt;br /&gt;
* event loops poll (check) to see when there are new events&amp;lt;br&amp;gt;&lt;br /&gt;
* what are event loops for node app?&amp;lt;br&amp;gt;&lt;br /&gt;
** where are interrupts for node apps? &amp;lt;br&amp;gt;&lt;br /&gt;
***Incoming network requests, it&#039;s an event&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code run differently in the kernel : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1)functions runs on the bhealf of insmod, unles sit is Independence context &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2)codes that run on the bhelaf o the process&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3)after an interrupt: no process , it is an interrupt cotext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) file names : regular programs but the square brackets, execution context + address space. they share the kernel&#039;s address space, they are called kernel threads which are independently scheduling . You can not kill them but you can change their scheduling , maybe their priority but not 100%. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does it create a proces? no , but it can create a kernel thread (is it a process? virtual adress space, .&amp;lt;br&amp;gt;&lt;br /&gt;
multi- threaded: maintains multiple address processes , ex: fire fox. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ps -elF | less &amp;quot;number&amp;quot; : displays threads.&lt;br /&gt;
&lt;br /&gt;
top : displays all the processes &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ls time : shows you the time . &lt;br /&gt;
&lt;br /&gt;
sys: how much time in the kernel space&lt;br /&gt;
real: how much time &lt;br /&gt;
user : how much time in user space &lt;br /&gt;
&lt;br /&gt;
process : can&#039;t manipulate its own memory map directly, it has an address space, but cant change it. Process: is limited but the kernel is not and the kernel can change it&#039;s own address and in charge of its self. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kernel tasks : are threads, when a process makes a system call , thi sis schedules in the process priority. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When running &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;quot;time ls&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
real = realtime it took to run&lt;br /&gt;
user = the user space time&lt;br /&gt;
sys = kernel time&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What&#039;s flow of control in tutorial 7? &amp;lt;br&amp;gt;&lt;br /&gt;
What is the connection? &amp;lt;br&amp;gt;&lt;br /&gt;
To exit the program, we must unmount the filesystem, run &amp;quot;sudo umount mnt&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
what is the flow of control ? what connection between things we are doing in the new terminal and the old one&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; these programs are communicating to each other, it will be invoked when we use mnt (mount) the kernel knows it is a filesystem , process runs system calls, then kernel talks to out original terminal. How? you can use strace to know, it is waiting to be invoked, to receive and responds to messages. events will be passed off to another process. switching between one process to another. it has potential security benefits. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Key to understand this tutorial : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; understand net flow control. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; how do processes communicate?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; how does it take a directory int and creates a filesystem from it?: &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
***sub tree starting at mount is delegated to this process.&amp;lt;br&amp;gt; &lt;br /&gt;
***permissions are limited &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How to kill it?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; ctrl c , no , you can but the kernel will be unhappy.&amp;lt;br&amp;gt;&lt;br /&gt;
-&amp;gt; unmount the file system when you are done using it &amp;lt;br&amp;gt;&lt;br /&gt;
-&amp;gt; umount / you have to do it as root &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Node web applications &amp;lt;br&amp;gt;&lt;br /&gt;
* Theres not a dedicated main function but its the first thing that runs &amp;lt;br&amp;gt;&lt;br /&gt;
* Every line in the node application terminates &amp;lt;br&amp;gt;&lt;br /&gt;
* If you start a web server, the function call starting it will terminate &amp;lt;br&amp;gt;&lt;br /&gt;
* Whats running? The main has finished. Is the program doing anything actively if theres no external input? &amp;lt;br&amp;gt;&lt;br /&gt;
* In many systems main just sets up event handlers &amp;lt;br&amp;gt;&lt;br /&gt;
* The event loop can be implicit or explicit &amp;lt;br&amp;gt;&lt;br /&gt;
* Its possible to have no loop at all just handlers and interrupts of some kind &amp;lt;br&amp;gt;&lt;br /&gt;
* Event loops check to see when there are new events &amp;lt;br&amp;gt;&lt;br /&gt;
* Os kernels behave the same way as node applications &amp;lt;br&amp;gt;&lt;br /&gt;
* Waiting for events &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens when you use insmod? &amp;lt;br&amp;gt;&lt;br /&gt;
* In newgetpid: Init and exit are called when the insmod program makes system calls to load the module &amp;lt;br&amp;gt;&lt;br /&gt;
* Init is run on behalf on insmod &amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel code fits into 3 categories &amp;lt;br&amp;gt;&lt;br /&gt;
** Code that runs on behalf of a process &amp;lt;br&amp;gt;&lt;br /&gt;
** Code that runs after an interrupt &amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel threads, has lots of functionality &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why is a kernel thread not a process? &amp;lt;br&amp;gt;&lt;br /&gt;
* The kernel maintains its own address space &amp;lt;br&amp;gt;&lt;br /&gt;
* Has its own virtual address map &amp;lt;br&amp;gt;&lt;br /&gt;
* The kernel always has just 1 address space regardless of how many threads there are &amp;lt;br&amp;gt;&lt;br /&gt;
* Processes cannot manipulate its own memory map directly, needs to ask kernel first &amp;lt;br&amp;gt;&lt;br /&gt;
* Processes are limited, the kernel is not, has control over itself &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel tasks = kernel threads &amp;lt;br&amp;gt;&lt;br /&gt;
* Independently scheduled &amp;lt;br&amp;gt;&lt;br /&gt;
* Once we call insmod everything happens in user space &amp;lt;br&amp;gt;&lt;br /&gt;
* Strace uses a system call called ptrace &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Tutorial 7: Fuse &amp;lt;br&amp;gt;&lt;br /&gt;
* Memoryll.py program &amp;lt;br&amp;gt;&lt;br /&gt;
* Always unmount a filesystem when youre done using it &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*No class Thursday! no office hours on Wednesday&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21270</id>
		<title>Operating Systems 2017F Lecture 18</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21270"/>
		<updated>2017-11-16T21:05:20Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 16, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec18-16Nov2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 18: Filesystems and such&lt;br /&gt;
--------------------------------&lt;br /&gt;
* How can you recover a filesystem?&lt;br /&gt;
* How do you delete a file?&lt;br /&gt;
&lt;br /&gt;
A filesystem is&lt;br /&gt;
 * persistent data structure&lt;br /&gt;
 * stored in fixed-sized blocks (at least 512 bytes in size)&lt;br /&gt;
 * maps hierarchical filenames to file contents&lt;br /&gt;
 * has metadata about files (somehow)&lt;br /&gt;
&lt;br /&gt;
What&#039;s in a filesystem?&lt;br /&gt;
 * data blocks&lt;br /&gt;
 * metadata blocks&lt;br /&gt;
&lt;br /&gt;
How do you organize metadata?&lt;br /&gt;
&lt;br /&gt;
First job: identify basic characteristics of the filesystem&lt;br /&gt;
&lt;br /&gt;
You need a &amp;quot;summary&amp;quot; block that tells you about everything else&lt;br /&gt;
 =&amp;gt; this is the &amp;quot;superblock&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Normally the superblock is the first block of the filesystem&lt;br /&gt;
&lt;br /&gt;
In the superblock&lt;br /&gt;
 - what kind of filesystem is this?&lt;br /&gt;
    - what filesystem magic number is there&lt;br /&gt;
 - how big is the filesystem?&lt;br /&gt;
 - how is it organized?&lt;br /&gt;
 - where can I find the rest of the metadata?&lt;br /&gt;
&lt;br /&gt;
for POSIX filesystems&lt;br /&gt;
 - file metadata is stored in...inodes&lt;br /&gt;
 - most have pre-reserved inodes&lt;br /&gt;
&lt;br /&gt;
So we have&lt;br /&gt;
 - superblock&lt;br /&gt;
 - inode blocks&lt;br /&gt;
 - data blocks&lt;br /&gt;
   - data blocks for directories&lt;br /&gt;
   - data blocks for files&lt;br /&gt;
&lt;br /&gt;
How do you recover from damage?&lt;br /&gt;
 - filesystems never &amp;quot;reboot&amp;quot;, must remain correct over&lt;br /&gt;
   the course of years&lt;br /&gt;
 - but errors will happen&lt;br /&gt;
   - bitrot&lt;br /&gt;
   - &amp;quot;accidental&amp;quot; corruption&lt;br /&gt;
   - computer failure/memory corruption/hard reboot&lt;br /&gt;
&lt;br /&gt;
To make filesystems fast, data &amp;amp; metadata is cached in RAM&lt;br /&gt;
 - bad things happen if this data hasn&#039;t been written to disk and you reboot&lt;br /&gt;
 - even worse things happen if your RAM is bad and corrupts the data&lt;br /&gt;
&lt;br /&gt;
Also bad...what if we lose the superblock?&lt;br /&gt;
 - you could lose EVERYTHING&lt;br /&gt;
 - so we have backup superblocks&lt;br /&gt;
&lt;br /&gt;
Old scandisk/fsck was slow because they had to scan all filesystem metadata&lt;br /&gt;
 - not to recover data, but to fix metadata&lt;br /&gt;
&lt;br /&gt;
Nowadays fsck is very fast and we rarely lose data due to losing power&lt;br /&gt;
 - we must be writing data to disk all the time&lt;br /&gt;
 - but isn&#039;t writing all the time slow?&lt;br /&gt;
&lt;br /&gt;
On magnetic hard disks (not SSDs)&lt;br /&gt;
 - sequential operations are fast&lt;br /&gt;
 - random access is slow&lt;br /&gt;
   - we have to move the read/write head&lt;br /&gt;
&lt;br /&gt;
So, on modern systems we update metadata (and sometimes data) by writing&lt;br /&gt;
sequentially to disk...and then later writing randomly&lt;br /&gt;
 - sequential writes go to the &amp;quot;journal&amp;quot;&lt;br /&gt;
&lt;br /&gt;
On fsck on a journaled filesystem&lt;br /&gt;
 - just check the journal for pending operations (replay the journal)&lt;br /&gt;
&lt;br /&gt;
There exist filesystems that are pure journal&lt;br /&gt;
 - log-based filesystem&lt;br /&gt;
&lt;br /&gt;
logs and journal inherently create multiple copies of data and metadata that are hard to track.  This makes deletion nearly impossible (at least to guarantee)&lt;br /&gt;
&lt;br /&gt;
Only way to guarantee...encrypt everything&lt;br /&gt;
 - if every file has its own key, you can delete the key and thus &amp;quot;delete&amp;quot; the data&lt;br /&gt;
&lt;br /&gt;
Solid State Disks (SSD) use log-structured storage at a level below blocks.&lt;br /&gt;
 - writes are coarse-grained (you have to write a lot at once)&lt;br /&gt;
 - you don&#039;t want to write to the same cells too often, they&#039;ll die&lt;br /&gt;
   - have to do &amp;quot;wear-leveling&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additional notes :&lt;br /&gt;
&lt;br /&gt;
Lecture 18, november 17 &lt;br /&gt;
&lt;br /&gt;
Comp 3000: &lt;br /&gt;
Midterm review:&lt;br /&gt;
2)mmap is called in dynamically linked libraries &lt;br /&gt;
Work on 2404 assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8) yes , using mmap &lt;br /&gt;
9) shell did , because it has to open a new file &lt;br /&gt;
10) mmap allocates the entire file , &lt;br /&gt;
11) after the fork , the memory won’t be shared, no communication will happen. &lt;br /&gt;
12) no, race condition, busy wait , spin lock in the kernel. Some other user can modify the code which we are waiting. Before we decrement someone else will modify it. Someone can change with the semantics. &lt;br /&gt;
How do you do kernel hacking?&lt;br /&gt;
1)	Be humble, &lt;br /&gt;
o	you don’t necessary know everything, everyone is retarded in their own way &lt;br /&gt;
2)	Verify you assumptions &lt;br /&gt;
o	By experiments &lt;br /&gt;
o	Compile and run&lt;br /&gt;
3)	Check for errors!&lt;br /&gt;
o	Saves time&lt;br /&gt;
o	Kernel has to live “ cleanly” &lt;br /&gt;
4)	Find another part of the kernel that is close to what you want to do &lt;br /&gt;
o	Use their ideas to apply yours by analyzing their code.&lt;br /&gt;
o	Follow their pattern “pattern match” to avoid problems since you may not understand all the abstractions and assumptions&lt;br /&gt;
o	Realize if their assumptions match yours&lt;br /&gt;
5)	Understand the “flow of control” in the program&lt;br /&gt;
o	Architecture &lt;br /&gt;
o	Division of responsibilities &lt;br /&gt;
o	Division Why does this matter?&lt;br /&gt;
o	Possible to make a module and run in the background! Anything is possible! All you have to do is be creative. In fact you have to do a kernel thread &lt;br /&gt;
	When does the Ethernet card receives data?&lt;br /&gt;
o	The Ethernet card sends an interrupt to the kernel &lt;br /&gt;
o	The CPU calls the kernel code for handling Ethernet data&lt;br /&gt;
	When does the kernel run? &lt;br /&gt;
o	The kernel gets woken up for those events &lt;br /&gt;
o	The clock generates a timer interrupt &lt;br /&gt;
	Interrupt requires a CPU score to be taken over&lt;br /&gt;
o	Core was probably running a user space process and this is scheduling is about&lt;br /&gt;
	Schedule: what to do after having kicked a user space process off a core.&lt;br /&gt;
o	Can it be a complex CPU algorithm : no since it always sending interrupts?&lt;br /&gt;
o	Determines what is the next task to do?&lt;br /&gt;
	Normally on a core:&lt;br /&gt;
o	A running userspace process&lt;br /&gt;
o	Interrupt happens&lt;br /&gt;
o	Core switches to supervisor mode, runs kernel code&lt;br /&gt;
o	Last part of the  kernel code is the scheduler, chooses which userspace code to run &lt;br /&gt;
o	Goto top&lt;br /&gt;
	Kernel is entered via interrupts, exited via scheduler &lt;br /&gt;
	Entry and exit the kernel has to do low-level tasks&lt;br /&gt;
o	Uses assembly code&lt;br /&gt;
	Limits because it is hard to manage &lt;br /&gt;
On the website:&lt;br /&gt;
	Arch : arch culture specific and the driver specific code, &lt;br /&gt;
	Entry_64.5 : before the system call it calls this. Don’t mess up with it. It take cares of dispatching the system calls.&lt;br /&gt;
	Shced.h: what the kernel uses to keep track of processes , go through it &lt;br /&gt;
	:1 means bitfields in c &lt;br /&gt;
	What criteria should the scheduler use? &lt;br /&gt;
o	“fairness” : everyone should get a turn, everyone gets to share the CPU.&lt;br /&gt;
o	Starvation : a term when a program does not get the CPU&lt;br /&gt;
o	Prevent starvation!&lt;br /&gt;
o	Equal share of resources.&lt;br /&gt;
o	Why would not you want your scheduler being fair? To avoid “foreground” tasks in the interactive systems.&lt;br /&gt;
o	Never enough biased towards “ foreground” tasks&lt;br /&gt;
o	Series of hacks and heuristics  &lt;br /&gt;
&lt;br /&gt;
	Memory is allocated lazily is the kernel : &lt;br /&gt;
o	which means it is possible to allocate way more memory that can be ever used.&lt;br /&gt;
o	This will cause “memory debt”&lt;br /&gt;
o	Out of memory killer : killing process when you exceed the amount of memory(ex: shoots whoever deposits the money)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Continuation of lecture 18: &lt;br /&gt;
&lt;br /&gt;
Important notes:&lt;br /&gt;
How can you recover a filesystem?&lt;br /&gt;
How do you delete a file?&lt;br /&gt;
What is a filesystem?: &lt;br /&gt;
*persistent data structure &lt;br /&gt;
* stored in fixed-sized blocks (at least 512 bytes in size)&lt;br /&gt;
*maps hierarchical filenames to file contents &lt;br /&gt;
*has metadata about files (somwhow)&lt;br /&gt;
What is in a filesystem?&lt;br /&gt;
*data blocks &lt;br /&gt;
*metadata blocks &lt;br /&gt;
How do you organize metdata:&lt;br /&gt;
1)	First you must identify characteristics of the file system &lt;br /&gt;
Superblock :  summary y block which tells you about the other blocks you have and it depends on which file system you have. It’s usually the first block of a file system. &lt;br /&gt;
In the superblock? :&lt;br /&gt;
1)	What kind of file system is this? By checking what is the magic number it has &lt;br /&gt;
2)	How big is the file system?&lt;br /&gt;
3)	How is it organized?&lt;br /&gt;
4)	Where can I find the rest of the metadata?&lt;br /&gt;
&lt;br /&gt;
*How can you identify which file system it is from looking at the super class&lt;br /&gt;
-&amp;gt; google “magic number of a file” &lt;br /&gt;
-&amp;gt; ex: jpg ctr^c ctr^c : switched the pictures into a binary file &lt;br /&gt;
-&amp;gt; look at the beginning of the file you will see JFIF:  first several bytes in general that identifies the type of the file (magic number)&lt;br /&gt;
File extension : &lt;br /&gt;
	what is it ? &lt;br /&gt;
	is it important&lt;br /&gt;
	the kernel does not know and not care about it&lt;br /&gt;
&lt;br /&gt;
For POSIX file systems: &lt;br /&gt;
-.&amp;gt; file metadata is stored in inodes &lt;br /&gt;
-.&amp;gt; most have pre-reserved inodes &lt;br /&gt;
   -&amp;gt; the only way you can run out of inodes if you keep creating small files &lt;br /&gt;
&lt;br /&gt;
Usenet : al the things you use to post messages thro social media, email, etc. Those were made using Usenet. Like email but Local Usenet server. But it died over time. Every message is stored in an individual file. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Important commands: &lt;br /&gt;
File * : to identify the kind of file system&lt;br /&gt;
1.	As : Run dumpe2fs foo. What does the output of this command mean?&lt;br /&gt;
	Does this give you info about the file system?&lt;br /&gt;
	File bar : bar is the file name and cp comp3000-midterm-2017.pdf bar &lt;br /&gt;
	Evince bar : opens up the pdf file&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
Lec 18 &amp;lt;br&amp;gt;&lt;br /&gt;
* More on filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
* How can you recover a fs and how do you delete a file? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
A filesystem is a: &amp;lt;br&amp;gt;&lt;br /&gt;
* Persistent data structure &amp;lt;br&amp;gt;&lt;br /&gt;
* Stored in fixed size blocks (at least 512 bytes in size) &amp;lt;br&amp;gt;&lt;br /&gt;
* Maps hierarchical filenames to file contents &amp;lt;br&amp;gt;&lt;br /&gt;
* Has metadata about files somehow &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What&#039;s in a filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* data blocks (stores file content) &amp;lt;br&amp;gt;&lt;br /&gt;
* metadata blocks, you need someway to find the blocks&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do you organize metadata?&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
First identify basic characteristics of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
- How big is the filesystem? &amp;lt;br&amp;gt;&lt;br /&gt;
- What is the block size? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do we differentiate between this and other filesystems?&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You need a &amp;quot;superblock&amp;quot; which is a &amp;quot;summary&amp;quot; block that tells you about everything else&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
- Format depends on filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
- Normally the superblock is the first block of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
- Think of it almost like the root of a binary tree &amp;lt;br&amp;gt;&lt;br /&gt;
In the superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* Type of filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
** What filesystem magic number is there (lets us identify one filesystem from another just by looking at the first block) &amp;lt;br&amp;gt;&lt;br /&gt;
** File command to know file type &amp;lt;br&amp;gt;&lt;br /&gt;
* Size of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* How the filesystem is organized (different filesystems organize their data differently) &amp;lt;br&amp;gt;&lt;br /&gt;
* Where can I find the rest of the metadata &amp;lt;br&amp;gt;&lt;br /&gt;
He opened a .jpg as a binary file to show us the magic number in a file, first several bytes identify type of file. &amp;lt;br&amp;gt;&lt;br /&gt;
- Kernel does not care about file extension but userspace programs may care about the extension.&amp;lt;br&amp;gt;&lt;br /&gt;
- File extensions are only really useful for the people looking at them&lt;br /&gt;
- Typical for binary file formats to have a set of bytes that identify the type of file&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
POSIX is a standard for maintaining compatibility between operating systems &amp;lt;br&amp;gt;&lt;br /&gt;
- QNX, UNIX, MacOS are all POSIX compliant&lt;br /&gt;
- Others comply on a varying scale&lt;br /&gt;
For POSIX filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
* File metadata is stored in INODES&amp;lt;br&amp;gt;&lt;br /&gt;
* When you create a filesystem, certain blocks are dedicated to being INODES &amp;lt;br&amp;gt;&lt;br /&gt;
- Possible to have space in your filesystem without being able to store things if you run out of INODES &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What is usenet?&lt;br /&gt;
- A worldwide distributed discussion system (stone age version of reddit) &amp;lt;br&amp;gt;&lt;br /&gt;
- Deprecated now because it could not handle the spam people uploaded into it, lol &amp;lt;br&amp;gt;&lt;br /&gt;
- Format for usenet was every message stored in its own file =&amp;gt; lots of small files &amp;lt;br&amp;gt;&lt;br /&gt;
- Everyone has a local usenet server, access to read posts on the forum &amp;lt;br&amp;gt;&lt;br /&gt;
- To post a message, send to local server which replicates it and sends it to all the other servers &amp;lt;br&amp;gt;&lt;br /&gt;
So we have: &amp;lt;br&amp;gt;&lt;br /&gt;
* superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* inode blocks &amp;lt;br&amp;gt;&lt;br /&gt;
* data blocks &amp;lt;br&amp;gt;&lt;br /&gt;
** data blocks for directories &amp;lt;br&amp;gt;&lt;br /&gt;
** data blocks for files &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do you recover from damage?&amp;lt;br&amp;gt;&lt;br /&gt;
* Filesystems never &amp;quot;reboot&amp;quot;, must remain correct over time &amp;lt;br&amp;gt;&lt;br /&gt;
* Errors will happen: bitrot (when bits change), accidental corruption, computer failiure/memory corruption/hard reboot &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To make filesystems fast, data and metadata are cached in RAM &amp;lt;br&amp;gt;&lt;br /&gt;
* Bad things happen if this data hasn&#039;t been writen to disk and you reboot &amp;lt;br&amp;gt;&lt;br /&gt;
* Even worse things happen if your RAM is bad and corrupts the data &amp;lt;br&amp;gt; &lt;br /&gt;
* FSCK is like scandisk in Windows 98 (this only happens when you do a hard reset)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What happens if you lose the superblock?&amp;lt;br&amp;gt;&lt;br /&gt;
* You could lose EVERYTHING &amp;lt;br&amp;gt;&lt;br /&gt;
* Node trunc dd command blew away first bytes of the file system so you could not mount it because you corrupted the superblock. However, fsck fixed this because we have backup superblocks :D &amp;lt;br&amp;gt;&lt;br /&gt;
- Most filesystems keep copies of the superblock in random locations throughout which takes up some unusable amount of data &amp;lt;br&amp;gt;&lt;br /&gt;
- But this is an impractical way to deal with data blocks &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Old scandisk/fsck was slow because it had to scan all filesystem metadata, this is bad since we may lose power before it finished running &amp;lt;br&amp;gt;&lt;br /&gt;
* Not to recover data, but to fix metadata &amp;lt;br&amp;gt;&lt;br /&gt;
* lost+found directory might have some files that you can recover &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What is lost+found? &amp;lt;br&amp;gt;&lt;br /&gt;
- Part of the filesystem for fsck to use, dedicated directory &amp;lt;br&amp;gt;&lt;br /&gt;
- Can find nodes that appear to be allocated but has no associated filename, no hardlinks, is inaccessible &amp;lt;br&amp;gt;&lt;br /&gt;
- If you run fsck and it returns error messages you may be able to recover them by looking in lost+found &amp;lt;br&amp;gt;&lt;br /&gt;
- Almost useless for modern filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Nowadays fsck is very fast and we rarely lose data due to losing power &amp;lt;br&amp;gt;&lt;br /&gt;
* What this means is we must be writing to disk all the time &amp;lt;br&amp;gt;&lt;br /&gt;
* But isn&#039;t writing slow? =&amp;gt; Not necessarily, all writes aren&#039;t the same &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On Magnetic Hard Disks (not SSD&#039;s) &amp;lt;br&amp;gt;&lt;br /&gt;
* sequential oeprations are fast &amp;lt;br&amp;gt;&lt;br /&gt;
* random access is slow &amp;lt;br&amp;gt;&lt;br /&gt;
** we have to move the read/write head &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
So, on modern systems we update metadata (and sometimes data) by writing sequentially to disk...and then later writing randomly (which means were actually writing twice) &amp;lt;br&amp;gt;&lt;br /&gt;
* Sequential writes go to the journal &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On fsck on a journaled filesystem&lt;br /&gt;
* Just check the journal for pending operations (replaying the journal) &amp;lt;br&amp;gt; &lt;br /&gt;
* There exists filesystems for optimizing writes that are pure journal&amp;lt;br&amp;gt;&lt;br /&gt;
* Log based filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How to delete things? &amp;lt;br&amp;gt;&lt;br /&gt;
* Compact it, we don&#039;t really know how many copies are stored in the filesystem&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Logs and journal inherently create multiple copies of data and metadata that are hard to track. This makes deletion nearly impossible (at least to guarantee) &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Only way to guarantee...encrypt everything &amp;lt;br&amp;gt;&lt;br /&gt;
* If every file has its own key, you can delete the key and this technically deletes the data &amp;lt;br&amp;gt;&lt;br /&gt;
* Only way to recover data is to break encryption scheme (this is nearly impossible)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
SSDs use log-structured storage at a layer below the regular filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* Writes are coarse-grained (efficient for writing large amounts at once) &amp;lt;br&amp;gt;&lt;br /&gt;
* You don&#039;t want to write to the same cells too often, they will die &amp;lt;br&amp;gt; &lt;br /&gt;
** Instead spread out where you write data =&amp;gt; &amp;quot;wear-leveling&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* All modern Intel cpus have a management chip that manages power and such &amp;lt;br&amp;gt;&lt;br /&gt;
** Runs a small operating system called minux (this can also be compromised)&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21267</id>
		<title>Operating Systems 2017F Lecture 18</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21267"/>
		<updated>2017-11-16T20:29:30Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 16, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec18-16Nov2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 18: Filesystems and such&lt;br /&gt;
--------------------------------&lt;br /&gt;
* How can you recover a filesystem?&lt;br /&gt;
* How do you delete a file?&lt;br /&gt;
&lt;br /&gt;
A filesystem is&lt;br /&gt;
 * persistent data structure&lt;br /&gt;
 * stored in fixed-sized blocks (at least 512 bytes in size)&lt;br /&gt;
 * maps hierarchical filenames to file contents&lt;br /&gt;
 * has metadata about files (somehow)&lt;br /&gt;
&lt;br /&gt;
What&#039;s in a filesystem?&lt;br /&gt;
 * data blocks&lt;br /&gt;
 * metadata blocks&lt;br /&gt;
&lt;br /&gt;
How do you organize metadata?&lt;br /&gt;
&lt;br /&gt;
First job: identify basic characteristics of the filesystem&lt;br /&gt;
&lt;br /&gt;
You need a &amp;quot;summary&amp;quot; block that tells you about everything else&lt;br /&gt;
 =&amp;gt; this is the &amp;quot;superblock&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Normally the superblock is the first block of the filesystem&lt;br /&gt;
&lt;br /&gt;
In the superblock&lt;br /&gt;
 - what kind of filesystem is this?&lt;br /&gt;
    - what filesystem magic number is there&lt;br /&gt;
 - how big is the filesystem?&lt;br /&gt;
 - how is it organized?&lt;br /&gt;
 - where can I find the rest of the metadata?&lt;br /&gt;
&lt;br /&gt;
for POSIX filesystems&lt;br /&gt;
 - file metadata is stored in...inodes&lt;br /&gt;
 - most have pre-reserved inodes&lt;br /&gt;
&lt;br /&gt;
So we have&lt;br /&gt;
 - superblock&lt;br /&gt;
 - inode blocks&lt;br /&gt;
 - data blocks&lt;br /&gt;
   - data blocks for directories&lt;br /&gt;
   - data blocks for files&lt;br /&gt;
&lt;br /&gt;
How do you recover from damage?&lt;br /&gt;
 - filesystems never &amp;quot;reboot&amp;quot;, must remain correct over&lt;br /&gt;
   the course of years&lt;br /&gt;
 - but errors will happen&lt;br /&gt;
   - bitrot&lt;br /&gt;
   - &amp;quot;accidental&amp;quot; corruption&lt;br /&gt;
   - computer failure/memory corruption/hard reboot&lt;br /&gt;
&lt;br /&gt;
To make filesystems fast, data &amp;amp; metadata is cached in RAM&lt;br /&gt;
 - bad things happen if this data hasn&#039;t been written to disk and you reboot&lt;br /&gt;
 - even worse things happen if your RAM is bad and corrupts the data&lt;br /&gt;
&lt;br /&gt;
Also bad...what if we lose the superblock?&lt;br /&gt;
 - you could lose EVERYTHING&lt;br /&gt;
 - so we have backup superblocks&lt;br /&gt;
&lt;br /&gt;
Old scandisk/fsck was slow because they had to scan all filesystem metadata&lt;br /&gt;
 - not to recover data, but to fix metadata&lt;br /&gt;
&lt;br /&gt;
Nowadays fsck is very fast and we rarely lose data due to losing power&lt;br /&gt;
 - we must be writing data to disk all the time&lt;br /&gt;
 - but isn&#039;t writing all the time slow?&lt;br /&gt;
&lt;br /&gt;
On magnetic hard disks (not SSDs)&lt;br /&gt;
 - sequential operations are fast&lt;br /&gt;
 - random access is slow&lt;br /&gt;
   - we have to move the read/write head&lt;br /&gt;
&lt;br /&gt;
So, on modern systems we update metadata (and sometimes data) by writing&lt;br /&gt;
sequentially to disk...and then later writing randomly&lt;br /&gt;
 - sequential writes go to the &amp;quot;journal&amp;quot;&lt;br /&gt;
&lt;br /&gt;
On fsck on a journaled filesystem&lt;br /&gt;
 - just check the journal for pending operations (replay the journal)&lt;br /&gt;
&lt;br /&gt;
There exist filesystems that are pure journal&lt;br /&gt;
 - log-based filesystem&lt;br /&gt;
&lt;br /&gt;
logs and journal inherently create multiple copies of data and metadata that are hard to track.  This makes deletion nearly impossible (at least to guarantee)&lt;br /&gt;
&lt;br /&gt;
Only way to guarantee...encrypt everything&lt;br /&gt;
 - if every file has its own key, you can delete the key and thus &amp;quot;delete&amp;quot; the data&lt;br /&gt;
&lt;br /&gt;
Solid State Disks (SSD) use log-structured storage at a level below blocks.&lt;br /&gt;
 - writes are coarse-grained (you have to write a lot at once)&lt;br /&gt;
 - you don&#039;t want to write to the same cells too often, they&#039;ll die&lt;br /&gt;
   - have to do &amp;quot;wear-leveling&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
Lec 18 &amp;lt;br&amp;gt;&lt;br /&gt;
* More on filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
* How can you recover a fs and how do you delete a file? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
A filesystem is a: &amp;lt;br&amp;gt;&lt;br /&gt;
* Persistent data structure &amp;lt;br&amp;gt;&lt;br /&gt;
* Stored in fixed size blocks (at least 512 bytes in size) &amp;lt;br&amp;gt;&lt;br /&gt;
* Maps hierarchical filenames to file contents &amp;lt;br&amp;gt;&lt;br /&gt;
* Has metadata about files somehow &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What&#039;s in a filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* data blocks (stores file content) &amp;lt;br&amp;gt;&lt;br /&gt;
* metadata blocks, you need someway to find the blocks&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do you organize metadata?&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
First identify basic characteristics of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
- How big is the filesystem? &amp;lt;br&amp;gt;&lt;br /&gt;
- What is the block size? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do we differentiate between this and other filesystems?&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You need a &amp;quot;superblock&amp;quot; which is a &amp;quot;summary&amp;quot; block that tells you about everything else&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
- Format depends on filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
- Normally the superblock is the first block of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
- Think of it almost like the root of a binary tree &amp;lt;br&amp;gt;&lt;br /&gt;
In the superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* Type of filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
** What filesystem magic number is there (lets us identify one filesystem from another just by looking at the first block) &amp;lt;br&amp;gt;&lt;br /&gt;
** File command to know file type &amp;lt;br&amp;gt;&lt;br /&gt;
* Size of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* How the filesystem is organized (different filesystems organize their data differently) &amp;lt;br&amp;gt;&lt;br /&gt;
* Where can I find the rest of the metadata &amp;lt;br&amp;gt;&lt;br /&gt;
He opened a .jpg as a binary file to show us the magic number in a file, first several bytes identify type of file. &amp;lt;br&amp;gt;&lt;br /&gt;
- Kernel does not care about file extension but userspace programs may care about the extension.&amp;lt;br&amp;gt;&lt;br /&gt;
- File extensions are only really useful for the people looking at them&lt;br /&gt;
- Typical for binary file formats to have a set of bytes that identify the type of file&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
POSIX is a standard for maintaining compatibility between operating systems &amp;lt;br&amp;gt;&lt;br /&gt;
- QNX, UNIX, MacOS are all POSIX compliant&lt;br /&gt;
- Others comply on a varying scale&lt;br /&gt;
For POSIX filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
* File metadata is stored in INODES&amp;lt;br&amp;gt;&lt;br /&gt;
* When you create a filesystem, certain blocks are dedicated to being INODES &amp;lt;br&amp;gt;&lt;br /&gt;
- Possible to have space in your filesystem without being able to store things if you run out of INODES &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What is usenet?&lt;br /&gt;
- A worldwide distributed discussion system (stone age version of reddit) &amp;lt;br&amp;gt;&lt;br /&gt;
- Deprecated now because it could not handle the spam people uploaded into it, lol &amp;lt;br&amp;gt;&lt;br /&gt;
- Format for usenet was every message stored in its own file =&amp;gt; lots of small files &amp;lt;br&amp;gt;&lt;br /&gt;
- Everyone has a local usenet server, access to read posts on the forum &amp;lt;br&amp;gt;&lt;br /&gt;
- To post a message, send to local server which replicates it and sends it to all the other servers &amp;lt;br&amp;gt;&lt;br /&gt;
So we have: &amp;lt;br&amp;gt;&lt;br /&gt;
* superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* inode blocks &amp;lt;br&amp;gt;&lt;br /&gt;
* data blocks &amp;lt;br&amp;gt;&lt;br /&gt;
** data blocks for directories &amp;lt;br&amp;gt;&lt;br /&gt;
** data blocks for files &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do you recover from damage?&amp;lt;br&amp;gt;&lt;br /&gt;
* Filesystems never &amp;quot;reboot&amp;quot;, must remain correct over time &amp;lt;br&amp;gt;&lt;br /&gt;
* Errors will happen: bitrot (when bits change), accidental corruption, computer failiure/memory corruption/hard reboot &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To make filesystems fast, data and metadata are cached in RAM &amp;lt;br&amp;gt;&lt;br /&gt;
* Bad things happen if this data hasn&#039;t been writen to disk and you reboot &amp;lt;br&amp;gt;&lt;br /&gt;
* Even worse things happen if your RAM is bad and corrupts the data &amp;lt;br&amp;gt; &lt;br /&gt;
* FSCK is like scandisk in Windows 98 (this only happens when you do a hard reset)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What happens if you lose the superblock?&amp;lt;br&amp;gt;&lt;br /&gt;
* You could lose EVERYTHING &amp;lt;br&amp;gt;&lt;br /&gt;
* Node trunc dd command blew away first bytes of the file system so you could not mount it because you corrupted the superblock. However, fsck fixed this because we have backup superblocks :D &amp;lt;br&amp;gt;&lt;br /&gt;
- Most filesystems keep copies of the superblock in random locations throughout which takes up some unusable amount of data &amp;lt;br&amp;gt;&lt;br /&gt;
- But this is an impractical way to deal with data blocks &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Old scandisk/fsck was slow because we they had to scan all filesystem metadata &amp;lt;br&amp;gt;&lt;br /&gt;
* Not to recover data, but to fix metadata &amp;lt;br&amp;gt;&lt;br /&gt;
* lost+found might have some files that you might recover. It is a part of the filesystem for fsck to use. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Nowadays fsck is very fast and we rarely lose data due to losing power &amp;lt;br&amp;gt;&lt;br /&gt;
* What this means is we must be writing to disk all the time &amp;lt;br&amp;gt;&lt;br /&gt;
* But isn&#039;t writing slow? All writes aren&#039;t slow particularly on conventional hard disks. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On Magnetic Hard Disks (not SSD&#039;s) &amp;lt;br&amp;gt;&lt;br /&gt;
* sequential oeprations are fast &amp;lt;br&amp;gt;&lt;br /&gt;
* random access is slow &amp;lt;br&amp;gt;&lt;br /&gt;
** we have to move the read/write head &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
So, on modern systems we update metadata (and sometimes data) by writing sequentially to disk...and then later writing randomly &amp;lt;br&amp;gt;&lt;br /&gt;
* Sequential writes go to the journal &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On fsck on a journaled filesystem&lt;br /&gt;
* just check the journal for pending operations (replaying the journal) &amp;lt;br&amp;gt; &lt;br /&gt;
There exists filesytems for optimizing writes that are pure journal&amp;lt;br&amp;gt;&lt;br /&gt;
* log-based filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Logs and journal inherently create multiple copies of data and metadata that are hard to track. This makes deletion nearly impossible (at least to guarantee) &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Only way to garauntee...encrypt everything &amp;lt;br&amp;gt;&lt;br /&gt;
* if every file has its own key, you can delete the key and this &amp;quot;delete&amp;quot; the data &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
SSD&#039;s use log-structured sotrage at a level below blocks &amp;lt;br&amp;gt;&lt;br /&gt;
* Writes are coarse-grained (you have to write a lot at once) &amp;lt;br&amp;gt;&lt;br /&gt;
* You don&#039;t want to write to the same cells too often, they will die &amp;lt;br&amp;gt; &lt;br /&gt;
** You have to do &amp;quot;wear-leveling&amp;quot; &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_15&amp;diff=21185</id>
		<title>Operating Systems 2017F Lecture 15</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_15&amp;diff=21185"/>
		<updated>2017-11-08T15:13:26Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: /* Additional */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 7, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec15-07Nov2017.mp4 is now available].  Unfortunately, the video cut out halfway through; [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec15-07Nov2017-audio.m4a audio is also available] however.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 15&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
What&#039;s a filesystem?&lt;br /&gt;
 - persistent data structure organized around fixed allocation units (blocks)&lt;br /&gt;
 - maps hierarchical names (keys) to values&lt;br /&gt;
 - provide a file-like API (open, read, write, close, etc)&lt;br /&gt;
&lt;br /&gt;
What does it mean to &amp;quot;make&amp;quot; a filesystem?&lt;br /&gt;
 - initialize the data structure&lt;br /&gt;
 - &amp;quot;formatting&amp;quot; a disk&lt;br /&gt;
&lt;br /&gt;
Physical versus logical size of a file&lt;br /&gt;
 - logical: the &amp;quot;size&amp;quot; your program sees when accessing the file&lt;br /&gt;
 - physical: how much space the file takes up on disk&lt;br /&gt;
&lt;br /&gt;
Physical is in terms of blocks - fixed units of storage allocation&lt;br /&gt;
 - ext4 has 4k blocks&lt;br /&gt;
 - default for many command line utilities is 1k blocks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel programming&lt;br /&gt;
 - you may destroy the system you are working on AT ANY TIME&lt;br /&gt;
 - HAVE GOOD BACKUPS&lt;br /&gt;
 - rsync is your friend&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel modules&lt;br /&gt;
 - way of splitting up kernel functionality so everything doesn&#039;t have to load&lt;br /&gt;
   at boot&lt;br /&gt;
    - code loaded as part of the initial boot image is hard to get rid of at&lt;br /&gt;
      runtime&lt;br /&gt;
 - why do we need modules? why not processes?&lt;br /&gt;
   - no new mechanisms&lt;br /&gt;
   - increased security (restricted access)&lt;br /&gt;
   - &amp;quot;microkernel&amp;quot; approach&lt;br /&gt;
   - instead of code talking in supervisor mode, processes do IPC&lt;br /&gt;
      - filesystems&lt;br /&gt;
      - drivers&lt;br /&gt;
      - networking&lt;br /&gt;
   - minix, QNX, GNU hurd&lt;br /&gt;
 - Linux is a &amp;quot;monolithic&amp;quot; kernel.  Why?&lt;br /&gt;
   - performance: context switches are expensive&lt;br /&gt;
     - techniques to make microkernels fast can be adopted by&lt;br /&gt;
       monolithic kernels to make them even faster&lt;br /&gt;
   - security benefit is illusory&lt;br /&gt;
     - if you control the filesystem process, you already own everything&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional===&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; Core kernel functionality is implemented via modules&lt;br /&gt;
--&amp;gt; use ls mod to see modules that are loaded&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is a monolithic kernel?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; a type of OS architecture where the entire OS is working in kernel space&lt;br /&gt;
--&amp;gt; can dynamically load/unload modules at runtime&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;make localmodconfig:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; takes output of ls mod and configures your kernel&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones.c program:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/ones:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; permissions are read only&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;file_operations ones_fops():&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; defines what happens when you open a file, read from it, release tells you what happens when you&#039;re done with it (not the same thing as close)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones_read():&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; len is the number of bytes to read&lt;br /&gt;
--&amp;gt; offset tells you where you are in the file&lt;br /&gt;
--&amp;gt; put_user() takes care of whatever needs to be done to write into that process properly&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones_release:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why are we using printk instead of printf?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; printf is not yet defined (ie. C library is not available in the kernel)&lt;br /&gt;
--&amp;gt; kernel doesn&#039;t depend on any libraries, all code belongs to the kernel itself&lt;br /&gt;
--&amp;gt; printk is the kernel&#039;s own implementation of printf (outputs to the kernel log --&amp;gt; /var/log/kern.log)&lt;br /&gt;
&lt;br /&gt;
vfs = virtual filesystem layer&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we limit access to user space processes?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; Do a permission check&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; kernels need to be updated regularly to correct bugs that make the kernel vulnerable to programs trying to gain access to important user space processes&lt;br /&gt;
--&amp;gt; unlikely() = tells you that this branch is not likely to be taken, optimize the current path&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vfs_read:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;file-&amp;gt;f_op-&amp;gt;read:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; this is how our read function will be called&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_15&amp;diff=21184</id>
		<title>Operating Systems 2017F Lecture 15</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_15&amp;diff=21184"/>
		<updated>2017-11-08T15:12:28Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: /* Additional */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 7, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec15-07Nov2017.mp4 is now available].  Unfortunately, the video cut out halfway through; [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec15-07Nov2017-audio.m4a audio is also available] however.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 15&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
What&#039;s a filesystem?&lt;br /&gt;
 - persistent data structure organized around fixed allocation units (blocks)&lt;br /&gt;
 - maps hierarchical names (keys) to values&lt;br /&gt;
 - provide a file-like API (open, read, write, close, etc)&lt;br /&gt;
&lt;br /&gt;
What does it mean to &amp;quot;make&amp;quot; a filesystem?&lt;br /&gt;
 - initialize the data structure&lt;br /&gt;
 - &amp;quot;formatting&amp;quot; a disk&lt;br /&gt;
&lt;br /&gt;
Physical versus logical size of a file&lt;br /&gt;
 - logical: the &amp;quot;size&amp;quot; your program sees when accessing the file&lt;br /&gt;
 - physical: how much space the file takes up on disk&lt;br /&gt;
&lt;br /&gt;
Physical is in terms of blocks - fixed units of storage allocation&lt;br /&gt;
 - ext4 has 4k blocks&lt;br /&gt;
 - default for many command line utilities is 1k blocks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel programming&lt;br /&gt;
 - you may destroy the system you are working on AT ANY TIME&lt;br /&gt;
 - HAVE GOOD BACKUPS&lt;br /&gt;
 - rsync is your friend&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel modules&lt;br /&gt;
 - way of splitting up kernel functionality so everything doesn&#039;t have to load&lt;br /&gt;
   at boot&lt;br /&gt;
    - code loaded as part of the initial boot image is hard to get rid of at&lt;br /&gt;
      runtime&lt;br /&gt;
 - why do we need modules? why not processes?&lt;br /&gt;
   - no new mechanisms&lt;br /&gt;
   - increased security (restricted access)&lt;br /&gt;
   - &amp;quot;microkernel&amp;quot; approach&lt;br /&gt;
   - instead of code talking in supervisor mode, processes do IPC&lt;br /&gt;
      - filesystems&lt;br /&gt;
      - drivers&lt;br /&gt;
      - networking&lt;br /&gt;
   - minix, QNX, GNU hurd&lt;br /&gt;
 - Linux is a &amp;quot;monolithic&amp;quot; kernel.  Why?&lt;br /&gt;
   - performance: context switches are expensive&lt;br /&gt;
     - techniques to make microkernels fast can be adopted by&lt;br /&gt;
       monolithic kernels to make them even faster&lt;br /&gt;
   - security benefit is illusory&lt;br /&gt;
     - if you control the filesystem process, you already own everything&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional===&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; Core kernel functionality is implemented via modules&lt;br /&gt;
--&amp;gt; use ls mod to see modules that are loaded&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is a monolithic kernel?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; a type of OS architecture where the entire OS is working in kernel space&lt;br /&gt;
--&amp;gt; can dynamically load/unload modules at runtime&lt;br /&gt;
&lt;br /&gt;
make localmodconfig:&lt;br /&gt;
--&amp;gt; takes output of ls mod and configures your kernel&lt;br /&gt;
&lt;br /&gt;
ones.c program:&lt;br /&gt;
&lt;br /&gt;
/dev/ones:&lt;br /&gt;
--&amp;gt; permissions are read only&lt;br /&gt;
&lt;br /&gt;
file_operations ones_fops():&lt;br /&gt;
--&amp;gt; defines what happens when you open a file, read from it, release tells you what happens when you&#039;re done with it (not the same thing as close)&lt;br /&gt;
&lt;br /&gt;
ones_read():&lt;br /&gt;
--&amp;gt; len is the number of bytes to read&lt;br /&gt;
--&amp;gt; offset tells you where you are in the file&lt;br /&gt;
--&amp;gt; put_user() takes care of whatever needs to be done to write into that process properly&lt;br /&gt;
&lt;br /&gt;
ones_release: &lt;br /&gt;
&lt;br /&gt;
Why are we using printk instead of printf?&lt;br /&gt;
--&amp;gt; printf is not yet defined (ie. C library is not available in the kernel)&lt;br /&gt;
--&amp;gt; kernel doesn&#039;t depend on any libraries, all code belongs to the kernel itself&lt;br /&gt;
--&amp;gt; printk is the kernel&#039;s own implementation of printf (outputs to the kernel log --&amp;gt; /var/log/kern.log)&lt;br /&gt;
&lt;br /&gt;
vfs = virtual filesystem layer&lt;br /&gt;
&lt;br /&gt;
How do we limit access to user space processes?&lt;br /&gt;
--&amp;gt; Do a permission check&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; kernels need to be updated regularly to correct bugs that make the kernel vulnerable to programs trying to gain access to important user space processes&lt;br /&gt;
--&amp;gt; unlikely() = tells you that this branch is not likely to be taken, optimize the current path&lt;br /&gt;
&lt;br /&gt;
vfs_read:&lt;br /&gt;
&lt;br /&gt;
file-&amp;gt;f_op-&amp;gt;read:&lt;br /&gt;
--&amp;gt; this is how our read function will be called&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_15&amp;diff=21183</id>
		<title>Operating Systems 2017F Lecture 15</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_15&amp;diff=21183"/>
		<updated>2017-11-08T15:11:47Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 7, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec15-07Nov2017.mp4 is now available].  Unfortunately, the video cut out halfway through; [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec15-07Nov2017-audio.m4a audio is also available] however.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 15&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
What&#039;s a filesystem?&lt;br /&gt;
 - persistent data structure organized around fixed allocation units (blocks)&lt;br /&gt;
 - maps hierarchical names (keys) to values&lt;br /&gt;
 - provide a file-like API (open, read, write, close, etc)&lt;br /&gt;
&lt;br /&gt;
What does it mean to &amp;quot;make&amp;quot; a filesystem?&lt;br /&gt;
 - initialize the data structure&lt;br /&gt;
 - &amp;quot;formatting&amp;quot; a disk&lt;br /&gt;
&lt;br /&gt;
Physical versus logical size of a file&lt;br /&gt;
 - logical: the &amp;quot;size&amp;quot; your program sees when accessing the file&lt;br /&gt;
 - physical: how much space the file takes up on disk&lt;br /&gt;
&lt;br /&gt;
Physical is in terms of blocks - fixed units of storage allocation&lt;br /&gt;
 - ext4 has 4k blocks&lt;br /&gt;
 - default for many command line utilities is 1k blocks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel programming&lt;br /&gt;
 - you may destroy the system you are working on AT ANY TIME&lt;br /&gt;
 - HAVE GOOD BACKUPS&lt;br /&gt;
 - rsync is your friend&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel modules&lt;br /&gt;
 - way of splitting up kernel functionality so everything doesn&#039;t have to load&lt;br /&gt;
   at boot&lt;br /&gt;
    - code loaded as part of the initial boot image is hard to get rid of at&lt;br /&gt;
      runtime&lt;br /&gt;
 - why do we need modules? why not processes?&lt;br /&gt;
   - no new mechanisms&lt;br /&gt;
   - increased security (restricted access)&lt;br /&gt;
   - &amp;quot;microkernel&amp;quot; approach&lt;br /&gt;
   - instead of code talking in supervisor mode, processes do IPC&lt;br /&gt;
      - filesystems&lt;br /&gt;
      - drivers&lt;br /&gt;
      - networking&lt;br /&gt;
   - minix, QNX, GNU hurd&lt;br /&gt;
 - Linux is a &amp;quot;monolithic&amp;quot; kernel.  Why?&lt;br /&gt;
   - performance: context switches are expensive&lt;br /&gt;
     - techniques to make microkernels fast can be adopted by&lt;br /&gt;
       monolithic kernels to make them even faster&lt;br /&gt;
   - security benefit is illusory&lt;br /&gt;
     - if you control the filesystem process, you already own everything&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional===&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; Core kernel functionality is implemented via modules&lt;br /&gt;
--&amp;gt; use ls mod to see modules that are loaded&lt;br /&gt;
&lt;br /&gt;
What is a monolithic kernel?&lt;br /&gt;
--&amp;gt; a type of OS architecture where the entire OS is working in kernel space&lt;br /&gt;
--&amp;gt; can dynamically load/unload modules at runtime&lt;br /&gt;
&lt;br /&gt;
make localmodconfig:&lt;br /&gt;
--&amp;gt; takes output of ls mod and configures your kernel&lt;br /&gt;
&lt;br /&gt;
ones.c program:&lt;br /&gt;
&lt;br /&gt;
/dev/ones:&lt;br /&gt;
--&amp;gt; permissions are read only&lt;br /&gt;
&lt;br /&gt;
file_operations ones_fops():&lt;br /&gt;
--&amp;gt; defines what happens when you open a file, read from it, release tells you what happens when you&#039;re done with it (not the same thing as close)&lt;br /&gt;
&lt;br /&gt;
ones_read():&lt;br /&gt;
--&amp;gt; len is the number of bytes to read&lt;br /&gt;
--&amp;gt; offset tells you where you are in the file&lt;br /&gt;
--&amp;gt; put_user() takes care of whatever needs to be done to write into that process properly&lt;br /&gt;
&lt;br /&gt;
ones_release: &lt;br /&gt;
&lt;br /&gt;
Why are we using printk instead of printf?&lt;br /&gt;
--&amp;gt; printf is not yet defined (ie. C library is not available in the kernel)&lt;br /&gt;
--&amp;gt; kernel doesn&#039;t depend on any libraries, all code belongs to the kernel itself&lt;br /&gt;
--&amp;gt; printk is the kernel&#039;s own implementation of printf (outputs to the kernel log --&amp;gt; /var/log/kern.log)&lt;br /&gt;
&lt;br /&gt;
vfs = virtual filesystem layer&lt;br /&gt;
&lt;br /&gt;
How do we limit access to user space processes?&lt;br /&gt;
--&amp;gt; Do a permission check&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; kernels need to be updated regularly to correct bugs that make the kernel vulnerable to programs trying to gain access to important user space processes&lt;br /&gt;
--&amp;gt; unlikely() = tells you that this branch is not likely to be taken, optimize the current path&lt;br /&gt;
&lt;br /&gt;
vfs_read:&lt;br /&gt;
&lt;br /&gt;
file-&amp;gt;f_op-&amp;gt;read:&lt;br /&gt;
--&amp;gt; this is how our read function will be called&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21178</id>
		<title>Operating Systems 2017F Lecture 16</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21178"/>
		<updated>2017-11-07T19:40:20Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Class&lt;br /&gt;
Comp 3000 &lt;br /&gt;
Lecture 16&lt;br /&gt;
Important notes: Tutorial 5:&lt;br /&gt;
File system : &lt;br /&gt;
	persistent data structure organized around blocks (which are fixed allocation units)&lt;br /&gt;
	maps hierarchal names (keys) to values&lt;br /&gt;
	provides a file-like API like open,  read, write, close,etc&lt;br /&gt;
What does it mean to “make” a file system?&lt;br /&gt;
	Initializing a data structure.&lt;br /&gt;
	“formatting” a disk&lt;br /&gt;
Physical vs Logical : logical size of a file: the size your program see when accessing the file (bytes in a file)&lt;br /&gt;
Physical : How much space it takes up on disk , in terms of blocks , fixed units of storage allocation &lt;br /&gt;
&lt;br /&gt;
Physical : &lt;br /&gt;
	By default or for multiple of files it is 1K blocks &lt;br /&gt;
	Example : Ext4 has 4k blocks&lt;br /&gt;
&lt;br /&gt;
Kernel Programing : &lt;br /&gt;
	Warning: &lt;br /&gt;
o	If you use linux base , you may crash your whole system, just backup before you do so using “rsync”.&lt;br /&gt;
Open Stack : log in through the terminal using your instance’s Ip address , but it failed to work . when you ssh to it you must write ssh “Address” –l Ubuntu&lt;br /&gt;
	You are required to use sude to add a user name, so u can play around in root.&lt;br /&gt;
What is a Kernel module ? &lt;br /&gt;
	A way of splitting up kernel functionality so everything does not have to load at boot.&lt;br /&gt;
	Modifies a kernel functionality &lt;br /&gt;
	Runs in kernel space , is the key thing to think about&lt;br /&gt;
o	It is more powerful than root and it can do anything &lt;br /&gt;
o	Access to all kernel memory&lt;br /&gt;
o	And you can modify everything &lt;br /&gt;
	If you miss anything in the kernel development your system will crash &lt;br /&gt;
	Kernel machine provides you with a floppy by default which explains why it still exists in Anil’s terminal&lt;br /&gt;
	Once you install a module , the module is unstrained &lt;br /&gt;
Why do we use modules? Why don’t we load processes instead?&lt;br /&gt;
	No new mechanisms &lt;br /&gt;
	Increased security (restricted access)&lt;br /&gt;
	Makes the kernel less smaller, microkernel design, &lt;br /&gt;
o	Putting in the functions that are supposed to be in the kernel into processes&lt;br /&gt;
o	Process do IPC rather than code talking in supervisor mode&lt;br /&gt;
	Examples : &lt;br /&gt;
•	Filesystems&lt;br /&gt;
•	Drivers&lt;br /&gt;
•	Networking&lt;br /&gt;
•	Minix, QNX, GNU, hurd, &lt;br /&gt;
	Why is Linux  “monolithics” kernel ?&lt;br /&gt;
o	Switching between contexts are expensive (context switch)&lt;br /&gt;
o	How to make microkernels fast can be adopted by monolithics kernels to make them even faster &lt;br /&gt;
o	Unreal security benefits :&lt;br /&gt;
	if you control the file system process, you can control everything &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rebuilding and changing the kernel: &lt;br /&gt;
	1)Type “make” : more compilacted than 2401 &lt;br /&gt;
o	Kernel built&lt;br /&gt;
	2)Make modules &lt;br /&gt;
	3)Sudo make install &lt;br /&gt;
	4) sudo make-modules install &lt;br /&gt;
	5) Sudo shutdown –r now : for the vm to reboot &lt;br /&gt;
	Which configuration would you use to build your own kernel ? &lt;br /&gt;
o	Don’t do configurations from scratch&lt;br /&gt;
o	Copy the configurations and use them&lt;br /&gt;
o	Make localmodconfig : output for ls mod and uses that for configuring your kernel&lt;br /&gt;
o	Requires time and effort &lt;br /&gt;
	Why less /dev/ones doesn’t exist anymore?&lt;br /&gt;
o	Since reboot occurred&lt;br /&gt;
o	You must load the modules again &lt;br /&gt;
o	Head –c 100 /dev/ones to be able to use it again&lt;br /&gt;
	Implementing the device file of dev 1 ? &lt;br /&gt;
&lt;br /&gt;
o	Implement the file API required &lt;br /&gt;
o	Teach the kernel what it means to do operations like read, etc&lt;br /&gt;
Code from the tutorial ones.c:&lt;br /&gt;
	Open ones_read code: file descriptor, file , buffer, amount of bytes to read and offset &lt;br /&gt;
o	Offset : position in the file &lt;br /&gt;
o	Fills the buffer with ones &lt;br /&gt;
o	Why don’t we just set it to 1 instead of putting put_user? &lt;br /&gt;
	Char *buf : Pointer for a user space process, in order for the kernel to write to user spacer safely &lt;br /&gt;
o	Line 46: Why use printk and not printf? Since printf is not defined because the c library is not available in the kernel, how can you can c library when the c library depends on the kernel? Kernel is independent, does not depend on any libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Commands: &lt;br /&gt;
Man ls : to see different ls commands &lt;br /&gt;
	Ls –las block &lt;br /&gt;
	Cat /dev/ones |less : it is like dev u random , but instead of generating random number, it instead generates infinite of number 1&lt;br /&gt;
	Ls –mod : displays all the moduls which are currently loaded on the virtual machine &lt;br /&gt;
	IBM ps/2 :  series of computers created to control PC, developed the interfaces to have a mouse and keyboard. &lt;br /&gt;
	Less readme : to check instructions of how to do a make&lt;br /&gt;
	Make menuconfig : options of kernel configurations&lt;br /&gt;
	Cat/pro&lt;br /&gt;
	Less .config : bad idea to go directly in it , use “make menuconfig “&lt;br /&gt;
	/boot : where the kernel got installed.&lt;br /&gt;
o	Ls –lah : to see the size&lt;br /&gt;
	Less/ etc/modules&lt;br /&gt;
	Modul init: what function should be called when loaded and when it is unloaded &lt;br /&gt;
	Modul exit: &lt;br /&gt;
	Creating a device file : defining a file which has special semantics, define a struct and functions which should be called to explain each file operation, open , read, release(like closing but not really)&lt;br /&gt;
	What happens if you start running to the file ? permission are read only, not writing&lt;br /&gt;
o	Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Additional notes:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; Warning: it&#039;s possible to destroy your entire system with 1 command. Solution: have good backups&lt;br /&gt;
--&amp;gt; Core kernel functionality is implemented via modules&lt;br /&gt;
--&amp;gt; use ls mod to see modules that are loaded&lt;br /&gt;
--&amp;gt; In practice, you load modules all at once&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why do we need to load code into the kernel anyways?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; more secure, ability to restrict access&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; examples of microkernel: minix (predecessor to Linux), QNX, GNU hurd&lt;br /&gt;
--&amp;gt; once you install a module, it&#039;s unrestrained&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is a monolithic kernel?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; a type of OS architecture where the entire OS is working in kernel space&lt;br /&gt;
--&amp;gt; can dynamically load/unload modules at runtime&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;make localmodconfig:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; takes output of ls mod and configures your kernel&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones.c program:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/ones:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; permissions are read only&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;file_operations ones_fops():&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; define what happens when you open a file, read from it, release tells you what happens when you&#039;re done with it (not the same thing as close)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones_read():&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; len = number of bytes to read&lt;br /&gt;
--&amp;gt; offset tells you where you are in the file&lt;br /&gt;
--&amp;gt; put_user(): takes care of whatever needs to be done to write into that process properly&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones_release:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why are we using printk instead of printf?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; printf is not yet defined (ie. C library is not available in the kernel)&lt;br /&gt;
--&amp;gt; kernel doesn&#039;t depend on any libraries, all code belongs to the kernel itself&lt;br /&gt;
--&amp;gt; printk is the kernel&#039;s own implementation of printf (outputs to the kernel log --&amp;gt; /var/log/kern.log)&lt;br /&gt;
&lt;br /&gt;
vfs = virtual filesystem layer&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we limit access to user space processes?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; Do a permission check&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; kernels need to be updated regularly to correct bugs that make the kernel vulnerable to programs trying to gain access to important user space processes&lt;br /&gt;
--&amp;gt; unlikely() = tells you that this branch is not likely to be taken, optimize the current path&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vfs_read:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;file-&amp;gt;f_op-&amp;gt;read:&#039;&#039;&#039; &lt;br /&gt;
--&amp;gt; this is how our read function will be called&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21177</id>
		<title>Operating Systems 2017F Lecture 16</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21177"/>
		<updated>2017-11-07T19:39:58Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Class&lt;br /&gt;
Comp 3000 &lt;br /&gt;
Lecture 16&lt;br /&gt;
Important notes: Tutorial 5:&lt;br /&gt;
File system : &lt;br /&gt;
	persistent data structure organized around blocks (which are fixed allocation units)&lt;br /&gt;
	maps hierarchal names (keys) to values&lt;br /&gt;
	provides a file-like API like open,  read, write, close,etc&lt;br /&gt;
What does it mean to “make” a file system?&lt;br /&gt;
	Initializing a data structure.&lt;br /&gt;
	“formatting” a disk&lt;br /&gt;
Physical vs Logical : logical size of a file: the size your program see when accessing the file (bytes in a file)&lt;br /&gt;
Physical : How much space it takes up on disk , in terms of blocks , fixed units of storage allocation &lt;br /&gt;
&lt;br /&gt;
Physical : &lt;br /&gt;
	By default or for multiple of files it is 1K blocks &lt;br /&gt;
	Example : Ext4 has 4k blocks&lt;br /&gt;
&lt;br /&gt;
Kernel Programing : &lt;br /&gt;
	Warning: &lt;br /&gt;
o	If you use linux base , you may crash your whole system, just backup before you do so using “rsync”.&lt;br /&gt;
Open Stack : log in through the terminal using your instance’s Ip address , but it failed to work . when you ssh to it you must write ssh “Address” –l Ubuntu&lt;br /&gt;
	You are required to use sude to add a user name, so u can play around in root.&lt;br /&gt;
What is a Kernel module ? &lt;br /&gt;
	A way of splitting up kernel functionality so everything does not have to load at boot.&lt;br /&gt;
	Modifies a kernel functionality &lt;br /&gt;
	Runs in kernel space , is the key thing to think about&lt;br /&gt;
o	It is more powerful than root and it can do anything &lt;br /&gt;
o	Access to all kernel memory&lt;br /&gt;
o	And you can modify everything &lt;br /&gt;
	If you miss anything in the kernel development your system will crash &lt;br /&gt;
	Kernel machine provides you with a floppy by default which explains why it still exists in Anil’s terminal&lt;br /&gt;
	Once you install a module , the module is unstrained &lt;br /&gt;
Why do we use modules? Why don’t we load processes instead?&lt;br /&gt;
	No new mechanisms &lt;br /&gt;
	Increased security (restricted access)&lt;br /&gt;
	Makes the kernel less smaller, microkernel design, &lt;br /&gt;
o	Putting in the functions that are supposed to be in the kernel into processes&lt;br /&gt;
o	Process do IPC rather than code talking in supervisor mode&lt;br /&gt;
	Examples : &lt;br /&gt;
•	Filesystems&lt;br /&gt;
•	Drivers&lt;br /&gt;
•	Networking&lt;br /&gt;
•	Minix, QNX, GNU, hurd, &lt;br /&gt;
	Why is Linux  “monolithics” kernel ?&lt;br /&gt;
o	Switching between contexts are expensive (context switch)&lt;br /&gt;
o	How to make microkernels fast can be adopted by monolithics kernels to make them even faster &lt;br /&gt;
o	Unreal security benefits :&lt;br /&gt;
	if you control the file system process, you can control everything &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rebuilding and changing the kernel: &lt;br /&gt;
	1)Type “make” : more compilacted than 2401 &lt;br /&gt;
o	Kernel built&lt;br /&gt;
	2)Make modules &lt;br /&gt;
	3)Sudo make install &lt;br /&gt;
	4) sudo make-modules install &lt;br /&gt;
	5) Sudo shutdown –r now : for the vm to reboot &lt;br /&gt;
	Which configuration would you use to build your own kernel ? &lt;br /&gt;
o	Don’t do configurations from scratch&lt;br /&gt;
o	Copy the configurations and use them&lt;br /&gt;
o	Make localmodconfig : output for ls mod and uses that for configuring your kernel&lt;br /&gt;
o	Requires time and effort &lt;br /&gt;
	Why less /dev/ones doesn’t exist anymore?&lt;br /&gt;
o	Since reboot occurred&lt;br /&gt;
o	You must load the modules again &lt;br /&gt;
o	Head –c 100 /dev/ones to be able to use it again&lt;br /&gt;
	Implementing the device file of dev 1 ? &lt;br /&gt;
&lt;br /&gt;
o	Implement the file API required &lt;br /&gt;
o	Teach the kernel what it means to do operations like read, etc&lt;br /&gt;
Code from the tutorial ones.c:&lt;br /&gt;
	Open ones_read code: file descriptor, file , buffer, amount of bytes to read and offset &lt;br /&gt;
o	Offset : position in the file &lt;br /&gt;
o	Fills the buffer with ones &lt;br /&gt;
o	Why don’t we just set it to 1 instead of putting put_user? &lt;br /&gt;
	Char *buf : Pointer for a user space process, in order for the kernel to write to user spacer safely &lt;br /&gt;
o	Line 46: Why use printk and not printf? Since printf is not defined because the c library is not available in the kernel, how can you can c library when the c library depends on the kernel? Kernel is independent, does not depend on any libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Commands: &lt;br /&gt;
Man ls : to see different ls commands &lt;br /&gt;
	Ls –las block &lt;br /&gt;
	Cat /dev/ones |less : it is like dev u random , but instead of generating random number, it instead generates infinite of number 1&lt;br /&gt;
	Ls –mod : displays all the moduls which are currently loaded on the virtual machine &lt;br /&gt;
	IBM ps/2 :  series of computers created to control PC, developed the interfaces to have a mouse and keyboard. &lt;br /&gt;
	Less readme : to check instructions of how to do a make&lt;br /&gt;
	Make menuconfig : options of kernel configurations&lt;br /&gt;
	Cat/pro&lt;br /&gt;
	Less .config : bad idea to go directly in it , use “make menuconfig “&lt;br /&gt;
	/boot : where the kernel got installed.&lt;br /&gt;
o	Ls –lah : to see the size&lt;br /&gt;
	Less/ etc/modules&lt;br /&gt;
	Modul init: what function should be called when loaded and when it is unloaded &lt;br /&gt;
	Modul exit: &lt;br /&gt;
	Creating a device file : defining a file which has special semantics, define a struct and functions which should be called to explain each file operation, open , read, release(like closing but not really)&lt;br /&gt;
	What happens if you start running to the file ? permission are read only, not writing&lt;br /&gt;
o	Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.&lt;br /&gt;
&lt;br /&gt;
Additional notes:&lt;br /&gt;
--&amp;gt; Warning: it&#039;s possible to destroy your entire system with 1 command. Solution: have good backups&lt;br /&gt;
--&amp;gt; Core kernel functionality is implemented via modules&lt;br /&gt;
--&amp;gt; use ls mod to see modules that are loaded&lt;br /&gt;
--&amp;gt; In practice, you load modules all at once&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why do we need to load code into the kernel anyways?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; more secure, ability to restrict access&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; examples of microkernel: minix (predecessor to Linux), QNX, GNU hurd&lt;br /&gt;
--&amp;gt; once you install a module, it&#039;s unrestrained&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is a monolithic kernel?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; a type of OS architecture where the entire OS is working in kernel space&lt;br /&gt;
--&amp;gt; can dynamically load/unload modules at runtime&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;make localmodconfig:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; takes output of ls mod and configures your kernel&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones.c program:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/ones:&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; permissions are read only&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;file_operations ones_fops():&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; define what happens when you open a file, read from it, release tells you what happens when you&#039;re done with it (not the same thing as close)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones_read():&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; len = number of bytes to read&lt;br /&gt;
--&amp;gt; offset tells you where you are in the file&lt;br /&gt;
--&amp;gt; put_user(): takes care of whatever needs to be done to write into that process properly&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ones_release:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why are we using printk instead of printf?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; printf is not yet defined (ie. C library is not available in the kernel)&lt;br /&gt;
--&amp;gt; kernel doesn&#039;t depend on any libraries, all code belongs to the kernel itself&lt;br /&gt;
--&amp;gt; printk is the kernel&#039;s own implementation of printf (outputs to the kernel log --&amp;gt; /var/log/kern.log)&lt;br /&gt;
&lt;br /&gt;
vfs = virtual filesystem layer&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How do we limit access to user space processes?&#039;&#039;&#039;&lt;br /&gt;
--&amp;gt; Do a permission check&lt;br /&gt;
&lt;br /&gt;
--&amp;gt; kernels need to be updated regularly to correct bugs that make the kernel vulnerable to programs trying to gain access to important user space processes&lt;br /&gt;
--&amp;gt; unlikely() = tells you that this branch is not likely to be taken, optimize the current path&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;vfs_read:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;file-&amp;gt;f_op-&amp;gt;read:&#039;&#039;&#039; &lt;br /&gt;
--&amp;gt; this is how our read function will be called&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21175</id>
		<title>Operating Systems 2017F Lecture 16</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21175"/>
		<updated>2017-11-07T18:03:19Z</updated>

		<summary type="html">&lt;p&gt;Krithikasaravanan: Created page with &amp;quot;In Class&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Class&lt;/div&gt;</summary>
		<author><name>Krithikasaravanan</name></author>
	</entry>
</feed>