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

CH 5.0ok

Uploaded by

Shree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

CH 5.0ok

Uploaded by

Shree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

5.

0 : File Management
Learning Outcomes
5.0 Understand File Management in Operating System
5.1 Describe three type of file structure / directory structure
a. Single - Level Directory
b. Two level directory
c. Tree – structured directory
5.2 Various method of storing files
a. Contiguous allocation
b. Link list allocation (disk blocks)
c. Link list allocation using index (table in main memory)
d. Index-node
Internal File Structure
• Files can be structured in any of several ways. Three
common possibilities are three kinds of files. (a) Byte
sequence. (b) Record sequence. (c) Tree.
– Stream of Bytes. The file is an unstructured sequence of
bytes. In effect, the operating system does not know or care
what is in the file. All it sees are bytes. Both UNIX and
Windows use this approach.
– Records. The first step up in structure is a sequence of fixed-
length records, each with some internal structure.
– Tree of Records. The third kind of file structure is a file
consists of a tree of records, not necessarily all the same
length, each containing a key field in a fixed position in the
record.
Internal File Structure

• Three kinds of files. (a) Byte sequence. (b) Record sequence.


(c) Tree.
Internal File Structure
• Internally, locating an offset within a file can be complicated for the
OS.
• Disk systems typically have a well-defined block size determined by
the size of a sector. All disk I/O is performed in units of one block
(physical record), and all blocks are the same size.
• It is unlikely that the physical record size will exactly match the
length of the desired logical record. Packing a number of logical
records into physical blocks is a common solution to this problem.
• For example, the UNIX OS defines all files to be simply streams of
bytes. Each byte is individually addressable by its offset from the
beginning (or end) of the file. In this case, the logical record size is 1
byte. The file system automatically packs and unpacks bytes into
physical disk blocks -say, 512 bytes per block- as necessary.
Internal File Structure
• The file may be considered to be a sequence of blocks. All the basic I/O
functions operate in terms of blocks.
• Because disk space is always allocated in blocks, some portion of the last
block of each file is generally wasted. If each block were 512 bytes, for
example, then a file of 1,949 bytes would be allocated four blocks (2,048
bytes); the last 99 bytes would be wasted.
• The waste incurred to keep everything in units of blocks (instead of bytes)
is internal fragmentation. All file systems suffer from internal
fragmentation; the larger the block size, the greater the internal
fragmentation.
• File systems were always sequential, meaning that the successive records
had to be processed in the order in which they were stored, starting from ...
When relationships between data elements need to be represented as part
of the records so as to make more efficient the desired operations.
• The conclusion of file structure is the way data is structured on a disk. Can
also refer to the way data is structured into records and fields within a
database file.
File Management
• Is software responsible for creating,
deleting, modifying and controlling
access to files(as well as for managing the
resources used by files)
Primary Activities Perform in File
Management
• Keep track of where each file is stored –in computer system
FM keep track of its files using directories that contain fail
name, physical location and other important information
about each file
• Use a policy that will determine where and how the files will
be stored, making sure to efficiently use the available storage
space and provide efficient access to the files
• Allocate each file when a user has been cleared for access to it,
then record its use
• Reallocate the file when the file is to be returned to storage,
and communicate its availability to others who may be waiting
for it.
Method of Storing File
• Many files will be stored on the same disk
• The main issue is how to allocate space to
these file  so that file disk space is utilized
effectively and file can be accessed quickly
• 3 allocation methods :
a. Contiguous Allocation
b. Link List Noncontiguous Allocation
c. Link List Using Index/Index node Allocation
Method of Storing File : Contiguous
Allocation

• This scheme used in early systems.


