0% found this document useful (0 votes)
11 views

Chapter 5 - File management

File management in operating system

Uploaded by

Enstain Ford
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)
11 views

Chapter 5 - File management

File management in operating system

Uploaded by

Enstain Ford
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
You are on page 1/ 25

Chapter 5: File Systems

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, …

Linked-list (sequential) allocation using a file-allocation table in main memory. 9


Fundamental concepts on file , …..
Sequential Vs Consequential data, …
 The primary disadvantage of the second method is that the
entire table must be in memory all the time to make it work.
 With a 1-TB disk and a 1-KB block size, the table needs 1 billion
entries, one for each of the 1 billion disk blocks.
 For speed in lookup, they should be 4 bytes.
 Thus the table will take up 3 GB or 2.4 GB of main memory all
the time, depending on whether the system is optimized for
space or time. Not wildly practical.
 Clearly the FAT idea does not scale well to large disks.
 But, it was the original MS-DOS file system and is still fully
supported by all versions of Windows though.
10
Fundamental concepts on file , …..

Content and structure of directories


 The simplest form of directory system is having one directory
containing all the files.
 Sometimes it is called the root directory .
 The advantages of this scheme are its simplicity and the ability to
locate files quickly—there is only one place to look, after all.

A single-level directory system containing four files.


11
Content and structure of directories , …
Hierarchical Directory Systems
 For modern users with thousands of files, it would be difficult
to find anything if all files were in a single directory.
 What is needed is a hierarchy (i.e., a tree of directories).
 With this approach, there can be as many directories as are
needed to group the files in natural ways.
 Furthermore, if multiple users share a common file server, as is
the case on many company networks, each user can have a
private root directory for his or her own hierarchy.
 This approach is shown in Fig. (next slide);
 Here, the directories A, B, and C contained in the root directory
each belong to a different user, two of whom have created
subdirectories for projects they are working on.
12
Content and structure of directories , …
 Hierarchical Directory Systems, ….

 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.

 This might be followed by the i-nodes, an array of data


structures, one per file, telling all about the file.

 Finally, the remainder of the disk contains all the other


directories and files.
18
File system techniques, …
Virtual file system
 Many different file systems are in use—often on the same computer—
even for the same operating system.
 A Windows system may have a main NTFS file system, but also a
legacy FAT -32 or FAT -16 drive or partition that contains old, but
still needed, data, and from time to time a flash drive, an old CD-ROM
or a DVD (each with its own unique file system) may be required as
well.
 Windows handles these disparate file systems by identifying each one
with a different drive letter, as in C:, D:, etc.
 When a process opens a file, the drive letter is explicitly or implicitly
present so Windows knows which file system to pass the request to.
 There is no attempt to integrate heterogeneous file systems into a
unified whole.
 In contrast, all modern UNIX systems make a very serious attempt to
integrate multiple file systems into a single structure. 19
File system techniques, …
Virtual file system, …
 Most UNIX systems have used the concept of a VFS (virtual file system) to
try to integrate multiple file systems into an orderly structure.
 The key idea is to abstract out that part of the file system that is common to
all file systems and put that code in a separate layer that calls the
underlying concrete file systems to actually manage the data.

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?

----------------- > End!


25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy