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

# Operating System (CH 4)

This document provides an overview of file systems, detailing their structure, naming conventions, types, and operations. It discusses how files are managed by operating systems, including attributes, protection mechanisms, and access control. Additionally, it outlines directory structures and the importance of file organization for efficient data retrieval and management.

Uploaded by

fikadu.meu.edu
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)
13 views

# Operating System (CH 4)

This document provides an overview of file systems, detailing their structure, naming conventions, types, and operations. It discusses how files are managed by operating systems, including attributes, protection mechanisms, and access control. Additionally, it outlines directory structures and the importance of file organization for efficient data retrieval and management.

Uploaded by

fikadu.meu.edu
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/ 46

Operating System

By
Fikadu M.
[email protected]
Chapter
Four
File System

Lecture 4: File System 3/12/2021


Outline
3

🠶 Introduction to file system

🠶 Directory Structure

🠶 Protection

🠶 Access

🠶 Space Allocation

Lecture 4: File System 3/12/2021


4 4.1. Introduction
 All computer applications need to store and retrieve information, While
a process is running.

 A file is a named collection of related information that is recorded on


secondary storage such as magnetic disks, magnetic tapes and optical
disks.

 In general, a file is a sequence of bits, bytes, lines or records whose


meaning is defined by the files creator and user.

Lecture 4: File System 3/12/2021


5 Cont’d
🠶 … for a collection of information.
A file is a container

🠶 Files are managed by the operating system.


 How they are structured,
 named,
 accessed,
 used,
 protected,
 implemented,
 and managed are major topics in operating system
design.

Lecture 4: File System 3/12/2021


6 Cont’d
🠶 …programs and data. Data files may be:
File represents

🠶 Types:
🠶 Data files may be:

🠶 numeric
🠶 character
🠶 binary
🠶 Program

Lecture 4: File System 3/12/2021


7 4.1.1. File Naming
🠶 When a process creates a file, it gives the file a name.

🠶 When the process terminates, the file continues to exist and can be accessed
by other processes using its name.

🠶 The exact rules for file naming vary somewhat from system to system, but all
current operating systems allow strings of one to eight letters as legal file
names.

🠶 Thus andrea, bruce, and cathy are possible file names. Frequently digits and
special characters are also permitted, so names like 2, urgent!, and Fig.2-14
are often valid as well.
🠶 Many file systems support names as long as 255 characters.

Lecture 4: File System 3/12/2021


8 Cont’d
… distinguish between upper and lower case letters, whereas
🠶 Some file systems
others do not.

🠶 Thus a UNIX system can have all of the following as three distinct files:
maria, Maria, and MARIA. In MS-DOS, all these names refer to the
same file.

🠶 Many operating systems support two-part file names, with the two parts
separated by a period, as in prog.c.

🠶 The part following the period is called the file extension and usually
indicates something about the file.

Lecture 4: File System 3/12/2021


9 Cont’d
🠶 …for example,
In MS-DOS,

🠶 file names are 1 to 8 characters, plus an optional extension of 1 to 3 characters.

🠶 In UNIX,

🠶 the size of the extension, if any, is up to the user, and a file may even have two or
more extensions, as in homepage.html.zip, where .html indicates a Web page in
HTML and .zip indicates that the file (homepage.html) has been compressed
using the zip program.

Lecture 4: File System 3/12/2021


1 Cont’d
0
🠶 Some of the…
more common file extensions and their meanings are shown in
Fig. 4-1.

Lecture 4: File System 3/12/2021


1 4.1.2. File
1
Structure
🠶 File structure is a structure, which is according to a required format that
operating system can understand.

🠶 Files can be structured in any of several ways. Three common possibilities


are depicted in Fig. 4-2.

Lecture 4: File System 3/12/2021


1 Cont’d
2

Lecture 4: File System 3/12/2021


1 Cont’d
3
🠶 A file has a…
certain defined structure according to its type.

🠶 A text file is a sequence of characters organized into lines.


🠶 A source file is a sequence of procedures and functions.
🠶 An object file is a into blocks that
sequence of bytes organized understandable are
by the machine.

Lecture 4: File System 3/12/2021


1 Cont’d
4
🠶 Four terms …
are used for files

🠶 Field : A field is the basic


element of data. An individual
field contains a single value.
🠶 Record : A record is a collection of related fields that can be treated as a unit by some
application program.
🠶 Database : A database is a collection of related data.
🠶 DBMS : Usually, there is a separate Database management system that is independent of
the operating system.

Lecture 4: File System 3/12/2021


1 4.1.3. File Types
5
🠶 When we design a file system – indeed , an entire operating system – we
always consider whether the operating system should recognize and support
file types.

🠶 If an operating system recognize the type of file, it can then operate on the
file in reasonable ways.

Lecture 4: File System 3/12/2021


1 Cont’d
6

Lecture 4: File System 3/12/2021


1 4.1.4. File
7
🠶 Every file Attributes
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.

🠶 They are vary from one operating system to another. The common attributes
are:-

Lecture 4: File System 3/12/2021


1 Cont’d
8
🠶 Name – The… symbolic file name is the only information kept in human-
readable form.

🠶 Identifier – This unique tag, usually a number, identifies the file within the
file system; it is the non-human-readable name for the file.

🠶 Type – This information is needed for systems that support different types of
files.

🠶 Location – This information is a pointer to a device and to the location of the


file on that device.

Lecture 4: File System 3/12/2021


1 Cont’d
9
🠶 another file…
attributes

Lecture 4: File System 3/12/2021


20 4.1.5. File operation
🠶 Any file system provides not only a means to store data organized as files,
but a collection of functions that can be performed on files.

🠶 Typical operations include the following:

🠶 Creating a file : A new file is defined and positioned within the structure of files.
🠶 Deleting a file : A file is removed from the file structure and destroyed. To delete a file, we
search the directory for the named file.
🠶 Opening a file : An existing file is declared to be "opened" by a process, allowing the
process to perform functions on the file.

Lecture 4: File System 3/12/2021


2 Cont’d
1
…: The file is closed with respect to a process, so that the
🠶 Closing a file
process no longer may perform functions on the file, until the process
opens the file again.
🠶 Reading a file : A process reads all or a portion of the data in a file.
🠶 Writing a file : A process updates a file, either by adding new data that
expands the size of the file or by changing the values of existing data items
in the file.
🠶 Appending:
🠶 Renaming:
🠶 Repositioning within a file : The directory is searched for the appropriate
entry, and the current-file-position pointer is repositioned to a given value
Repositioning within a file need not involve any actual I/0.

Lecture 4: File System 3/12/2021


2 Ex. File lock in
2
🠶 The lock ()java
method of the File Channel is used to acquire the lock.

FileLock lock(long begin, long end, boolean shared)

🠶 Where begin and end are the beginning and ending positions of the
region being locked.

Lecture 4: File System 3/12/2021


2 Ex. File lock in
3
🠶 java
import java.io.*;
🠶 import java.nio.channels.*;
🠶 public class LockingExample {
🠶 public static final boolean EXCLUSIVE = false;
🠶 public static final boolean SHARED = true;
🠶 public static void main(String arsg[]) throws IOException {
🠶 FileLock sharedLock = null;
🠶 FileLock exclusiveLock = null;
🠶 try {
🠶 RandomAccessFile raf = new RandomAccessFile("file.txt",
"rw");
🠶 // get the channel for the file
🠶 FileChannel ch = raf.getChannel();
🠶 // this locks the first half of the file - exclusive
🠶 exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);
🠶 /** Now modify the data . . . */
🠶 // release the lock
🠶 exclusiveLock.release();
Lecture 4: File System 3/12/2021
24 Ex. File lock in
🠶 java
// this locks the second half of the file - shared
🠶 sharedLock = ch.lock(raf.length()/2+1, raf.length(),
SHARED);
🠶 /** Now read the data . . . */
🠶 // release the lock
🠶 exclusiveLock.release();
🠶 } catch (java.io.IOException ioe) {
🠶 System.err.println(ioe);
🠶 }finally {
🠶 if (exclusiveLock != null)
🠶 exclusiveLock.release();
🠶 if (sharedLock != null)
🠶 sharedLock.release();
🠶 }
🠶 }
🠶 }

Lecture 4: File System 3/12/2021


25 4.2. Directory
🠶 Next, we consider how to store files. Certainly, no general-purpose computer
stores just one file. There are typically thousand, millions, and even billions of
files within a computer.

🠶 Files are stored on random-access storage devices, including hard disks, optical
disks, and solid state (memory-based) disks.

🠶 A storage device can be used in its entirety for a file system. It can also be
subdivided for finer-grained control.

🠶 For example, a disk can be partitioned into quarters, and each quarter can hold a
file system.
🠶 Partitioning is useful for limiting the sizes of individual file systems, putting multiple file-system
types on the same device, or leaving part of the device available for other uses, such as swap
space or unformatted (raw) disk space.

Lecture 4: File System 3/12/2021


26 Cont’d

Lecture 4: File System 3/12/2021


2 Directory structure
7
A collection of nodes containing information about
all files.

Directory

File
F F F
s F
1 2 4
3 F
n

Backups of these two structures are kept on


tapes.
Lecture 4: File System 3/12/2021
28 Cont’d
🠶 …can be viewed as a symbol table that translates file names into
The directory
their directory entries.
🠶 To keep track of files, file systems normally have directories or folders,
which in many systems are themselves files.

🠶 When considering a particular directory structure, we need to keep in mind


the operations that are to be performed on a directory:
🠶 Create a file
🠶 Delete a file
🠶 List a directory
🠶 Rename a file
🠶 Traverse the file system

Lecture 4: File System 3/12/2021


29 Single level directory system
🠶 The simplest form of directory system is having one directory containing all
the files. Sometimes it is called the root directory, but since it is the only one,
the name does not matter much.

Lecture 4: File System 3/12/2021


30 Two level directory system
🠶 Separate directory for each user

🠶 Path name
🠶 Can have the same file name for different user
🠶 Efficient searching
🠶 No grouping capability

Lecture 4: File System 3/12/2021


3 Tree structured Directory
1

Lecture 4: File System 3/12/2021


3 Cont’d
2

Lecture 4: File System 3/12/2021


33 Cont’d
🠶 Information…
in a Device Directory
🠶 Name
🠶 Type
🠶 Address
🠶 Current length
🠶 Maximum length
🠶 Date last accessed (for archival)
🠶 Date last updated (for dump)
🠶 Owner ID (who pays)
🠶 Protection information (discuss later)

Lecture 4: File System 3/12/2021


34 Protectio
🠶 n should be able to control:
File owner/creator
🠶 what can be done

🠶 By whom

🠶 When information is stored in a computer system, we want to keep it safe


from physical damage (the issue of reliability) and improper access (the
issue of protection). Reliability is generally provided by duplicate copies of
files.

Lecture 4: File System 3/12/2021


35 Cont’d

Lecture 4: File System 3/12/2021


36 Types of access
🠶 The need to protect files is a direct result of the ability to access files.

🠶 Systems that do not permit access to the files of other users do not need
protection.

🠶 Protection mechanisms provide controlled access by limiting the types of file


access that can be made.

Lecture 4: File System 3/12/2021


37 Cont’d
🠶 … types of operations may be controlled:
Several different

🠶 Read. Read from the file.


🠶 Write. Write or rewrite the file.
🠶 Execute. Load the file into memory and execute it.
🠶 Append. Write new information at the end of the file.
🠶 Delete. Delete the file and free its space for possible reuse.
🠶 List. List the name and attributes of the file.

🠶 Other operations, such as renaming, copying, and editing the file, may also
be controlled.

Lecture 4: File System 3/12/2021


38 Access Control
🠶 The most common approach to the protection problem is to make access
dependent on the identity of the user. Different users may need different
types of access to a file or directory.

🠶 The most general scheme to implement dependent access is to associate with


each file and directory an access control list (ACL) specifying user names
and the types of access allowed for each user.

🠶 When a user requests access to a particular file, the operating system checks
the access list associated with that file. If that user is listed for the requested
access, the access is allowed. Otherwise, a protection violation occurs, and
the user job is denied access to the file.

Lecture 4: File System 3/12/2021


39 Cont’d
🠶 …the length of the access-control list, many systems recognize
To condense
three classifications of users in connection with each file:

 Owner. The user who created the file is the owner.


 Group. A set of users who are sharing the file and need similar access is a
group, or work group.
 Universe. All other users in the system constitute the universe.

Lecture 4: File System 3/12/2021


40 Window 7 access control list management

Lecture 4: File System 3/12/2021


4 A sample UNIX directory
1
listing

Lecture 4: File System 3/12/2021


42 File Access Mechanism
🠶 File access mechanism refers to the manner in which the records of a file
may be accessed. There are several ways to access files

🠶 Sequential access :the records are accessed in some sequence i.e. the
information in the file is processed in order, one record after the other.
Example: Compilers usually access files in this fashion.
🠶 Direct/Random access : Random access file
organization provides, accessing the records directly.
🠶The records need not be in any sequence within the file and they need not be
in adjacent locations on the storage medium.
🠶 Indexed sequential access : This mechanism is built up on base of
sequential access.
🠶 Index is searched sequentially and its pointer is used to access the file directly.

Lecture 4: File System 3/12/2021


43 Space Allocation
🠶 Files are allocated disk spaces by operating
system. Operating systems deploy following three main
ways to allocate disk space to files.

1. CONTIGUOUS ALLOCATION
🠶 Each file occupy a contiguous address space on disk.
🠶 Assigned disk address is in linear order.
🠶 Easy to implement.
🠶 External fragmentation is a major issue with this type of allocation technique.

Lecture 4: File System 3/12/2021


44 Cont’d

2. LINKED ALLOCATION
🠶 Each file carries a list of links to disk blocks.
🠶 Directory contains link / pointer to first block of a file.
🠶 No external fragmentation
🠶 Effectively used in sequential access file.
🠶 Inefficient in case of direct access file.

3. INDEXED ALLOCATION
🠶 Provides solutions to problems of contiguous and linked allocation.
🠶 A index block is created having all pointers to files.
🠶 Each file has its own index block which stores the addresses of disk space occupied by the
file.
🠶 Directory contains the addresses of index blocks of files.

Lecture 4: File System 3/12/2021


45 File System in LINUX
🠶 Linux supports many different file systems, but common choices for the
system disk include the ext family (such as ext2 and ext3), XFS, JFS and
ReiserFS.
🠶 The ext3 or third extended file system is a journaled file system and is the
default file system for many popular Linux distributions .
🠶 It is an upgrade of its predecessor ext2 file system and among other things it
has added the journouling feature.
🠶 A journaling file system is a file system that logs changes to a journal
(usually a circular log in a dedicated area) before committing them to the
main file system. Such file systems are less likely to become corrupted in the
event of power failure or system crash.

Lecture 4: File System 3/12/2021


End of Chapter
Four

Lecture 4: File System 3/12/2021

You might also like