Skip to content
On this page
6. Virtual File System
1

Virtual File System

/dev, /proc, /tmp, /sys

15.05.2023
6. Virtual File System
2

Zugriff auf Files

  • File wird geöffnet: open
  • File wird gelesen und/oder beschrieben: read / write.
  • Sprung innerhalb eines Files: seek.
  • File wird geschlossen: close.
  • Kontrollanweisung (unabh. von read / write): ioctl.
15.05.2023
6. Virtual File System
3

File Users / Groups

  • In Linux Files haben Zugehörigkeit
  • ... zu einem user.
  • ... zu einer group.
  • Beispiel: ls -al
15.05.2023
6. Virtual File System
4

Output von ls -al

bash
# PERMISSIONS  USER  GROUP  SIZE
drwxr-xr-x  5 office office 4096 Mär 21 21:41 .
drwxr-xr-x 44 office office 4096 Apr 13 12:22 ..
-rw-r--r--  1 office office  102 Mär 21 21:41 envsetup.sh
drwxr-xr-x  8 office office 4096 Mär 25 16:35 gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
drwxr-xr-x 25 office office 4096 Mär 21 21:49 linux-stable
lrwxrwxrwx  1 office office   52 Mär 21 21:33 toolchain -> gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/
drwxr-xr-x 25 office office 4096 Mär 21 21:35 u-boot
15.05.2023
6. Virtual File System
5

Ownership eines Files ändern

bash
sudo touch hello

ls -l hello
-rw-r--r--  1 root   root      0 Apr 13 13:44 hello

sudo chown office.office hello

ls -l hello
-rw-r--r--  1 office office    0 Apr 13 13:44 hello
15.05.2023
6. Virtual File System
6

Groups

  • Groups können mehrere Users beinhalten
  • Users können mehreren Groups angehören
bash
# groups des users anzeigen
groups
office adm cdrom sudo dip plugdev lpadmin sambashare

# alle groups
cat /etc/group
15.05.2023
6. Virtual File System
7

Permissions

  • r : read
  • w : write
  • x : execute
  • -rw-r--r-- 1 office office 29 Apr 13 14:12 hello.sh
bash
user group others
rw-  r--   r--
15.05.2023
6. Virtual File System
8

Beispiel: Bash Script

bash
cat hello.sh
#!/bin/bash
echo "Compiling"

ls -l hello.sh
-rw-r--r-- 1 office office 29 Apr 13 14:12 hello.sh

# try exec
./hello.sh
bash: ./hello.sh: Permission denied
15.05.2023
6. Virtual File System
9

Mit chmod ausführbar machen

bash
# x für user hinzufügen
chmod u+x hello.sh
ls -l hello.sh
-rwxr--r--  1 office office   29 Apr 13 14:12 hello.sh

# im terminal ist hello.sh nun auch grün => ausführbar

./hello.sh
Compiling
15.05.2023
6. Virtual File System
10

File Types

  • Erster character in ls -l ist der File Type
NameType
-Regular File
dDirectory
lSymbolic Link
pNamed Pipe
sSocket
cCharacter Device
bBlock Device
15.05.2023
6. Virtual File System
11
  • Abkürzung, welche auf ein File zeigt
  • Softlink / Hardlink
bash
# Softlink erstellen
cd
cd esl
ln -s gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf toolchain
ls -l toolchain
lrwxrwxrwx 1 office office 51 Apr 13 14:33 toolchain -> gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
15.05.2023
6. Virtual File System
12
  • Abstraktion: Link kann ausgetauscht werden
  • ... während Zielfiles gleich bleiben (und namen erhalten bleibt)
  • Namen können kurz gehalten werden
  • Löschen des Symlinks löscht das Zielfile nicht
15.05.2023
6. Virtual File System
13

File System Tree

bash
# Anzeigen des Root File Systems
ls -l /
  • / ist die "Wurzel" / "Root" des File Systems.
  • Auf dem Target wird das RFS von der SD-Karte gemounted
  • mount = Einbinden eines Filesystems
  • Anzige via mount Befehl
15.05.2023
6. Virtual File System
14

File System Tree

bash
mount

/dev/nvme0n1p3 on / type ext4 (rw,relatime,errors=remount-ro)
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=8115788k,nr_inodes=2028947,mode=755)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/sdc5 on /boot type ext4 (rw,relatime)
15.05.2023
6. Virtual File System
15

Mountpoints

  • Was wird wo gemounted
    • /dev/nvme0n1p3 on /
    • sysfs on /sys
  • File System Type: ext4, tmpfs, sysfs
  • Optionen
    • rw: read / write
    • ro: readonly
    • noatime: Keine Änderung bei last Access Time
15.05.2023
6. Virtual File System
16

