Вы находитесь на странице: 1из 11

Introduction Files Introduction Files

Information used by a computer system may be stored The operating system provides a mapping between
on a variety of storage mediums(magnetic disks, mag- the abstract logical units of storage, that is a file, and
netic tapes, optical disks, etc). the physical storage device.

A file system provides a uniform logical view of this


information. Ass2

Doom

stars

1 2

Introduction Files Files Files

A layered approach is often used in implementing this A file is a named collection of related information.
mapping. The layers are:
Files consists of a sequence of bits, bytes, lines, or
lower levels — physical properties of the storage records.
device,
The information in a file is generally defined by its cre-
ator.
intermediate levels — map the logical file con-
cepts into physical device properties, and

upper levels — symbolic file names and logical


properties of files.

Files are usually stored on non-volatile devices so the


information is not lost when the power goes down or
the system is reset.
3 4
File Types Files File Attributes Files

There is numerous types of files. These include: Typically the operating system will keep track of the
text, following attributes for each file:

source, name,

object, type,

executable, location,

binary, size,

compressed, protection,

graphics image, temporal information about creation and use.

data base, etc...

A critical decision in the design of an operating system


is too what extent does the operating systems support
typed files.
5 6

Routines Files File Table Files

A file is an abstract data type. The operating system Rather than the operating system constantly search-
will provide a set of routines to uniformly view/manipulate ing the directory for each operation that is performed
this data type. A basic set of routines includes:
on file. Files are generally opened and information
creation, about the file is stored in the open file table. Then all
file operation are performed using an index to this ta-
writing,
ble. The process will close the file once the interaction
reading, with the file is complete.
repositioning,

deletion,

truncating,

appending, and

renaming.

From these basic operations other operations such as


copying or printing may be performed.
7 8
File Table Files Types Files

The information in the open file table includes : Types are supported to a variety of extents by different
operating systems.

file pointer,
MS-DOS — recognises file extensions.

file open count, and


Macintosh — has file types like “text” or “pic”. Also
files have their creator program as part of its at-
disk location of the file.
tributes.

Example. Unix has a per-process open file table and


UNIX — Does not really support file types. Al-
a system wide open file table.
though, some files have a crude magic number at
the beginning of the file giving its type.

9 10

Accessing files Files Directories Files

Two basic approaches are used to access files: The file system may be divided into partitions. Each
partition will have a directory structure.

Sequential access, and


Directories store information such as name, size, and
location of a file.

Read/Write Operations performed on a directory include:


Pointer
search for a file,

create a file,
Direct access.

  

  
delete a file,

2) Write 3) Read 1) Read list a directory,

rename a file, and

traverse the file system.

11 12
Single-Level Directory Files Two-Level Directory Files

directory files directories files

marks marks

rank rank

graph1 graph1

graph2 graph2

test
test
Jack

Jill
marks
Jim rank

graph1

ass1

rank

game1

game2

test

13 14

Tree-Structure Directory Files Acyclic-Graph Directories Files

marks marks

rank rank

graph1 graph1

graph2 graph2

test test
Jack Jack

Jill Jill
marks marks

home rank home rank

graph1 themail
bin bin

var ls var ls

rm rm

cp cp

log log
sent sent
mail mail
received received
error error
log log

15 16
General Graph Directories Files Protection Files

marks The file system must be protected from improper ac-


rank

graph1
cess.
graph2

Jack
test
The types of access a user may be either granted or
Jill denied includes:
marks

rank
home
themail
read,
bin

var ls write,
rm

cp execute,

log append,
sent
mail
received
error delete, and
log

var
list.

In most cases access to a file is controlled at these


low-level functions. This in tern controls access to
higher level functions.
17 18

Protection Files Protection Files

Approaches to provide file protect include : Some of the problems of access lists may be over-
come by providing a condensed version of the access
list. For each file the operating systems considers
Access lists — each file has a list of users and
three types of users:
how they may access the file, and
User — the user who created and owns the file.

Passwords — a user must provided a password Group — the set of users that belong to group for the file.

