# SO - Lista 11
###### tags: `SO`
## Zadanie 1

### TODO
1. Gdzie można instalować pseudo systemy plików?
2. Scenariusze kiedy używamy relatime, noexec i nodev
Punkty montażowe - A mount point is a directory on a file system that is logically linked to another file system.
Linux has two default mount point locations for removable media: /dev (device) is where all physical devices are first mounted. From there, an additional link to the removable media is made in the /mnt (mount) directory. The /mnt directory and subdirectories are intended for mount points to removable or temporary files storage.
As an example of using mount points, consider plugging a USB flash drive into a Linux computer. The system detects the hardware device and puts it into the file system at /dev/sdc1. You then execute the command mount /dev/sdc1 /mnt/usb to mount the file system on the USB drive to the mount point location /mnt/usb. To make the data more convenient to use, you then create an additional mount point with the command mount /dev/sdc1 /home/john/files to put the data in the home directory.
The file for default mount points to be loaded at system startup is located in /etc/fstab for many Linux distributions.
----------------------------------------------------------
A mount point is a directory or file at which a new file system, directory, or file is made accessible. To mount a file system or a directory, the mount point must be a directory; and to mount a file, the mount point must be a file.
Typically, a file system, directory, or file is mounted over an empty mount point, but that is not required. If the file or directory that serves as the mount point contains any data, that data is not accessible while it is mounted over by another file or directory. In effect, the mounted file or directory covers what was previously in that directory. The original directory or file that has been mounted over is accessible again once the mount over it is undone.
When a file system is mounted over a directory, the permissions of the root directory of the mounted file system take precedence over the permissions of the mount point. The one exception involves the .. (dot dot) parent directory entry in the mounted-over directory. In order for the operating system to access the new file system, the mount point parent directory information must be available.
For example, if the current working directory is /home/frank, the command cd .. changes the working directory to /home. If /home/frank directory is the root of a mounted file system, the operating system must find the parent directory information in the /home/frank directory in order for the cd .. command to succeed.
```
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=3976620k,nr_inodes=994155,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=800052k,mode=755)
/dev/nvme0n1p4 on / type ext4 (rw,relatime,errors=remount-ro)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=10822)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
/var/lib/snapd/snaps/core18_2667.snap on /snap/core18/2667 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/gtk-common-themes_1535.snap on /snap/gtk-common-themes/1535 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/gnome-3-28-1804_161.snap on /snap/gnome-3-28-1804/161 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/core18_2654.snap on /snap/core18/2654 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/core_14399.snap on /snap/core/14399 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/spotify_60.snap on /snap/spotify/60 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/bare_5.snap on /snap/bare/5 type squashfs (ro,nodev,relatime,x-gdu.hide)
/dev/nvme0n1p1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=800048k,nr_inodes=200012,mode=700,uid=1000,gid=1000)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
portal on /run/user/1000/doc type fuse.portal (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
```
Kolumny:
* nazwa
* ścieżka
* architektura
* właściwości:
* tryb systemu





## Zadanie 2