inodes

  • Bei Linux Filesystemen (z.B. ext)
    • Speichern Metainfos eines Files
    • Sind in einem fixen Bereich der Partition
    • ... Es gibt nur endlich viele inodes: limitiert Anzahl Files auf dem fs
    • Speichert weder Namen noch Inhalt des Files
    • Beinhaltet Hirarchische Struktur des Filesystems
  • Bei Pseudo- / VFS im Memory
15.05.2023
6. Virtual File System
17

Infos eines inodes via stat

bash
stat hello.sh
  File: hello.sh
  Size: 29        	Blocks: 8          IO Block: 4096   regular file
Device: 10303h/66307d	Inode: 15991128    Links: 1
Access: (0744/-rwxr--r--)  Uid: ( 1000/  office)   Gid: ( 1000/  office)
Access: 2020-04-13 14:12:54.441693474 +0200
Modify: 2020-04-13 14:12:39.217653839 +0200
Change: 2020-04-13 14:23:34.086831762 +0200
 Birth: -
15.05.2023
6. Virtual File System
18

Grundsatz in *nix Systemen

Everything is a File

  • Zugriff via read / write / open / close
  • Vorteile:
    • Einbindung ins FS möglich
    • ... somit auch sichtbar mit ls / File Explorer
    • Permission System vom FS applizierbar.
    • Einfaches und unversales Interface für libc über System Calls
15.05.2023
6. Virtual File System
19

/dev Interface zu Device Drivers

  • Zugriff erfolgt via Virtuelles File System
  • open erfolgt im File System
    • Beispiel: dd auf /dev/sdb
  • Permissions werden im File System geprüft.
    • ... wie bei "normalen" Files.
15.05.2023
6. Virtual File System
20

Device Nodes

  • Sind keine "normale" Files
  • Sind keine Treiber
  • Sind Einträge im VFS (Special Files)
  • Beim Booten wird /dev als devtmpfs gemounted
  • Ein Gerät wird vom Kernel erkannt
    • ... ein neuer Eintrag im devtmpfs wird automatisch angelegt
  • udev passt die Permissions an.
15.05.2023
6. Virtual File System
21

udev

  • Ist ein User-Space Device Manager
  • Zuständig für "Hotplug" Mechanismus für Geräte unter /dev
  • Lädt unter anderem Firmware für Peripherie nach
  • Setzt permissions für Nodes unter /dev
    • Beispiel UART: /dev/ttyAMC0
    • Kann Programme ausführen, sobald ein neues Gerät eingebunden wird
15.05.2023
6. Virtual File System
22

Major / Minor Numbers unter /dev

  • Major Number
    • Identifiziert zuständigen Treiber
    • ... siehe /proc/devices
    • 1 Aufwäres für fix Reservierte Major Nodes
    • ... 255 Abwärts für dynamisch registrierte Nodes
  • Minor Number
    • Treiberspeziefisch ...
    • ... zB. Partition / Audiokanal / Serielle Schnittstelle
    • ... kann auch zur Treiberauswahl verwendet werden
15.05.2023
6. Virtual File System
23

Characterdevice

  • Verwendet für Character-wise Zugriff auf Gerät
    • Serielle Schnitstelle
    • Soundkarte
    • Input Device
    • Busse
15.05.2023
6. Virtual File System
24

Blockdevice

  • Verwendet für Block-wise Zugriff auf Gerät
    • Festplatte
    • Flash Speicher
    • SSD
  • Einbindbar via mount
15.05.2023
6. Virtual File System
25

Abstraktion bei Block Devices

15.05.2023
6. Virtual File System
26

Zugriff auf Blockdevice

  1. Aufruf via Systemcall / Streaming Function aus glibc
  2. Mapping von VFS auf Gerätetreiber, Prüfung Permissions
  3. Performance Optimierung via RAM
  4. Implementierung des FS (ext4 / FAT / NTFS / btrfs)
  5. Block IO für Medium (Scheduling / Abstraktion von Transfers)
  6. Device Treiber für Bus
  7. Speichermedium
15.05.2023
6. Virtual File System
27

Proc FS

  • Zugriff auf System- und Prozessinfo aus dem User Space
  • ... via File-IO
  • Info per man proc
  • Dokumentation <Kernelsource>/Documentation/filesystems/proc.txt
15.05.2023
6. Virtual File System
28
File
/proc/versionKernel Build and Version Info
/proc/cpuinfoInfos zum Prozessor
/proc/cmdlienKernel Command Line
/proc/meminfoInfo zu Memory (wie in top)
/proc/partitionsPartitionstabellen
/proc/bus/input/devicesHID Input Devices
/proc/<PID>/mapsMemory Map eines Prozesses
15.05.2023
6. Virtual File System
29

Mounten eines Filesystems

bash
mount -t <filesystemtyp>  <blockdevicenode> <mountpoint>
  • Automatisches Mounten via /etc/fstab
15.05.2023