08 Filemanagement
08 Filemanagement
File Management
8.1 Motivation
low cost
and allow
reading and writing access.
Following, we will focus on disk drives as main medium for file storage
DVD and CD-ROM have a similar structure
SSD also have a similar structure, but certain specialties have to be
obeyed (addressed separately in the lecture on I/O)
Only tapes are fundamentally different, since they allow only sequential
access due to their one-dimensional linear structure
User
command Free space
(e.g. read I/O management
file)
access File
control operations
allocate
Example:
1 2 1 1 2 1 512 1
H. Parzyjegla, TU Berlin, WS2014/15
8-5
Blocks and records
Blocks are the elementary units of a disk (physical units), while records
are the elementary units of a file (logical units).
If records are required to be of arbitrary length, we need a flexible
assignment of records to blocks.
For constant record length the ratio of block length to record length is
called blocking factor f.
record 1 record 2
f=1
block 1 block 2
S1 S2 S3 S4 S5 S6 S7 S8
f=4
block 1 block 2
f = 1/2
block 1 block 2
H. Parzyjegla, TU Berlin, WS2014/15
8-6
Blocks and records
constant S1 S2 S3 S4
unspecified S1 S2 S3 S4 S5
Blocks (Sectors)
tracks volume label
cylinder
allocation information
file
table of contents
file
file
Identifier of volume
Date of activation
Capacity
Physical layout
Bad blocks
Link to allocation information (or allocation information itself)
Link to table of contents (or table of contents itself)
Vector- or list-based
contiguous or scattered
Example:
Vector (bit map) for allocated and free blocks, separate for each
area (minimizing head movements)
1100010110100000
area,
e.g. cylinder
1100000000000111
1100111100011000
address
(block no.) length
3 16 1 2 3 4 5 6 7 8
22 9 9 10 11 12 13 14 15 16
32 10 17 18 19 20 21 22 23 24
44 9 25 26 27 28 29 30 31 32
57 8 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
The file directory contains the list of the descriptions of all files and is stored
on the volume.
File description
constant or
variable long
For large volumes and many files the flat structure is awkward and
unhandy (for the human user as well as for accessing programs).
H. Parzyjegla, TU Berlin, WS2014/15
8-12
File directory
Structured directories
Entry into
file directory A B E Possibly more blocks
file
B
R S A D T
file
file file E.T
A.R E.A
X Y X Y
file name
organization
creation date
owner
access rights
date of last access
date of last change (write access)
position of file (or its parts)
size
....
We distinguish:
begin of file r4
r1 r2 r3 r4 r5 r6 r7 r8
old new
position of pointer
H. Parzyjegla, TU Berlin, WS2014/15
8-17
Sequential file organization
Writing to a file is usually only possible at the end of the file.
Only if a record can be replaced by another record of the same
length, writing within the file is possible.
r1 r2 r3 r4 r5 r6 r7 r8 r9 append
old new
EOF
Non-contiguous allocation
The file occupies arbitrary blocks on the disk.
The ordering of the blocks can be achieved in two different ways:
Linked allocation (chaining)
direct (integrated) chaining of blocks
separate chaining in a table (e.g. FAT in MS-DOS / Windows)
Indexed allocation
r4 r5 r6
r7 r8 r9
r1 r2 r3
r4 r5 r6
r7 r8 r9
235 129
298 EOF
567 298
File Allocation Table
ki ri
record
key
The address (block- or track number) is calculated based on the key
value.
V r r r r r r
V
V r r
ai = f (ki ) V r r r r
blocks or
V r r tracks
24 13 22 19
16 49 18 15 data
92 31 blocks
27
g g max = 3
after extension b = 2 max = 8
g 2 2 2 3 2 2 2 3 pointer vector
pointer
24 13 22 19 15
16 49 18 27 31 data
92 43 blocks
r4 r7 r 12 r 15 r 18
r 1 r 2 r 3 r 4 r 5 r 6 r 7 r 8 r 9 r 10 r 11 r 12 r 13 r 14 r 15 r 16 r 17 r 18
r 4.2 r 12.3
r4 r7 r 12 r 15 r 18
r 1 r 2 r 3 r 4 r 5 r 6 r 7 r 8 r 9 r 10 r 11 r 12 r 13 r 14 r 15 r 16 r 17 r 18
19 31 71
13 14 17 19 23 24 29 31 37 41 43 71 73 79
31
16 19 41 71
13 14 16 17 19 23 24 29 31 37 41 43 71 73 79
B*-tree after deletion of record with key 71 (node merger at leaf level)
31
16 19 41
13 14 16 17 19 23 24 29 31 37 41 43 73 79
102
104
106
108
1010
Operations on files
Create
open
read
write
reset
lock
..
close
read parameter
Delete
The thread or process control block contains references to the file control
blocks of files that this process has currently opened.
FCB‘
common part
TCB2
FCB FCB
Unified
Almost all system objects are represented as files and accessed by
using the file interface (files, catalogues, communication objects,
devices).
syntactically equal treatment of all types, semantically as far as
possible.
therefore programs are independent of the object type
Simple
only few, but flexible file operations
simple file structure
byte string
arbitrarily addressable
content without property and structure
form and content completely defined by user
maximum file size depending on system (typically GB or TB range,
originally GB range)
limited to one logical volume
protection by access rights
r read
w write
e execute
specifically for user, group, world
at the root-directory.
If a path starts with a character other than “/”, it is a relative path
Each directory starts with an entry ".", that indicates the I-node of
the current directory.
The second entry is ".." and refers to the parent directory.
The path name is being resolved from left to right and at every
resolution the respective name is searched in the directory.
As long as it is not the last name of the path, it must be a
directory. If not, the search is aborted with an error message.
Example:
With symlink("/usr/src/uts/sys","/usr/include/sys")
and symlink("/usr/include/realfile.h","/usr/src/uts/sys/testfile.h")
we have three path names to the same file:
/usr/src/uts/sys/testfile.h
/usr/include/sys/testfile.h
/
/usr/include/realfile.h
usr
src include
sys
inode.h testfile.h
H. Parzyjegla, TU Berlin, WS2014/15
8-43
Hard and Symbolic Links
A symbolic link (soft link) is a file, that contains a path name for
a directory or a file.
Symbolic Links will be evaluated at each access.
If the file is deleted, the path name does no longer refer to an
existing file, e.g. it gets invalid.
Symbolic links to files or directories can be created even if the file or
directory does not yet exist.
bin
mount-point
etc usr
cc sh getty passwd
... ...
boundary 8-46
H. Parzyjegla, TU Berlin, WS2014/15
Buffering
Disk blocks are buffered in main memory. For fast access a hash table is
used. Blocks with identical hash value are kept in a linked list.
The management of the buffer blocks (replacement strategy) follows the
LRU principle. A free list is maintained, in which the free blocks are
double linked in a circular way. Free blocks are removed at the head and
inserted at the tail.
free
locked
:
read(3,..)
:
open files file table I-node- Data blocks
(process specif.) (system wide) Table
(in buffer)
user address space system address space disk
Windows NT supports older file systems like the FAT system of DOS
and Windows95 or HPFS of OS/2.
The usual one is NTFS (NT File System) with following properties:
Fault tolerance
Transaction concept (all-or-nothing)
Automatic restart at system crash during operation.
Support of RAID-1 (mirroring) and RAID-5 (block-level-parity, server
only)
Security
Discretionary access control
Support of large files and large disks
Unicode-Names
Posix support
Encryption
Compression
partition
Master File Table System File Area
boot
Files
sector
I/O Manager
Log the transaction
Read/write a
Log File NTFS Driver
mirrored or
Service
Read/write striped volume
the file Fault Tolerant
Flush the Driver
Write the Read/write
log file cache the disk
Disk Driver
Virtual Memory
Manager
Process
file object
file object
master
handle file table
table
data
attribute
NTFS data structures
(use to manage the
user defined
on-disk structure)
attribute
stream file
control control
blocks block
Features:
Storage pools
End-to-end data integrity by checksums
Copy on write transactional model
Caching
Snapshots
Deduplication
Encryption
…many more
Three layers:
ZFS POSIX layer (ZPL)
Issues transactions atomically
Changes are reverted if it does not complete atomically
Offers the classical POSIX interface to the user
RAM cache
Caches read accesses
Can use large amounts of RAM in an efficient manner