\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}