to be able to access a file. Other — any user on the system.

The files attributes will include :

the user name,

the group name,

the access control for the user, group, and others.

19 20
Protection Files Magnetic Disk Files

Spin

Part of COMP3009’s html directory: track


read-write head Actuator
[˜cs3/lib/html/comp3009] % ls -al sector
total 900
drwxr-xr-x 4 ericm cs3 1024 May 6 10:49 .
drwxr-xr-x 37 josie cs3 1536 Mar 29 14:36 ..
-rw-r--r-- 1 ericm cs3 1845 Feb 25 14:10 advance.html
-rw-r--r-- 1 ericm bstaff 9380 Mar 22 11:20 ass1.html
-rw-r--r-- 1 ericm bstaff 9095 Mar 17 09:13 ass1.html˜ platter
-rw-r--r-- 1 ericm bstaff 314518 Apr 14 13:48 ass2.ps
-rw-r--r-- 1 ericm bstaff 4344 Apr 14 13:48 ass2.txt
-rw-r--r-- 1 ericm bstaff 2571 Apr 13 15:16 assignments.html
-rw-r--r-- 1 ericm bstaff 2422 Apr 10 14:10 assignments.html˜
-rw-r--r-- 1 ericm cs3 5660 Feb 25 18:02 bashead.gif cylinder
-rw-r--r-- 1 ericm cs3 6655 Feb 25 18:02 bashead.jpg

The time required to read or write a sector on a mag-


netic disk consists of:

the transfer time, and

random access time(seek time, rotational latency).

21 22

File system Files Allocation Methods Files

The designer of a file system must: The allocation method determines how a file will be
stored on the disk. It’s view of a disk is a set of fixed
sized blocks.
determine how the file system should look to the
user, and
A block consists of one or more sectors.

design algorithms and data structures that map The main problem is how to allocate the disk space to
the logical files into the physical storage devices. the files such that the disk space is utilised effectively
and files can be accessed quickly.

The file system must allow the data to be stored, lo- There are three major approaches:
cated, and retrieved easily.
contiguous,

linked, and

indexed.

23 24
Contiguous Files Contiguous Files

The contiguous allocation method places files in a set Accessing a file that has been allocated contiguously
of contiguous blocks on the disk. is easy. However, find space for a new file is more
difficult.
directory disk

file start length

report 1 2

0 1 2 3
What if there is only alot of small contiguous free
test 14 5
holes?
4 5 6 7

8 9 10 11

12 13 14 15
How big will the new file be?
16 17 18 19

Can files grow?

25 26

Contiguous Files Linked Files

Determining where to place a new file is a particular


The linked allocation method uses a pointer in each
application of the general dynamic storage-allocation
block that points to the next block that makes up the
problem. Common strategies are:
file. So if a block consist of 512 bytes and 4 bytes are
used by the pointer then the remaining 508 bytes is
First-fit, and the contents of the file. Note that, the pointers are not
part of the logical file.
Best-fit.
directory disk

file start end

report 1 2
Simulations have show that both first-fit and best-fit
test 14 6 0 1 4 2 -1 3 10
are better than worst-fit.
4 10 5 6 -1 7

8 10 6
These approaches suffer from external fragmentation. 9 11 3

As there may be sufficient space for a new file, how- 12 13 14 11 15

ever, there may be no contiguous space big enough 16 17 18 19

for the file. This may be address by compacting the


free space into one contiguous hole. Compaction is
very costly in terms to down time.
27 28
Linked Files Linked Files

The linked approach overcomes the external fragmen-


tation problem.
Another disadvantage is the space overhead of point-
The major problem with linked allocation is that in can ers. (eg if blocks are 512 bytes and pointers are 4
only be effectively used for sequential access of files. bytes then 0.78% of the disk space is used for point-
ers!!) One solution to this problem is to collect blocks
Linked allocation cannot efficiently support direct-access. into multiples, these are called clusters.

 
If a process wishes to access the ’th block it must fol-
low the pointers which requires this many disk Note that, cluster will increase the internal fragmenta-
reads. tion. This problem may be very bad if there are many
small files.

The linked allocation approach is also more fragile


then either contiguous or indexed allocation.

29 30

FAT Files Indexed allocation Files

An import variation of the linked approach is the file


allocation table(FAT). The approach is used by MS-
DOS and OS/2 operating systems. Indexed allocation uses an index block which contains
pointers that point directly to the blocks that make up
Rather than having the pointers at the end of blocks, the file.
the pointer for each block is moved into a single table
which is stored at the beginning of the partition. Each This approach addresses the problems of external frag-
entry in the FAT is associated with a block on the disk. mentation and size-declaration problems of contigu-

The contents of entry in the FAT points to the block ous allocation and also supports efficient direct ac-

that block links to. cess.
directory disk

  


   
The main advantage of this approach is that direct ac- file index block
block 0 block 16
report 0

 
14


cess is improved, as the location of any block within a test 16 0 1 2 3
1
4 11

2 3

 
  
file can be found using the FAT. 4

8
5 6 7
-1
-1
10
6
9 10 11
-1 -1
12 13 14 15 -1 -1

16 17 18 19

31 32
Indexed allocation Files Indexed allocation Files

This indexing allocation approach would limit the file



The indexed allocation approach generally suffers from
size to where is number of pointers in the index
wasted space. The index table overhead is generally
greater than that of pointers for the linked allocation

block and is the size of a block. This problem must
be addressed. Mechanism for dealing with large files
approach.
include:

a linked scheme,

a multilevel index, or

combined scheme.

Example. Given blocks are 512 bytes and block point-


ers are 32 bit. What is the maximum file size if a two
level indexing appraoch is used? How many blocks
would a 1 byte file use?
33 34

UNIX File Structure Files Combined Allocation Files

  


inode

Some operating system combine contiguous and linked


 
user id Blocks Containing the File’s Data

approaches by using contiguous allocation for small


  
group id
modification time
hard link count
files and then changing to indexed allocation if the file
  
file type
(plain, dir, sym link,

      


char/block device, or socket)

Direct Block 0
 grows. This is transparent to the user.
Direct Block 1
:
         
Direct Block 11
  





Example. Unix used an inode block which contains:




Single Indirect

"!"! "!"! "!"!                


Double Indirect
Triple Indirect
   file attributes (mode, uid,gid, trimestaps etc),
   "! "! "!        
    several direct pointers,
$#$# $#$# $#$#       
$# $# $#         one single indirect pointer,
Index Blocks
   one double indirect pointer, and

one triple indirect pointer.

35 36
Free-Space Management Files Free-Space Management Files

The free space list records all the disk blocks that are Approaches used to keep track of the free space in-
free. As a file grows or a new file is created the free cludes:
list is used to find available disk blocks. When files are
deleted or truncated then their blocks are return to the
bit vector
free list.

The free list implementation must also consider effi- linked list
ciency and performance.

grouping

counting

37 38

Efficiency and Performance Files Performance Files

A variety of techniques may be used to improve the ef- A disk cache may be used to reduce the number of
ficiency and performance of secondary storage. Some actual reads and writes to the disk.
examples are:
Disk caches may use different replacement algorithms
depending on the type of file accessed. An example
UNIX allocation and free-space algorithms try to
of this is the use of sequential accessed files may be
keep a file’s data block near that file’s inode block
improved by using free-behind and read-ahead tech-
to reduce seek time.
niques. In free-behind once a block is written past or
read pasted it will not be accessed again and hence
BSD UNIX varies the cluster size as a file grows. it may be replaced. Also blocks may be read before
they are access so they are in the cache when the
sequential access gets to them.

39 40
Recovery Files

As files and directories are cached in memory care


must be taken that a system failure does not loss data
or create inconsistent data.

Often an operating system will check the consistency


of the file system at boot time. This consistency checker
will also attempt to fix any inconsistencies it finds.

41

Вам также может понравиться