*Superblok* - (SB) przechowuje najważniejsze właściwości systemu plików
(blksz, #blk, #inode). Deskryptory grup (GDs) przechowują położenie
i rozmiar bitmapy zajętości bloków i i-węzłów każdej grupy bloków.
https://www.nongnu.org/ext2-doc/ext2.html#superblock
block size = 1024 << s_log_block_size;
s_inodes_per_group
s_blocks_per_group
number_of_entries = s_blocks_count / s_blocks_per_group.

Descriptor = 32B
Descriptors = (32 * (number_of_entries)) / (block size).
Inodes_per_block = block_size / s_inode_size
For each block group in the file system, such a group_desc is created. Each represent a single block group within the file system and the information within any one of them is pertinent only to the group it is describing. Every block group descriptor table contains all the information about all the block groups.
inodes_per_block = block_size / s_inode_size
Inode tables = Inode_per_group / inodes_per_block

Każda grupa bloków składa się z kopii superbloku, kopii tablicy deskryptorów grpu bloków, bitmapy bloku, bitmapy i-węzła, tablicy i-węzłów i bloków z danymi. Rozmiar obu bitmap to 1 bajt dla każdej, tablica i-węzłów zajmuje s_inodes_per_group / inodes_per_block, gdzie inodes_per_block = block_size / s_inode_size, a resztę miejsca zajmują bloki z danymi.
"The first version of ext2 (revision 0) stores a copy at the start of every block group, along with backups of the group descriptor block(s). Because this can consume a considerable amount of space for large filesystems, later revisions can optionally reduce the number of backup copies by only putting backups in specific groups (this is the sparse superblock feature). The groups chosen are 0, 1 and powers of 3, 5 and 7."
## Zadanie 3


Blok pośredni (ang. indirect block) to blok zawierający wskaźniki na inne bloki pośrednie lub na bloki danych, zwykle jest używany przy pracy z dużymi plikami.
Zapis synchroniczny wykonywany jest za pomocą polecenia fsync(2) lub fdatasync(2). Oznacza to, że dane zapisywane są do deskryptora pliku fd na dysku (lub innym urządzeniu) w taki sposób, że po crashu systemu lub reboocie pliki nadal mogą zostać odzyskane.
Dopisanie n bloków na koniec pliku może odbywać się w następujący sposób. Wybieramy wolne bloki i zapalamy ich bity, aby zaznaczyć, że są używane. Następnie zapisujemy zawartość tych bloków i dodajemy bloki do i-węzła: w razie potrzeby tworzymy bloki pośrednie lub modyfikujemy aktualnie istniejące, a później aktualizujemy metadane i-węzła: wskaźniki na bloki, rozmiar i timestamp.
Metadane do aktualizacji - wskaźniki, rozmiar, czas
## Zadanie 4

### TODO
1. Ale w sumie to czemu jest ten EXDEV?
EXDEV - Oldpath and newpath are not on the same mounted filesystem. (Linux permits a filesystem to be mounted at multiple points, but ```rename()``` does not work across different mount points, even if the same filesystem is mounted on both.)
Algorytmem wykorzystywanym do przenoszenia pliku między dwoma różnymi katalogami może być następujący ciąg instrukcji: zwiększamy licznik dowiązań i_links_count w i-węźle przenoszonego pliku, a jeśli w katalogu docelowym jest wyzerowany wpis (katalog pusty), to zmieniamy go na wpis pliku, który przenosimy. W przeciwnym wypadku dodajemy do katalogu docelowego wpis przenoszonego pliku i modyfikujemy poprzedni w taki sposób, aby nie wskazywał na koniec bloku. W poprzednim katalogu “usuwamy” wpis zmieniając wartość inode na 0 i zmieniamy licznik dowiązań w i-węźle tego pliku (przed przeniesieniem i po powinien być taki sam - jest to pewnego rodzaju niezmiennik, jako że nie wykonujemy kopii, to w systemie powinno być tyle samo dowiązań).
## Zadanie 5

1. Gasimy
2. Zmniejszamy licznik
3. Usuwamy
### TODO
Undelete???
## Zadanie 6

Zawartość dowiązania symbolicznego jest często przechowywana w samym i-node, ze względu na mały rozmiar.
Pętle tworzymy dowiązaniem symbolicznym na "."
Jądro systemu zwraca błąd kiedy przekroczymy dopuszczalną głębokość rekursji
Hardware nie pozwala na robienie pętli na hardlinkach!
## Zadanie 7

Fragmentacja jest zła bo wydajność.
Odroczony przydział bloków pozwala na lepsze zarządzanie pamięcią, poprzez przygotowanie bloków na podstawie aktualnego rozmiaru i tempa jego wzrostu

Zakresy (ang. extents) pomagają w ograniczaniu rozmiaru metadanych przechowujących adresy bloków należących do danego pliku. Wykorzystuje je system plików ext4. Pole zakresu zajmuje 48 bitów i może reprezentować $2 ^{15}$
sąsiadujących ze sobą bloków. Każdy węzeł w drzewie zaczyna się nagłówkiem, który zawiera liczbę poprawnych wpisów w węźle. Sposób, w jaki zakresy pomagają w ograniczaniu rozmiaru metadanych jest dość prosty: tworzony jest tymczasowy i-węzeł, a następnie alokowany w nim jest ciągły zakres. Następnie dane są kopiowane z oryginalnego i-węzła do tymczasowego, do czego wykorzystywany jest odroczony przydział bloków. Na samym końcu przepinane są wskaźniki na bloki z tymczasowego i-węzła do oryginalnego. W taki sposób odbywa się defragmentacja, dzięki której możemy uzyskać więcej wolnych bloków - używane będzie mniej zakresów, niż poprzednio. Poniższy schemat przedstawia układ drzewa zakresów: