summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--file-system.md41
1 files changed, 21 insertions, 20 deletions
diff --git a/file-system.md b/file-system.md
index acd7ab5..fa98d8e 100644
--- a/file-system.md
+++ b/file-system.md
@@ -13,17 +13,18 @@ If we look at storage devices as a way to store a bunch of ones and zeroes, we
13can see that this is not the most humane way of storing data. At the hardware 13can see that this is not the most humane way of storing data. At the hardware
14level, there is no concept of file or directories, so we need a way of 14level, there is no concept of file or directories, so we need a way of
15organizing these ones and zeroes in such a way that we can tell "such and such 15organizing these ones and zeroes in such a way that we can tell "such and such
16series of bytes corresponds to the `/home/user/file.txt` content". 16series of bytes correspond to the `/home/user/file.txt` content".
17 17
18This is exactly what a file system is. At the core, a file system is a way of 18This is exactly what a file system is. At the core, a file system is a way of
19organizing data (we can this a "format", since it's a way of "formatting" 19organizing data (we call this a "format", since it's a way of "formatting"
20data). 20data).
21 21
22Once we have some storage formatted for a known file system, we rely on the 22Once we have some storage formatted for a known file system, we rely on the
23kernel to be able to read this file system. 23kernel to be able to read this file system.
24 24
25Then, once we know the kernel is able to read the file system, we want to tell 25Then, once we know the kernel is able to read the file system, we want to tell
26the kernel where we would like to see it in our directory tree. This is called "[mounting](#mounts)" a file system. 26the kernel where we would like to see it in our directory tree. This is called
27"[mounting](#mounts)" a file system.
27 28
28 29
29## Storage devices 30## Storage devices
@@ -42,7 +43,7 @@ In Flash Memory, used in USB Flash drives and often used in embedded systems,
42you cannot set a single 0 to a 1, but instead have to erase a whole "sector" to 43you cannot set a single 0 to a 1, but instead have to erase a whole "sector" to
43set every bit in that sector back to a 1. 44set every bit in that sector back to a 1.
44 45
45While these specificities might have an impact in high end computing, or bare 46While these specificities might have an impact in high-end computing, or bare
46metal embedded systems (i.e. without a kernel), in our case, we thankfully 47metal embedded systems (i.e. without a kernel), in our case, we thankfully
47don't have to care about any of that. 48don't have to care about any of that.
48 49
@@ -51,7 +52,7 @@ implemented in the kernel, leaving us with a much simpler interface, like
51`read` and `write` system calls. 52`read` and `write` system calls.
52 53
53 54
54## Some known file systems 55## Some well-known file systems
55 56
56Just as there are multiple ways of storing an image in a file (jpeg, png, bmp, 57Just as there are multiple ways of storing an image in a file (jpeg, png, bmp,
57etc.), there are multiple file system formats. 58etc.), there are multiple file system formats.
@@ -65,7 +66,7 @@ Flash Drive into something (computer, router, gaming console, etc.), you can be
65pretty sure it'll work. 66pretty sure it'll work.
66 67
67It is not without drawbacks though: it is prone to fragmentation, can't handle 68It is not without drawbacks though: it is prone to fragmentation, can't handle
68files bigger than 4GB, and doesn't have many features that more modern file 69files bigger than 4 GB, and doesn't have many features that more modern file
69systems have (e.g. error recovery). 70systems have (e.g. error recovery).
70 71
71### ext4 72### ext4
@@ -78,7 +79,7 @@ using ext4.
78 79
79NTFS is the standard file system used by Windows computers. To my knowledge, it 80NTFS is the standard file system used by Windows computers. To my knowledge, it
80is not much used elsewhere, except to have Windows compatible external drives, 81is not much used elsewhere, except to have Windows compatible external drives,
81and support files bigger than 4GB (so FAT32 is not a valid choice). 82and support files bigger than 4 GB (so FAT32 is not a valid choice).
82 83
83 84
84## Enabling file systems in the kernel 85## Enabling file systems in the kernel
@@ -102,13 +103,13 @@ To enable or disable a file system in the kernel, simply go to your
102[configuration](kernel.md#configuring-the-kernel), look up your file system in 103[configuration](kernel.md#configuring-the-kernel), look up your file system in
103the "File Systems" menu, and enable or disable it. 104the "File Systems" menu, and enable or disable it.
104 105
105## Usual format of a file system 106## Anatomy of a file system
106 107
107Because a file system stores more that just the content of files, it needs 108Because a file system stores more that just the content of files, it needs
108space for this "meta data". Different file systems do this differently, and 109space for this "metadata". Different file systems do this differently, and
109have different needs, so let's quickly look at a few examples: 110have different needs, so let's quickly look at a few examples:
110 111
111TODO: reference source of image 112TODO: install the pandoc-citeproc filter
112 113
113![FAT32 format](./res/fat32.jpg) 114![FAT32 format](./res/fat32.jpg)
114 115
@@ -130,8 +131,8 @@ partitions fails, fall back on booting on the other (in case a system upgrade
130broke something, for example). 131broke something, for example).
131 132
132Like everything else in computer science, you have several ways of doing it: in 133Like everything else in computer science, you have several ways of doing it: in
133a similar to file systems, partitioning schemes are a way of formatting ones 134a similar way to file systems, partitioning schemes are a way of formatting
134and zeroes, but instead of storing files, it stores file systems. 135ones and zeroes, but instead of storing files, it stores file systems.
135 136
136The two most common partitioning schemes are GPT (the most modern one) and MBR 137The two most common partitioning schemes are GPT (the most modern one) and MBR
137(which you'll often find on older systems). 138(which you'll often find on older systems).
@@ -141,7 +142,7 @@ TODO: reference source of image
141![GPT format](./res/GUID-Partition-Table-Scheme.svg) 142![GPT format](./res/GUID-Partition-Table-Scheme.svg)
142 143
143 144
144Like file format, you'll find sections dedicated to the meta data of the 145Like file format, you'll find sections dedicated to the metadata of the
145partitions (i.e. name of the partitions, id of the partition, etc.), and 146partitions (i.e. name of the partitions, id of the partition, etc.), and
146a whole space (partition data) to put your file system. 147a whole space (partition data) to put your file system.
147 148
@@ -188,13 +189,13 @@ But this is not what we usually want, we want to access the partitions inside
188the disk. For this, the kernel provides us with the files `/dev/sda1`, 189the disk. For this, the kernel provides us with the files `/dev/sda1`,
189`/dev/sda2`, etc. 190`/dev/sda2`, etc.
190 191
191In a similar fashion, if you were to read directly from the file `/dev/sda2`, 192Similarly, if you were to read directly from the file `/dev/sda2`, you would
192you would get the bytes that are stored in the second partition of the first 193get the bytes that are stored in the second partition of the first disk (and
193disk (and you could parse yourself the format ext4, fat32, etc.) 194you could parse yourself the format ext4, fat32, etc.)
194 195
195Again, we do not usually want to access the bytes inside of the partition, but 196Again, we do not usually want to access the bytes inside the partition, but we
196we want to access the files stored inside of the file system of the partition! 197want to access the files stored inside the file system of the partition! To
197To that end, what we do is [mount](#mounts) the file system. 198that end, what we do is [mount](#mounts) the file system.
198 199
199Accessing the raw bytes of the disk or partition is often useful, however. It 200Accessing the raw bytes of the disk or partition is often useful, however. It
200can be used to list all the partitions in a disk, resize partitions, or get 201can be used to list all the partitions in a disk, resize partitions, or get
@@ -253,7 +254,7 @@ To mount a file system, we can use the `mount` command (being root is needed):
253root@host:~$ mount /dev/sda1 /mnt 254root@host:~$ mount /dev/sda1 /mnt
254``` 255```
255 256
256With this command, the kernel will try to auto detect the type of file system 257With this command, the kernel will try to auto-detect the type of file system
257(ext4, fat, etc.), and provide you with the files inside that file system under 258(ext4, fat, etc.), and provide you with the files inside that file system under
258the given directory (in this example: `/mnt`). 259the given directory (in this example: `/mnt`).
259 260