• Allocation using first fit/ best fit
• A need for compaction
• It is very simple to manage and implement.
• Any record can be found and read once its starting
address and size are known.
• Advantage is its ease of direct access because every
part of the file is stored in the same compact area.
Method of Storing File : Contiguous
Allocation
Advantages
• Simple – only starting location (block #)
and length (number of blocks) are required
• Advantage is its ease of direct access
because every part of the file is stored in the
same compact area.
Method of Storing File : Contiguous
Allocation
Disadvantages
• Difficulty in finding space for a new file
• Wasteful of space
• Suffer from the problem of external fragmentation
• Size declaration problem
– 2 possibilities; if allocated too little space to
filemay file cannot be extended
– User normally overestimate the amount of space
needed  occur wasted space
Method of Storing File : Contiguous
Allocation
Method of Storing File : Link- List
Noncontigous Allocation
• Simple – need only starting address
• Free-space management system implemented– no
waste of space
• Free –space – management system: keep track free disk
space called free-space list and record all free disk block
• Each file consists of a list of disk blocks that linked :
the disk block may be scattered anywhere on the disk
• The directory contains a pointer to the first and last
block of the file
• Each block contains pointer to the next block .
Method of Storing File : Link- List
Noncontigous Allocation
Advantages
• Solves problem of contiguous allocation,
– No external fragmentation
– Size declaration problem (the size of a file does
not need to be declared when the file is created)
– Simply to create a new file by implementation
of free- space – management system
Method of Storing File : Link- List
Noncontigous Allocation
Disadvantages
• Space is required for the pointer. (Eg: If pointer
requires 4bytes out of 512-byte block, so 0.78% is
being used for pointer rather than infomation)
• Cannot support efficient direct access because
the pointer to block are scattered anywhere on
the disk(Eg: To find ith block of a file, we must
start at the beginning of the file and follow the
pointers until we get to the ith block)
Method of Storing File : Link- List
Noncontigous Allocation

10

16 25

A file of 5 blocks might start at


block 9, continue at block 16,
then block 1, block 10 and
finally block 25.
Method of Storing File : Link List Using
Index/Index Node Allocation

• Bringing all pointers together into one


location
• Each file has its own index block
Method of Storing File : Link List Using
Index/Index Node Allocation
Advantages
• Solves the Link List Allocation problem:
– Cannot support efficient direct access because
the pointer to block are scattered anywhere on
the disk
– Solution : by bringing all pointer together into
one location (index block)
Method of Storing File : Link List Using
Index/Index Node Allocation
Free Space Management System

• Free –space – management system: keep track free disk space. The
system maintain a free – space list.
• The free – space list records all free disk block(those not allocated to
some file or directory)
• To create a file, we search a free – space list for required amount of
space and allocate that space to the new file.
• If space is allocated, it will removed from free- space list.
• When a file is deleted, its disk space is added to the free – space list.
• Free – space allocation method influence:
– Efficiency of use of disk space
– Performance of file system
– Reliability of secondary storage
Free Space Management System
• Free – space list is implemented as bit map or bit
vector
• If block is free it represent in bit 1
• If block is allocated it represent in bit 0
• Eg: Consider a disk has 30 blocks
– Where blocks 2,3,4,5,8,9,10,11,12,13,17,18,25,26 and
27 are free, and the rest of the blocks are allocated.
– What is bit vector for disk above ?
– Bit vector : 0011110011111100011000000111000
Free Space Management System
A disk has 35 blocks in which no. blocks 5, 7, 9, 12,
13, 24, 28, 29, 31, and 34 have been allocated to
specific files.

a) Define the bit vectors to disk above.


b) By using the method of First Fit and Contiguous
Fit , Draw the position of the TEST file size 45K
who wish to be included in the disk. Assume a
block size = 20K.
c) Define the bit vectors for the new disk after
test file allocated
File caching 18.9.13(5A) (5B)

• Caching occurs under the direction of the cache manager, which


operates continuously while Windows is running. File data in the
system file cache is written to the disk at intervals determined by the
operating system, and the memory previously used by that file data is
freed—this is referred to as flushing the cache. The policy of delaying
the writing of the data to the file and holding it in the cache until the
cache is flushed is called lazy writing, and it is triggered by the cache
manager at a determinate time interval. The time at which a block of
file data is flushed is partially based on the amount of time it has been
stored in the cache and the amount of time since the data was last
accessed in a read operation. This ensures that file data that is
frequently read will stay accessible in the system file cache for the
maximum amount of time.
File caching
File system
• A file system (or filesystem) is a means to organize
data expected to be retained after a program terminates
by providing procedures to store, retrieve and update
data as well as manage the available space on the
device(s) which contain it. A file system organizes data
in an efficient manner and is tuned to the specific
characteristics of the device. A tight coupling usually
exists between the operating system and the file system.
Some file systems provide mechanisms to control access
to the data and metadata. Ensuring reliability is a major
responsibility of a file system. Some file systems allow
multiple programs to update the same file at nearly the
same time.
Metadata
Metadata (metacontent) is defined as data providing information
about one or more aspects of the data, such as:
• Means of creation of the data
• Purpose of the data
• Time and date of creation
• Creator or author of data
• Location on a computer network where the data was created
• Standards used
• For example, a digital image may include metadata that describes how
large the picture is, the color depth, the image resolution, when the
image was created, and other data. A text document's metadata may
contain information about how long the document is, who the author
is, when the document was written, and a short summary of the
document.

You might also like