L5: Introduction to file systems (v4a)
-
Upload
alejandro-calderon-mateos -
Category
Education
-
view
170 -
download
2
Transcript of L5: Introduction to file systems (v4a)
Lesson 5 (a)File systems
Operating System Design
Bachelor in Informatics Engineering
ARCOS Group
Universidad Carlos III de Madrid
Alejandro Calderón Mateos
Goals
ARCOS @ UC3M2
1. To know the abstractions within a operating System.
2. To use monitoring and fine-tuning tools.
3. To search the best way for better solutions.
Alejandro Calderón Mateos
Recommended books
ARCOS @ UC3M3
1. Carretero 2007:
1. Chapter 9
1. Tanenbaum 2006(en):
1. Chap.5
2. Stallings 2005:
1. Three part
3. Silberschatz 2006:
1. Chap. 10, 11 & 12
Base Additional
Alejandro Calderón Mateos
Remember…
ARCOS @ UC3M4
1. To study the associated theory.� Better study the bibliography readings because the slides
are not enough.
� To add questions with answers, and proper justification.
2. To review what in class is introduced.� To do the practical Linux task step-by-step.
3. To practice the knowledge and capacities.� To do the practical tasks as soon as possible.
� To do as much exercises as possible.
Alejandro Calderón Mateos
Overview
ARCOS @ UC3M5
1. Introduction
2. Abstractions used
3. System software
Alejandro Calderón Mateos
Overview
ARCOS @ UC3M6
1. Introduction
2. Abstractions used
3. System software
File systemDatabase
Storage devices
Applications
Alejandro Calderón Mateos
Introduction
� A photo editor (for example) has in memory its code and data.
� Each process works with its data (photo), and it might make new data (modified photo) as the result of this treatment.
7
Process
code
data
stack
code
data
stack
…
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Introduction
� A photo editor (for example) has in memory its code and data.
� Each process works with its data (photo), and it might make new data (modified photo) as the result of this treatment.
� It can be several process in memory, and the operating system distributes and manages the memory.
8
Process
code
data
stack
code
data
stack
…
Operating System
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Introduction
� The nowadays main memory is small, with word access and volatile.
� The data in main memory is not persistent (without electricity).
� The size only let us to store a fragment of data accessed by processor during a (small) period of time.
� It has random access to any word.
� Where data might be stored?
9
Process
code
data
stack
code
data
stack
…
Operating System
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Introduction
� Secondary memory has higher size, block access, and it is not volatile.
� Persistent data.
� To the process that create the data.
� Let us store more amount of data that main memory.
� Block based, it will need a block manager.
� Data is stored in secondary memory: hard disk, flash, etc.
10
Process
code
data
stack
code
data
stack
…
Operating System
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Introduction
� Part of the operating system is going to distributed and manages the S.M.
� The file system.
� The file system offers services for storing and retrieving data in a simple way.
� It hides the details of the S.M. using simple abstractions: files, directories, etc.
11
Process
code
data
stack
code
data
stack
…
Operating System
Res
erve
d by
O
S
…
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Introduction
� It is also possible that other applications manages the S.M.:
� Database Manager.
� The Operating System offers full access to the devices, the database manager manages it.
� It is possible a mix organization:
� File System plus Database manager
12
Process
code
data
stack
code
data
stack
…
Operating System
Res
erva
do
BB
DD
…
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Summary
� The SNIA propose an architecture for both:
� Storage Networking Industry Association
� http://www.snia.org
� The application get its data from storage devices by using file systems or database manager.
13
File systemDatabase
Storage devices
Applications
Sistemas Operativos - ARCOS
ARCOS @ UC3MSNIA: Storage Networking Industry Association (http://www.snia.org/)
Alejandro Calderón Mateos
Overview
ARCOS @ UC3M14
1. Introduction
2. Abstractions used
3. System software
File SytemDatabase
Storage Devices
Devices
Partitions/Volumes
File Systems
Files + Directories
Applications
Alejandro Calderón Mateos
Introduction
� files, directories, file systems, volumes, and devices
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Physical visionLogic vision
Log
ical
vis
ion
Phy
sica
l vi
sion
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Introduction
� Be careful with expression “file system” that is used for both, naming the management software, and for the file system’s disk structures.
Sistemas Operativos - ARCOS
ARCOS @ UC3M
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Alejandro Calderón Mateos
Devices
17
Sistemas Operativos - ARCOS
ARCOS @ UC3M
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Alejandro Calderón Mateos
Devices
� Hard disk
� SSD (solid state)
� Optical system
� Etc.
ARCOS @ UC3M18
Devices
Partitions/Volumes
File Systems
Directories
Files…
Alejandro Calderón Mateos
Devices
� To list the PCI devices:
� To list the USB devices:
19
acaldero@arcos:~/infodso/$ lspci00:00.0 Host bridge: Intel Corporation 82Q35 Express DRAM Controller (rev 02)00:01.0 PCI bridge: Intel Corporation 82Q35 Express PCI Express Root Port (rev 02)00:03.0 Communication controller: Intel Corporation 8 2Q35 Express MEI Controller (rev 02)
00:03.2 IDE interface: Intel Corporation 82Q35 Expre ss PT IDER Controller (rev 02)00:03.3 Serial controller: Intel Corporation 82Q35 E xpress Serial KT Controller (rev 02)...
acaldero@arcos:~/infodso/$ lsusbBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub...
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 003 Device 002: ID 1241:1166 Belkin MI-2150 Trust MouseBus 005 Device 002: ID 0c45:600d Microdia TwinkleCam U SB camera
ARCOS @ UC3M
Alejandro Calderón Mateos
Disks
� To list the disks/partitions:
� To list the block devices (disks/partitions):
20
acaldero@arcos:~/infodso/$ cat /proc/partitionsmajor minor #blocks name
8 0 2930266584 sda8 1 19998720 sda18 2 512000000 sda2
...
ARCOS @ UC3M
acaldero@arcos:~/infodso/$ lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 2,7T 0 disk ├─sda1 8:1 0 19,1G 0 part├─sda2 8:2 0 488,3G 0 part /├─sda3 8:3 0 2T 0 part /mnt/sda3└─sda4 8:4 0 196,7G 0 part
Alejandro Calderón Mateos
Devicesstackable services
� loopback device
� File as block device
� Example of working session:
1. [1] To make an empty initial file (~128 MB):dd if=/dev/zero of= /tmp/sf-01 bs=1M count=128
2. Assign the file to a loopback device:sudo losetup /dev/loop1 /tmp/sf-01
3. Working with the device… /dev/loop1
4. Unassign the device:losetup –d /dev/loop1
ARCOS @ UC3M21
Devices
…
Partitions/Volumes
File Systems
Directories
Files
Alejandro Calderón Mateos
Devicesstackable services
� md device
� Bonding devices as a device
� Example of working session :
1. [1] To make a mirror md device:mdadm --create --verbose /dev/md5 --level=1
--raid-devices=2 /dev/loop1 /dev/loop2
2. Working with the device:… /dev/md5
3. To stop the md device:mdadm --stop /dev/md5
4. To start the md device:
mdadm --assemble /dev/md5 /dev/loop1 /dev/loop2
ARCOS @ UC3M22
Dev.
…
Dev.
Partitions/Volumes
File Systems
Directories
Files
Alejandro Calderón Mateos
Partitions/volumes
23
Sistemas Operativos - ARCOS
ARCOS @ UC3M
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Alejandro Calderón Mateos
� A partition is a portion of disk with its own identity, and can be used by
the operating system as an independent logical entity.
� A file system container (or data management system).
Partitions/volumes
24
Part
ition
tabl
e Primary partition 1(active)
Primary partition 2(non-active)
First sector Last sector
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Partitions/volumes: attributes
� Typical attributes of a partition:� Kind of: primary, secondary, logic unit, bootable, etc.
� Size: partition start and end (or full size)
� Inner file system: linux, linux swap, vfat, etc.
� Identification: number of partition (order or UUID)
25
Partitiontable Partition Partition
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Partitions/volumes
� To list the disks/partitions:
26 ARCOS @ UC3M
acaldero@arcos:~/infodso/$ parted -l
Modelo: ATA ST3000DM001-1CH1 (scsi)Disco /dev/sda: 3001GBTamaño de sector (lógico/físico): 512B/4096BTabla de particiones. gpt
Numero Inicio Fin Tamaño Sistema de archivos Nombre Banderas1 1049kB 20,5GB 20,5GB bios_grub2 20,5GB 545GB 524GB ext43 545GB 2789GB 2245GB ntfs4 2789GB 3001GB 211GB ntfs msftdata
…
acaldero@arcos:~/infodso/$ blkid
/dev/sda4: LABEL="w10" UUID="0A568AE42B85AEDC" TYPE="ntfs" /dev/sda2: UUID="8de35b39-e3e8-43d8-a5b1-91cf76ca2e89" TYPE="ext4" /dev/sda3: UUID="2CB158D64D7CC0DD" TYPE="ntfs" …
Alejandro Calderón Mateos
Partitions/volumes traditional PC partition system
� The boot sectors contains the partition table.
� Primary partition, and secondary partition (with logic units)
� Old and limited:
� Only 4 partition (primaries + secondaries)
� In order to change the partition size, data has to be backup and restored
27
First sector
Boo
tse
ctor
Primarypartition 1 (active)
Primarypartition 2
Fre
e sp
ace
Last sector
Extended partition
Logicalpartition
1
Logicalpartition
2
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Partitions/volumesvolumes-based system
� Logical volumes (~old partitions)over a volume group formed by physical volumes.
� Modern and flexible system:
� Without limit, dynamic change, multiple disk usage, etc.
28
http://www.howtoforge.com/linux_lvm
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Partitions/volumesvolumes-based system
� To create a physical volume, a volume group, and a logical one:
1. # pvcreate /dev/sdb1
2. # vgcreate vol_infoso /dev/sdb1
3. # lvcreate –L100M –nweb vol_infoso
4. … /dev/vol_infoso/web
29
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
File systems
30 ARCOS @ UC3M
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Alejandro Calderón Mateos
Sectors
� The block store device is divided into sectors, heads, and cylinders.
31
Firstsector
Lastsector
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Blocks
� Block: logical group of disk sectors (2n sectors)
� It is the minimal transfer unit used by the O.S.
� To optimize the device I/O transfer efficiency.
� Users can define the block size to be used when the file system is created, otherwise the default selected by O.S. is used.
32
First block Last block
Firstsector
Lastsector
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Blocks
� Block: logical group of disk sectors (2n sectors)
� It is the minimal transfer unit used by the O.S.
� To optimize the device I/O transfer efficiency.
� Users can define the block size to be used when the file system is created, otherwise the default selected by O.S. is used.
33
Sistemas Operativos - ARCOS
ARCOS @ UC3M
First block Last block
Alejandro Calderón Mateos
Block size
� The block size selection process tries to balance:
� Bandwith: large block size improve the bandwidth
� Space usage: lower block size improve the inner fragmentation (better space usage)
34
Tamaño de Bloque
ancho de banda
uso del disco
Anc
ho d
e B
anda
(K
byte
s/se
c)
Uso
del
Esp
acio
de
Dis
co
0
50
100
500
800
256 512 1K 2K 4K 8K 16K 32K
0
100 %
25
50
75
Sistemas operativos: una visión aplicada
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
File systems
� A file system could manage the information inside the storage device in a structured format for the O.S:
� This format has the O.S. metainformation and user data.
35
First block Last block
Metadata data
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
File system: typical attributes
� Used space management: total number of blocks, block size, number of i-nodes, metadata size, etc.
� Free space management: free i-node/block identification.
� Entry management: for each entry (file or directory) a metadata space is reserved in order to describe it:
� General attributes: dates, permissions, owner identification, etc.
� Used block attributes: blocks used by this entry for storing its data.
� Root directory reference.
36
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Metadata
Boo
tblo
ck
Sup
er-b
lock
Res
ourc
eas
sign
men
t 000
001
002
003
004
i-nodes
data
Alejandro Calderón Mateos
File system
� To show the file system metadata:
37 ARCOS @ UC3M
acaldero@arcos:~/infodso/$ dumpe2fs /dev/sda2
dumpe2fs 1.42.9 (4-Feb-2014)Filesystem volume name: <none>Last mounted on: /Filesystem UUID: 8de35b39-e3e8-43d8-a5b1-91cf76ca2e89Filesystem magic number: 0xEF53Filesystem revision #: 1 (dynamic)Filesystem features: has_journal ext_attr resize_inode dir_index filetypeneeds_recovery extent flex_bg sparse_super large_file huge_file uninit_bgdir_nlink extra_isizeFilesystem flags: signed_directory_hashDefault mount options: user_xattr aclFilesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 32006144Block count: 128000000Reserved block count: 6400000Free blocks: 100051682…
Alejandro Calderón Mateos
File system: operations
� File system operations:� To create
� To mount
� To unmount
38
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Part
ition
tabl
e
Met
adat
a(s
wap
)First sector Last sector
data (swap) Metadata(ext2)
data (ext2)
� To write into disk the data structures needed for the management:
� # mkswap -c /dev/hda1 20800
� # mkfs.ext2 -c /dev/hda2 -b 8196 123100
Alejandro Calderón Mateos
File system: operations
� File system operations:� To create
� To mount
� To unmount
39
umount /usr
/
/lib /bin /usr
/
/d1 /d2 /d3
/d3/f2/d3/f1
/
/lib /bin /usr
/usr/d1 /usr/d3
/usr/d3/f2/usr/d3/f1
Volumen raiz(/dev/hd0)
Volumen sin montar(/dev/hd1)
mount /dev/hd1 /usr
Volumen montado
Sistemas operativos: una visión aplicada
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
File systems
� Great number of file systems
40http://en.wikipedia.org/wiki/List_of_file_systems
� For storage devices:– minix (Minix)
– ext2 (Linux)
– ext3 (Linux)
– ufs (BSD)
– fat (DOS)
– vfat (win 95)
– hpfs (OS/2)
– hfs (Mac OS)
– ntfs (winNT/2K/XP)
– ...
� Special ones:– procfs (/proc)
– devFS (/dev)
– umsdos(Unix over DOS)
– …
� Network file systems:
– NFS
– CODA
– SMBFS
– NCPFS (Novell)
– …
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Alternative file systemzfs file system (Sun now Oracle)
� It simplifies the usage of devices, volumes, and file systems by the integration of all into a single extend file system:� zpool create arcos /home/ocean/disk1
� zfs create arcos/alex
ARCOS @ UC3M41
Alejandro Calderón Mateos
Example: volumes + file system
� To use file as block devices:
1. dd if=/dev/zero of=/tmp/disk1 bs=1G count=1
2. losetup /dev/loop2 /tmp/disk1
� To create a physical volume, a volume group, and a logical one:
1. pvcreate /dev/loop2
2. vgcreate vol_dso /dev/loop2
3. lvcreate –L100M –ntest vol_dso
� To create a file sytem, and mount it in a directory:
1. mkfs –t ext3 /dev/vol_dso/test
2. mount /dev/vol_dso/test /mnt
3. df –mh
42
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Example: volumes + file system
� To change the file system size:
1. umount /mnt
2. fsck –f /dev/vol_dso/test
3. resize2fs /dev/vol_dso/test 50M
� To change the volume size:
1. lvreduce -L -50m /dev/vol_dso/test
2. mount /dev/vol_dso/test /mnt
3. df –mh
43
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Example: integrated file system (btrfs)
� To use file as block devices:
1. dd if=/dev/zero of=/tmp/disk3 bs=1G count=1
2. losetup /dev/loop3 /tmp/disk3
3. dd if=/dev/zero of=/tmp/disk3 bs=1G count=1
4. losetup /dev/loop4 /tmp/disk3
� To create a btrfs volume/filesytem and mount it:
1. mkfs.btrfs /dev/loop3
2. mount /dev/loop3 /btrfs
3. btrfs filesystem show /dev/loop3
44
Sistemas Operativos - ARCOS
ARCOS @ UC3Mhttp://www.slideshare.net/anu-bhaskar/introducing-btrfs
Alejandro Calderón Mateos
Example: integrated file system (btrfs)
� To change the filesystem size:
1. btrfs filesystem resize -10m /btrfs/
2. btrfs filesystem show /dev/loop3
� To add a new device space into the filesystem:
1. btrfs device add /dev/loop4 /btrfs
2. btrfs filesystem balance /btrfs/
3. btrfs filesystem show /dev/loop3
� To create a volume (~a directory that can be mounted as root dir.):
1. cd /btrfs/
2. btrfs subvolume create vol_infodso
3. btrfs subvolume list /btrfs/
45
Sistemas Operativos - ARCOS
ARCOS @ UC3Mhttp://www.funtoo.org/BTRFS_Fun
Alejandro Calderón Mateos
Files
46
Sistemas Operativos - ARCOS
ARCOS @ UC3M
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Alejandro Calderón Mateos
Files
� Set of related informationthat has been defined by its creator.
� Different types of information:
ARCOS @ UC3M47
Alejandro Calderón Mateos
Files
� The content is represented as a sequence of bytes:
ARCOS @ UC3M48
R/W position
Alejandro Calderón Mateos
Files
� It is translated into binary, and stored as an array (or sequence) of bytes:
ARCOS @ UC3M49
R/W position
Alejandro Calderón Mateos
Files: interface
� Generic interface to access to information:� descriptor ← open (name, flags, mode)
� close (descriptor)
� read (descriptor, address, size)
� write (descriptor, address, size)
� lseek (descriptor, offset, reference_of_offset)
� ioctl (descriptor, request, address_of_parameters)
ARCOS @ UC3M50
R/W position
Alejandro Calderón Mateos
Files: POSIX interface
51
#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <fcntl.h>
int main ( int argc, char *argv[] ){int fd1 ;char str1[10] ;int nb ;
fd1 = open ("/tmp/txt1",O_CREAT|O_RDWR, S_IRWXU);
if ( -1 == fd1) {perror("open:"); exit(-1);
}
strcpy(str1,"hola");nb = write (fd1,str1,strlen(str1));printf(" bytes escritos = %d\n",nb);
close (fd1);return (0) ;
}
write#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <fcntl.h>
int main ( int argc, char *argv[] ){int fd1 ;char str1[10] ;int nb, i ;
fd1 = open ("/tmp/txt1", O_RDONLY);if ( -1 == fd1) {
perror("open:"); exit(-1);
}
i=0;do {
nb = read (fd1,&(str1[i]),1); i++;} while (nb != 0) ;str1[i] = '\0';printf(“%s\n",str1);
close (fd1);return (0);
}
read
ARCOS @ UC3M
Alejandro Calderón Mateos
� File information:
Files
ARCOS @ UC3M52
� data
� Information that is storedby the file.
� Metadata
� Information aboutthe file.
� Several attributes
Alejandro Calderón Mateos
� File information:
Files
ARCOS @ UC3M53
� data
� Information that is storedby the file.
� Metadata
� Information aboutthe file.
� Several attributes
Alejandro Calderón Mateos
� File information:
Files
ARCOS @ UC3M54
� data
� Information that is storedby the file.
� Metadata
� Information aboutthe file.
� Several attributes:
� Name and type
� Disk blocks, and size
� Protection
� Dates (creation, …)
� Etc.
Alejandro Calderón Mateos
Directories
55
Sistemas Operativos - ARCOS
ARCOS @ UC3M
File SytemDatabase
Storage Devices
Applications
Devices
Partitions/volumes
File Systems
Files + Directories
Alejandro Calderón Mateos
Directories
� Data structure that let us to group a number of files by using some user criteria.
ARCOS @ UC3M56
Alejandro Calderón Mateos
Directories
� To organize and to provide information about the structure of the file systems:
57
/
foto.jpg x.exe nota.txt
alex ana
/
boot lib home
alex ana
/
boot lib home users
� One level� 1 dir with n files
� 1 file with 1 dir.
� Tree-based� 1 dir with n entries
� 1 entry with 1 dir.
� Acyclic graph� 1 dir. with n entries
� 1 entry with n dir.
pic.jpg x.exe
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Directories
� To organize and to provide information about the structure of the file systems:
58
/
foto.jpg x.exe nota.txt
alex ana
/
boot lib home
alex ana
/
boot lib home users
� One level� 1 dir with n files
� 1 file with 1 dir.
� Tree-based� 1 dir with n entries
� 1 entry with 1 dir.
� Acyclic graph� 1 dir. with n entries
� 1 entry with n dir.
pic.jpg x.exe
Sistemas Operativos - ARCOS
ARCOS @ UC3M
It is needed to track the referencesto the entry (to remove it):• Linked list• Reference counter
Alejandro Calderón Mateos
Directories
� Hierarchy names for the identification.
� Kinds of directory naming:
� Absolute path: name specification relative to the root directory. (/ in LINUX, \ in Windows)
� Relative path: name specification relative to one directory (other than root).
� Example: (being in /users/) alex/correo.txt
� Relative ones to the working/actual directory: based on the current directory where the user is (working directory)
� Special directories:
� Current directory or working directory: .
� Parent directory: ..
� User home directory: $HOME
ARCOS @ UC3M59
alex ana
/
boot lib home users
Alejandro Calderón Mateos
Directories: interface
� Generic interface to work with directories:� mkdir (name,mode)
� rmdir (name)
� chdir (name)
� getcwd (name, name_size)
� descriptor ← opendir (name)
� closedir (descriptor)
� entry_struct ← readdir (descriptor)
� rewindir (descriptor)
� unlink (name)
� rename (old_name, new_name)
60
Sistemas Operativos - ARCOS
alex ana
/
boot lib home users
ARCOS @ UC3M
Alejandro Calderón Mateos
Directories: POSIX interface
61
#include <unistd.h>#include <sys/types.h>#include <dirent.h>#include <stdio.h>
int main ( int argc, char *argv[] ){DIR *dir1 ;struct dirent *dp ;char nombre[256] ; int ret ;
ret = chdir ("/tmp/") ;if (ret < 0) exit(-1) ;
getcwd (nombre, 256);printf("%s\n",nombre);
dir1 = opendir (nombre);if (NULL == dir1) exit(-1) ;while ( (dp = readdir (dir1)) != NULL) {
printf(“%/%s\n",nombre,dp->d_name);}closedir (dir1);
return (0) ;}
listing of /tmp Sistemas Operativos - ARCOS
To change the working directory
To print the current working directory
To open a directory working session
To read the directory entries and to print thename of each entry
To close the directory work session
ARCOS @ UC3M
Alejandro Calderón Mateos
� Directory information:
� data
� “special file” that contains the entries list.
� Metadata
� Information about the directory.
� Different attributes about the directory
Directories
ARCOS @ UC3M62
files | directory
Alejandro Calderón Mateos
� Directory information:
� data
� “special file” that contains the entries list.
� Metadata
� Information about the directory.
� Different attributes about the directory:
Directories
ARCOS @ UC3M63
files | directory
o Name and type
o Disk blocks, and size
o Protection
o Dates (creation, …)
o Etc.
Alejandro Calderón Mateos
Overview
ARCOS @ UC3M64
1. Introduction
2. Abstractions used
3. System softwareBenchmarks
Consistency
Reliability
File SytemDatabase
Storage Devices
Devices
Partitions/Volumes
File Systems
Files + Directories
Applications
Alejandro Calderón Mateos
System software
65 ARCOS @ UC3M
Alejandro Calderón Mateos
Benchmarks
Consistency
Reliability
File SytemDatabase
Storage Devices
Devices
Partitions/Volumes
File Systems
Files + Directories
Applications
Alejandro Calderón Mateos
Benchmarking
� Sometimes it is needed to know the best file system for a certain work (with some specific workload).
� Solution:� To use software (benchmarks) that let us to measure the performace
of the file system.
� There are designed to measure several aspects: latency, bandwith, number of files handled per unit of time, etc.
� Two aspects to be evaluated:
� Metadata management.
� Data management.
ARCOS @ UC3M66
Alejandro Calderón Mateos
Benchmarkingdata
67 http://www.phoronix.com/scan.php?page=article&item=ubuntu_1204_fs&num=1 ARCOS @ UC3M
� Examples:
� iozone, postmark, etc.
Alejandro Calderón Mateos
BenchmarkingMetadata
68 ARCOS @ UC3M
� Examples:
� fdtree, mdtest, etc.
http://linuxgazette.net/122/piszcz.html
http://www.linux-mag.com/id/7682/
Alejandro Calderón Mateos
Increase performance
� To Defrag:� To reorder the file blocks in order to place them in order
of creation, or in the order that are loaded into memory the last time, etc.
� E.g.: defrag in Windows
� E.g.: defragfs in Linux
69 ARCOS @ UC3M
Alejandro Calderón Mateos
Consistency in the file system
� Software failures might trigger inconsistency in the data (and metadata) stored.
� Solution:� To design some tools to check the file system in order to detect the
inconsistency, and to repair the found errors.
� Two aspect to be checked:
� To check that the physical structure of the file system is correct.
� To check that the logical structureof the file system is correct.
ARCOS @ UC3M70
Alejandro Calderón Mateos
Consistency in the file systemphysical structure
� Controller logic: � To test/stress the disk-controller
� E.g.: S.M.A.R.T.
71
� Disk surface:
� Disk block are read and written oneby one to check disk surfaceproblems
� E.g.: if what is read is different to whatis written then error on surface
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Consistency in the file systemlogical structure
� Disk structures: � To review disk metadata in order to check that are valid for partition,
directories, and file stored in.
� E.g.: fsck in Linux or scandisk in Windows
72
Sistemas Operativos - ARCOS
ARCOS @ UC3M
Alejandro Calderón Mateos
Reliability in a file system
� Hardware and software failures may cause fail in a volume(information may be lost after failure)
� Solutions:
� To detect it:
� E.g.: Controler that deal with failing sectors
� Redundancy:
� Redundant Array of Independent/Inexpensive Disks
� Backup:
� Full Backup, incremental or diferential
� On disk, tapes, or remote backup
ARCOS @ UC3M73
Alejandro Calderón Mateos
Reliability in a file system
� Hardware and software failures may cause fail in a volume(information may be lost after failure)
� Solutions:
� To detect it:
� E.g.: Controler that deal with failing sectors
� Redundancy:
� Redundant Array of Independent/Inexpensive Disks
� Backup:
� Full Backup, incremental or diferential
� On disk, tapes, or remote backup
ARCOS @ UC3M74
Alejandro Calderón Mateos
Redundancywith replication
ARCOS @ UC3M75 Sistemas operativos: una visión aplicada
A
B
B
A
Alejandro Calderón Mateos
Redundancywith parity
ARCOS @ UC3M76 Sistemas operativos: una visión aplicada
b0Parity 012b1 b2
Disk 0 Disk 1 Disk 2 Disk 3
b3 …
Alejandro Calderón Mateos
Reliability in a file system
� Hardware and software failures may cause fail in a volume(information may be lost after failure)
� Solutions:
� To detect it:
� E.g.: Controler that deal with failing sectors
� Redundancy:
� Redundant Array of Independent/Inexpensive Disks
� Backup:
� Full Backup, incremental or diferential
� On disk, tapes, or remote backup
ARCOS @ UC3M77
Alejandro Calderón Mateos
BackupWhere?
� Place:
� Far from the main system to protect
� Protection against the water, fire, etc.
� Fireproof cabinets
� Media:
� Hard disk
� Adv.: capacity and price, Dis.: somehow weak
� Tape
� Adv.: capacity and price, Dis.: slow
ARCOS @ UC3M78
Alejandro Calderón Mateos
BackupHow?
� Full backup:A copy of all file system information.
� Differential backup:It has all files (and directories) that has been updated since the last full backup.
� Incremental backup: It has all the files (and directories) that has been updated since the last full or differential backup.
ARCOS @ UC3M79
Alejandro Calderón Mateos
BackupWhen?
� Off-line:
� The backup is done while the system is not used (e.g.: at midnight).
� On-line:
� The backup is done while the system is been used.
� It is needed techniques to avoid consistency problems:
� Snapshotsread-only copy of the file system
� Copy-on-writeupdates after the snapshot are done in a copy of the original block
ARCOS @ UC3M80
Alejandro Calderón Mateos
BackupApple Time Machine, Microsoft vault, etc.
ARCOS @ UC3M81
http://www.reghardware.com/2007/11/08/review_leopard_pt2/page2.html
http://www.genbeta.com/sistemas-operativos/primeras-imagenes-de-history-vault-el-time-machine-de-windows-8
Lesson 5 (a)File systems
Operating System Design
Bachelor in Informatics Engineering
ARCOS Group
Universidad Carlos III de Madrid