Chapter 5 - File management
Chapter 5 - File management
Contents:
Fundamental concepts on file
Data and meta data
Operations in file
Sequential Vs Consequential data
Content and structure of directories
File system techniques
Partitioning
Virtual file system
Memory-mapped files
Special purpose files systems: backup strategies
1
Fundamental concepts on file
Data and meta data:
Every file has a name and its data.
In addition, all operating systems associate other information with each file,
for example, the date and time the file was last modified and the file’s size.
We will call these extra items the file’s attributes.
Some people call them metadata.
The list of attributes varies considerably from system to system.
See table in next slide – the first four attributes relate to the file’s protection
and tell who may access it and who may not;
In some systems the user must present a password to access a file, in which
case the password must be one of the attributes.
The flags are bits or short fields that control or enable some specific
property.
Hidden files, for example, do not appear in listings of all the files.
2
Fundamental concepts on file, … Some possible file attributes.
3
Fundamental concepts on file, … File Operation
Operations in file:
Files exist to store information and allow it to be retrieved later.
Different systems provide different operations to allow storage
and retrieval.
The most common system calls relating to files are: Create ,
Open, Delete, Close, Read , Write, Append, Rename, Seek, get
attributes, set attributes, ... etc
Seek: For random-access files, a method is needed to specify from
where to take the data.
One common approach is a system call, seek, that repositions the file pointer
to a specific place in the file.
Get attributes: Processes often need to read file attributes to do their work.
Set attributes: Some of the attributes are user settable and can be
changed after the file has been created.; This system call makes that
possible. 4
Fundamental concepts on file , …..
Sequential Vs Consequential data
The simplest allocation scheme is to store each file as a contiguous run
of disk blocks.
Thus on a disk with 1-KB blocks, a 50-KB file would be allocated 50
consecutive blocks,
while with 2-KB blocks, it would be allocated 25 consecutive blocks.
We see an example of contiguous storage allocation in Fig. (a) next
slide;
Here the first 40 disk blocks are shown, starting with block 0 on the left.
Initially, the disk was empty; a file A, of length four blocks, was written
to disk starting at the beginning (block 0).
After that a three-block file, B, was written starting right after the end
of file A.
In the figure, a total of seven files are shown, each one starting at the
block following the end of the previous one.
Shading is used just to make it easier to tell the files apart.
5
Fundamental concepts on file , …..
6
Fundamental concepts on file , …..
Sequential Vs Consequential data, …
The second method for storing files is to keep each one as a
linked list of disk blocks known as sequential data.
The first word of each block is used as a pointer to the next
one and the rest of the block is for data.
No space is lost to disk fragmentation (except for internal
fragmentation in the last block).
Also, it is sufficient for the directory entry to merely store the
disk address of the first block; the rest can be found starting
there.
In both figures (next slide), we have two files; File A uses disk
blocks 4, 7, 2, 10, and 12, in that order, and file B uses disk
blocks 6, 3, 11, and 14, in that order too’.
7
Fundamental concepts on file , …..
Sequential data:
Using the table of Fig. in next slide, we can start with block 4 and follow the
chain all the way to the end.
The same can be done starting with block 6. Both chains are terminated with
a special marker (e.g., -1) that is not a valid block number.
Such a table in main memory is called a FAT (File Allocation Table). 8
Fundamental concepts on file , …..
Sequential Vs Consequential data, …
For this reason, nearly all modern file systems are organized in this manner.
The ability for users to create an arbitrary number of subdirectories provides
a powerful structuring tool for users to organize their work.
13
Content and structure of directories , …
Implementing Directories
Before a file can be read, it must be opened.
When a file is opened, the operating system uses the path name supplied by the
user to locate the directory entry on the disk.
In MS-DOS files have a 1–8 character base name and an optional extension of 1–
3 characters and in UNIX Version 7, file names were 1–14 characters, including
any extensions.
However, nearly all modern operating systems support longer, variable-length
file names. How can these be implemented?
The simplest approach is to set a limit on file-name length with 255 characters
reserved for each file name.
This approach is simple, but wastes a great deal of directory space, since few
files have such long names. For efficiency reasons, a different structure is
desirable. 14
Content and structure of directories , …
Implementing Directories, …
In this example
we have three
files,
project-
budget,
personnel, and
foo.
Each file name
is terminated
by a special
character
(usually 0),
which is
represented in
the figure by a
box with a
cross in it.
Two ways of handling long file names in a directory. (a) In-line. (b) In a heap. 15
File system techniques
Partitioning
File systems are stored on disks.
Most disks can be divided up into one or more partitions, with independent
file systems on each partition.
Sector 0 of the disk is called the MBR (Master Boot Record) and is used to
boot the computer.
The end of the MBR contains the partition table and this table gives the
starting and ending addresses of each partition.
One of the partitions in the table is marked as active; When the computer is
booted, the BIOS reads in and executes the MBR.
The first thing the MBR program does is locate the active partition, read in
its first block, which is called the boot block, and execute it.
The program in the boot block loads the operating system contained in that
partition.
16
File system techniques, …
Partitioning, …
Often the file system will contain some of the items shown in Fig. below.
The first one is the superblock that contains all the key parameters about the file
system and is read into memory when the computer is booted or the file system is
first touched.
Typical information in the superblock includes a magic number to identify the file-
system type, the number of blocks in the file system, and other key administrative
information.
17
File system techniques, …
Partitioning, …
Next might come information about free blocks in the file
system, for example in the form of a bitmap or a list of
pointers.
20
Position of the virtual file system.
File system techniques, …
Virtual file system, …
The calls coming from user processes are the standard POSIX calls, such as
open, read, write, seek, and so on.
Thus the VFS has an ‘‘upper’’ interface to user processes and it is the well-
known POSIX interface.
The VFS also has a ‘‘lower’’ interface to the concrete file systems, which is
labeled VFS interface in Fig. (last slide).
In fact, the original motivation for Sun to build the VFS was to support
remote file systems using the NFS (Network File System) protocol.
The VFS design is such that as long as the concrete file system supplies the
functions the VFS requires.
Internally, most VFS implementations are essentially object oriented, even
if they are written in C rather than C++.
21
Memory-mapped files
22
Memory-mapped files, … cont’
23
Memory-mapped files, … cont’
The following illustration shows how multiple processes can have
multiple and overlapping views to the same memory-mapped file at
the same time.
24
Backup strategies: Discussion
• What can you do if your file lost from a
storage media, or your storage media failed
and you took formatting ?
• Do you have any chance to get your lost
file?