1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
\subsubsection{Filesystem Elements}
% ----------------------------
\begin{frame}
\frametitle{Filesystem: Basics Elements}
\begin{itemize}
\item Filesystem
\begin{itemize}
\item structured data organization for block-devices
\item super-block, inodes, data-blocks
\end{itemize}
\item super-block
\begin{itemize}
\item information about the filesystem itself
\end{itemize}
\item inode
\begin{itemize}
\item organizational data structure
\item unique inode number
\item meta-data
\item list of data-block addresses
\end{itemize}
\item data-block
\begin{itemize}
\item payload storage
\end{itemize}
\end{itemize}
\end{frame}
% Any data on a block-device is stored and accessed in blocks. This is an
% efficient way to deal with large data-sets. Because it is not easy, to
% find the right information in large, unsorted data-sets (especially for
% humans), Linux provides filesystems to organize the data in a
% block-device.
% Filesystems use some blocks of a block-device to store organizational
% information about the payload data on the device. The organizational
% structures are called "inodes".
% The "super-block" of a filesystem stores information about the filesystem
% itself, like block-size, number of blocks, number of inodes, and so on.
% ----------------------------
\begin{frame}[fragile]
\frametitle{Filesystem: INodes and Data-Blocks}
\begin{figure}[h]
\centering
\includegraphics[width=5cm]{images/filesystem-organization.png}
\end{figure}
\end{frame}
% The Diagram shows the organization of inodes and blocks. The inode is the
% informational part of a file or directory, it contains the meta-data (like
% owner, group, access-permissions) and the addresses of the data-blocks
% (where the data of a file or directory is stored).
% The payload of directories are name/inode-number tuples of their elements.
\subsubsection{File Types}
% ----------------------------
\begin{frame}[fragile]
\frametitle{File Types}
\begin{itemize}
\item \textbf{-}: normal file
\item \textbf{d}: directory
\item \textbf{l}: symbolic link
\item \textbf{c}: character device
\item \textbf{b}: block device
\item \textbf{s}: socket
\item \textbf{p}: named pipe (FIFO)
\end{itemize}
\bigskip
\begin{beamerboxesrounded}[shadow=true]{Listing: all file-types}
\begin{scriptsize}
\begin{verbatim}
-rw-r--r-- 1 6 file
drwxr-xr-x 2 4096 directory
lrwxrwxrwx 1 4 symlink -> file
crw-r--r-- 1 4, 65 devicenode_character
brw-r--r-- 1 8, 0 devicenode_block
srwxr-xr-x 1 0 socket
prw-r--r-- 1 0 pipe
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% Linux has several file types. The behaviour varies depending on the file
% type, but for the access to all type of files, the same syscalls are used
% (open, read, write, ioctl, mmap, ...).
% The file-types in Linux are:
% Normal file (-), directory (d), symbolic link (l), character and block
% devicenode, socket and pipe.
% ----------------------------
\begin{frame}[fragile]
\frametitle{Directory}
\begin{itemize}
\item hierarchical structure
\item references: name -> inode tuples
\item access permissions: create/delete entries
\item create directory: \textbf{mkdir <name>}
\end{itemize}
\bigskip
\begin{beamerboxesrounded}[shadow=true]{Listing: Directories}
\begin{scriptsize}
\begin{verbatim}
drwxr-xr-x 2 4096 directory1
dr-xr-x--- 2 4096 directory2
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% Directories provides a hierarchical organization for all file-types. In
% its payload, a directory contains name-inode tuples (file-names). The
% access-permissions of a directory manages the access of the directory
% itself, directory entries can be created or removed. E.g. if a directory
% is read-only, it is not possible to create new files in, or delete
% existing files from this directory.
% ----------------------------
\begin{frame}[fragile]
\frametitle{Symlinks}
\begin{itemize}
\item reference by pathname (relative and absolute)
\item broken, if destination doesn't exist
\item cross-filesystem: yes
\item access permissions: -
\item size: length of referenced pathname
\item create symlink: \textbf{ln -s <src> <dst>}
\end{itemize}
\bigskip
\begin{beamerboxesrounded}[shadow=true]{Listing: Symbolic Links}
\begin{scriptsize}
\begin{verbatim}
-rw-r--r-- 1 6 file
lrwxrwxrwx 1 4 symlink_rel -> file
lrwxrwxrwx 1 15 symlink_abs -> /home/user/file
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% Symlinks (or symbolic-links) are references to another entity in the
% filesystem-tree, based on its pathname. The path of a symlink can be
% either relative (to the link) or absolute (path starts with a /). Symlinks
% can be created to entities in another filesystem, where hard-links are
% filesystem-local. A link is broken, if the destination entity doesn't
% exist. The length of a symlink depends of the length of the path-name.
% The access-permissions of a symlink has no meaning in Linux.
% ----------------------------
\begin{frame}[fragile]
\frametitle{Hard Links}
\begin{itemize}
\item additional name entry to same inode-number
\item increase reference-count
\item cross-filesystem: no
\item access permissions: same as destination
\item size: same as destination
\item create hard-link: \textbf{ln <src> <dst>}
\item delete: remove only name-entry
\begin{itemize}
\item remove name-inode tuple (directory)
\item decrease reference-count (inode)
\end{itemize}
\end{itemize}
\bigskip
\begin{beamerboxesrounded}[shadow=true]{Listing: Hard Links}
\begin{scriptsize}
\begin{verbatim}
3165779 -rw-r--r-- 2 6 Jan 11 14:16 file
3165779 -rw-r--r-- 2 6 Jan 11 14:16 hard_link
3165785 lrwxrwxrwx 1 4 Jan 11 14:22 symlink -> file
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% Hardlinks are (additional) named references to an inode. Normal files are
% hard-links with a reference-count of 1. Had-links can only exist
% filesystem-local, because its just a name-inode reference.
% The meta-data (size, timestamp, access-permissions) of a hard-link are
% identical with the destination, because they are stored in the inode, the
% hard-links references to. Deleteing a hard-link does not affect the file
% content, it just removes the name-entry in the directory. Only if the last
% hard-link is removed (reference.count==0), the content is freed.
% Note: The filename is not part of the meta-data, its an entry in the
% directory.
% ----------------------------
\begin{frame}[fragile]
\frametitle{Character/Block Devices}
\begin{itemize}
\item inode-only
\item device handle/reference for Userspace
\item meta-data: major and minor number
\item more details: see \textbf{Linux Userspace-to-Kernel API}
\end{itemize}
\bigskip
\begin{beamerboxesrounded}[shadow=true]{Listing: Hard Links}
\begin{scriptsize}
\begin{verbatim}
crw-r--r-- 1 4, 65 devicenode_character
brw-r--r-- 1 8, 0 devicenode_block
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\begin{frame}[fragile]
\frametitle{Pipe and Socket}
\begin{itemize}
\item inode-only
\item named handle to IPC machanism (provided by Kernel)
\item pipe: FIFO (like anonymous pipes)
\item socket: UNIX domain socket
\end{itemize}
\bigskip
\begin{beamerboxesrounded}[shadow=true]{Listing: Hard Links}
\begin{scriptsize}
\begin{verbatim}
srwxr-xr-x 1 0 socket
prw-r--r-- 1 0 pipe
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}
% ----------------------------
\subsubsection*{}
\begin{frame}
\frametitle{Resources}
\begin{itemize}
\item linfo.org
\begin{itemize}
\item \href {http://www.linfo.org/inode.html}{Inode Definition}
\item \href {http://www.linfo.org/file.html}{Files: A Brief Introduction}
\end{itemize}
\item man-Pages
\begin{itemize}
\item \href {http://man7.org/linux/man-pages/man1/ls.1.html}{man 1 ls}
\item \href {http://man7.org/linux/man-pages/man1/rm.1.html}{man 1 rm}
\item \href {http://man7.org/linux/man-pages/man1/ln.1.html}{man 1 ln}
\item \href {http://man7.org/linux/man-pages/man1/mkdir.1.html}{man 1 mkdir}
\item \href {http://man7.org/linux/man-pages/man1/mkfifo.1.html}{man 1 mkfifo}
\item \href {http://man7.org/linux/man-pages/man7/symlink.7.html}{man 7 symlinks}
\item \href {http://man7.org/linux/man-pages/man7/pipe.7.html}{man 7 pipe}
\end{itemize}
\end{itemize}
\end{frame}
|