0% found this document useful (0 votes)
23 views14 pages

Understanding Linux File Systems

Uploaded by

fabio.guelfi64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views14 pages

Understanding Linux File Systems

Uploaded by

fabio.guelfi64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[J]EMARO – Robotics Engineering

POSIX
ESSENTIALS
Part II - FILES

Rur Zaccaria, 2023-2024


files


POSIX manages two types of Inter Process Communication
(IPC) primitives:
– data
– events

Data IPC are supported by a unique concept named FILE

Posix inherits from Unix the file concept
concept and terminology

a FILE is an abstract concept to accomplish the whole series of


data transfer services of the OS:

regular file: traditional permanent data storage, with serial or
random access in secondary memory

special or device: interface with I/O device drivers (mass
storage, windows, printer, network...)

shared memory: access to shared memory between
processes

socket: IP connection with machines in internet

pipe: standard serial IPC channel between processes
concept and terminology


directory: node of a tree of files or, recursively, of directories

file system: root of a tree of directories and files

physical file system: a hard disk partition

pseudo/virtual file systems for different operations and services:
– accessing kernel’s internal values and accessing hardware
(proc, sys)
– connecting peripherals,like an ISO CDROM (loop)
– installing software (snap)
– providing special computational I/O (null, zero, random...)
– a file system stored in memory simulating a mass storage
(ramfs, tmpfs)
Concept (cont.)

pathname: the textual definition of a file in the hierarchy, absolute or
relative:
– absolute: a slash separated list of directories to descend from root plus
the filename itself; example: usr/bin/ls
– relative: the same, but using the pseudonames “.” (dot) and “..” (double
dot) that define, respectively, the working directory and the directory
above; example: ../doc/[Link]

link: a reference to some regular or special file, that may be
– symbolic or soft link: a textual reference to some other file (its absolute
pathname); deleting a soft link the referenced file remains unchanged
– hard link: a further reference to some file in the same file system, so that
a file can have multiple synonyms The file name is managed by the OS
as a “first hard link”. Deleting additional hard links do not affect the file
until removal of the first (alias of deleting the file)
Files hierarchy


All files are part of a unique tree in the OS, whose root
is indicated by “/” (slash, or root)

File systems are dynamically mounted (or unmounted)
as directories at any point of the “/” tree. For example,
the udev daemon continuously checks if a new
storage device has been plugged, and mounts it at a
conventional point. When the device is unplugged,
udev dismounts it.
/

A generic example of / in some standard Linux OS.

Figure by Saloni Gupta


a deeper sight on /
En excerpt of the mount command showing various file system
mounted in root subdirectories
sysfs on /sys type sysfs (rw,nosuid,nodev,.… sys virtual file system
proc on /proc type proc (rw,nosuid,nodev,.… sys virtual file system
udev on /dev type devtmpfs (rw,nosuid,..... network distributed virtual file
system
devpts on /dev/pts type devpts (rw,nosuid,.... virtual pseudo-terminals e.g.
in terminal windows
tmpfs on /run type tmpfs (rw,nosuid,noexec,.... ramdisk
/dev/sda2 on / type ext4 (rw,relatime,errors=remount.... hard disk 2nd
partition
fusectl on /sys/fs/fuse/connections type fusectl .... virtual fyle system
for mounting foreign fyle system types
/var/lib/snapd/snaps/canonical-livepatch_84.snap on .... new software
/dev/sda1 on /boot/efi type vfat .... hard disk boot partition
/dev/sdb1 on /media/renato/FLASH DRIVE type vfat (rw,nosuid.... usb
drive plugged in
real Ubuntu 18.04 Linux OS
File Descriptor

A unique convention is used for identifying all files, as well for using
them:
Any file (including special files) is identified by a FILE DESCRIPTOR
(non negative integer number)

opening, closing, reading, writing and related actions are carried out
by the same primitives. For example:
– writing on the terminal window
– writing on a regular file
– exchanging data with a process
– sending data to a machine in internet
– writing on memory shared by two processes
● are performed by the same write() system call
special files and device drivers

Accessing a special file is the way for activating a device driver in kernel
space.

For example:
– a process P calls write() to write on a line printer
– The syscall write() writes data on the special file /dev/lp
– this activates the lp driver which gets the data from P using a shared
memory and
– sends them to the printer
● Even hardware signals are detected/generated by read() / write()
system calls with file descriptors corresponding to /dev special files
connected to some suitable device driver
file descriptor and I/O
In the following drawing the first phases of activating an electric signal (e.g.
for switching on a led) are sketched
1) A suitable device driver is written and installed in the kernel (e.g. using
the Linux insmod command
2) A corresponding special file is written in the /dev directory
3) The process opens the device getting a file descriptor with the system
call open(pathname..)
4) The process writes the command for switching on the led with the
system call write(file descriptor..)
5) Both system calls carry out interaction between the process in user
space and the driver in kernel space
file descriptor and I/O

Switcher

Ready queue
el
Kern

System calls Interrupt Handlers I/O drivers

File table i-node table


Process Table
Buffer pool

U-Area File descriptor table U-Area

Stack Stack ledfd=open(/dev/bit,..) Stack


...
n=write(ledfd,..)
Data Data Data

Text Text Text

Process 1 Process 2 Process n


conclusions


POSIX manages two types of Inter Process Communication
(IPC) primitives:
– data
– events

Data IPC are supported by a unique concept named FILE

The second category of services:
events
are managed by the signal model (see Part III)
post scriptum
Some strange special files (pseudo devices), very useful
for debugging:
● /dev/null – accepts and discards all input written to it; provides
an end-of-file indication when read from
● /dev/zero – accepts and discards all input written to it; produces a
continuous stream of null characters (zero-value bytes) as output
when read from
● /dev/full – produces a continuous stream of null characters (zero-
value bytes) as output when read from, and generates an ENOSPC
("disk full") error when attempting to write to it.
● /dev/random – produces bytes generated by the kernel's
cryptographically secure pseudorandom number generator
© Wikipedia

You might also like