0% found this document useful (0 votes)
6 views46 pages

OS - 3 - Files

The document provides an overview of secondary storage structures, focusing on file systems, their types, and operations. It discusses file attributes, access methods, directory structures, and file sharing mechanisms, emphasizing the importance of file management in operating systems. Additionally, it covers file protection and access control, highlighting the roles of users and groups in managing file permissions.
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)
6 views46 pages

OS - 3 - Files

The document provides an overview of secondary storage structures, focusing on file systems, their types, and operations. It discusses file attributes, access methods, directory structures, and file sharing mechanisms, emphasizing the importance of file management in operating systems. Additionally, it covers file protection and access control, highlighting the roles of users and groups in managing file permissions.
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

By

K PAVAN KUMAR
Dept. Of CSE
VFSTR University
Secondary Storage Structure
• File Systems - file concept, access methods
• Directory structure,
• File system mounting,
• File sharing protection;
• File-system structure,
• File system implementation,
• Directory implementation,
• Allocation methods,
• Free space management.
File

• Its a collection of data or information.


• Computer treats every file like a single unit.
• Therefore each file has a filename.
• 2 Types: Program files and Data Files.
• Program files  Software instructions.
• Source program files and Executable files.
• Data Files  Stores information.
• Graphic Files, Audio files and Animation/Video files.
File systems

• Data structure that stores data and information on storage devices


• File system is the part of the OS.
• It is responsible for file management.
• It provides a mechanism to store the data and access to the file
contents including data and programs.

• Some Operating systems treats everything as a file for example


Ubuntu.
File systems in Windows

• Windows environment, follows 3 file systems.


• Each with different indexing methods.
1. FAT (12, 16, or 32) file system.
2. NTFS (New Technology File System)
3. exFAT, is a lightweight file system used primarily in flash storage
applications and SD cards.
• FAT: file allocation table
File systems in Unix
• Linux file system has a hierarchal file structure
• It contains a root directory and its subdirectories.
• All other directories can be accessed from the root directory.
• A partition usually has only one file system, but it may have more than
one file system.

Ex: Ext, Ext2, Ext3 and Ext4  Extended File System.


• JFS  Journaled File System, and it is developed by IBM for AIX Unix. ...
• ReiserFS File System. ...
• XFS File System. ...
• Btrfs File System. ...
• Swap File System.
Important properties of a file system:

• Files are stored on disk or other storage.


• Files have names and are associated with access permissions.

• Arranged to reflect the relationship between them.

• File Name = Name.Extension


File Attributes
• Name  Only information kept in human-readable
form
• Identifier  Unique tag (number) identifies file
within file system
• Type  Needed for systems that support different
types
• Location  Pointer to file location on device
• Size  Current file size
• Protection  Controls who can do reading,
writing, executing
• Time, date, and user identification  Data for
protection, security, and usage monitoring
File Operations
File is an abstract data type
• Create :
• Write : At write pointer location
• Read : At read pointer location
• Reposition/Seek : Current position to a specific place in the file.
• Delete : Directory is searched and Freed.
• Truncate : Deleting the file except deleting attributes.
• Open(Fi) : search the directory structure on disk for entry Fi, and move
the content of entry to memory
• Close (Fi) : move the content of entry Fi in memory to directory
structure on disk.
• Append and Rename
Open Files
• Several pieces of data are needed to manage open files:
• Open-file table: tracks open files
• File pointer: pointer to last read/write location, per process that has the file
open
• File-open count: counter of number of times a file is open – to allow removal of
data from open-file table when last processes closes it
• Disk location of the file: Cache of data access information
• Access rights: per-process access mode information
Open File Locking

• Provided by some OS and file systems


• Similar to reader-writer locks
• Shared lock similar to reader lock – several processes can acquire
concurrently
• Exclusive lock similar to writer lock
• Mediates access to a file
• Mandatory or advisory:
• Mandatory: Access is denied depending on locks held and requested
• Advisory: Processes can find status of locks and decide what to do
File Types

• Executable files  .exe


• Object files  .obj/o
• Source code  .c, .java etc..
• Batch Files  bat
• Text files
• Word process files
• Print and view files pdf
• Library files  .lib
• Archive files  .zip
• Multimedia files  .mp4
File Types – Name. Extension
File Structure

• Predefined format in such a way that an OS understands.


• It has an exclusively defined structure, which is based on its type.
• Three types of files structure in OS:
Text file: It is a series of characters that is organized in lines.
Object file: It is a series of bytes that is organized into blocks.
Source file: It is a series of functions and processes.
File Structure

• Simple record structure


• Lines
• Fixed length
• Variable length
• Complex Structures
• Formatted document
• Relocatable load file
• Can simulate last two with first method by inserting appropriate
control characters
• Who decides:
• Operating system
• Program
Access Methods

• When a file is used, information is read and accessed into computer


memory
Types are
• Sequential-Access,
• Direct Access,
• Index sequential Method.
Sequential-Access

• Data is accessed one record right after another record in an order.


• When we use read command, it move ahead pointer by one
• When we use write command, it will allocate memory and move the
pointer to the end of the file
• Such a method is reasonable for tapeEditor and compiler usually
access the file in this fashion.
Direct Access

• Relative access method.


• Read and Write records in No Particular order.
• Access is based on the disk model of a file.
• For direct access, the file is viewed as a numbered sequence of block
or record.
Ex: Read 14 then block 59 and then block 17.

• A block number provided by the user to the OS is normally a relative


block number, the first relative block of the file is 0 and then 1 and so
on.
Index sequential method

• It is built on top of Sequential access.


• It control the pointer by using index

• To find a record in the file, we first search the index and then by the
help of pointer we access the file directly.
Ex: of Index and Relative Files
Directory structure
Directory

• Directory is a container that is used to contain folders and files.


• It organizes files and folders in a hierarchical manner.
Directory
• A collection of nodes containing
information about all files.
• Both the directory structure and
the files reside on disk
Directory Organization

Efficiency: Locating a file quickly


Naming: Convenient to users
• Two users can have same name for different files
• The same file can have several different names
Grouping: Logical grouping of files by properties, (e.g., all Java
programs, all games, …)
Operations Performed on Directory

• Search for a file

• Create a file

• Delete a file

• List a directory

• Rename a file

• Traverse the file system


Directory Structure

• Single-level directory
• Two-level directory
• Tree-structured directory
• Acyclic graph directory
• General graph directory structure
Single-level directory
• Simplest directory structure.
• In it, all files are contained in the same directory
Advantages:
• Implementation is very easy.
• If the files are smaller in size, creation, searching, deletion, updating
will become faster.

Disadvantages:
• There may chance of name collision because two files can not have
the same name.
• If the files are larger in size, creation, searching, deletion, updating
will become slow.
• This can not group the same type of files together.
Two-level directory
• Create a separate directory for each user.
• Each user has their own UFD (user files directory).
• System’s MFD(master file directory) is searches whenever a new user
id=s logged in.
Two-level directory

Advantages:
• We can give full path like /User-name/directory-name/.
• Different users can have the same directory as well as the file name.
• Searching of files becomes easier due to pathname and user-
grouping.

Disadvantages:
• A user is not allowed to share files with other users.
• Still, it not very scalable, two files of the same type cannot be
grouped together in the same user.
Tree structure

• The tree has a root directory, and every file in the system has a
unique path.
Tree structure

• Efficient searching
• Grouping Capability
• Current directory (working directory)
• cd /spell/mail/prog
• type list

No Sharing between users


Tree structure

• Path: Describes the location of a file


• Absolute path or full path: It always starts at the root directory.
• Relative path: It is a path that describes the location of a file or folder
in relative to the current working directory.
Acyclic graph directory

• It is a graph with no cycles


• Allows us to share subdirectories and files.
Acyclic graph directory

Advantages:
• Share files.
• Searching is easy due to different-different paths.

Disadvantages:
• We share the files via linking, in case deleting it may create the
problem,
• If the link is a soft link then after deleting the file we left with a
dangling pointer.
• In the case of a hard link, to delete a file we have to delete all the
references associated with it.
General Graph Directory

• Cycles are allowed within a directory structure where multiple


directories can be derived from more than one parent directory.
General Graph Directory

Advantages:
• It allows cycles.
• It is more flexible than other directories structure.

Disadvantages:
• It is more costly than others.
• It needs garbage collection.
File System Mounting

• Mounting is a process by which the OS makes files and directories on


a storage device (such as hard drive, CD-ROM, or network share)
available for users to access via the computer's file system.
File System Mounting
• OS is given the name of the device and the mount point -the location
within the file structure where the file system is to be attached.

• Typically, a mount point is an empty directory.


• Next, the OS verifies that the device contains a valid file system.
• Finally, the OS notes in its directory structure that a file system is
mounted at the specified mount point.
• This scheme enables the OS to traverse its directory structure, switching
among file systems as appropriate.
Mount Point

• A unmounted file system (b) is mounted at a mount point


File Sharing/ File-swapping

• Sharing of files on multi-user systems is desirable.


• Sharing may be done through a protection scheme.
• On distributed systems, files may be shared across a network
• Network File System (NFS) is a common distributed file-sharing
method
• If multi-user system
• User IDs identify users, allowing permissions and protections to be per-user
• Group IDs allow users to be in groups, permitting group access rights
• Owner of a file / directory
• Group of a file / directory
File sharing

Ways are:
• Removable storage devices
• Centralized file hosting server installations on networks
• World Wide Web-oriented hyperlinked documents
• Distributed peer-to-peer networks
File Sharing – Remote File Systems

• In Distributed systems, file system access between systems


• Manually via programs like FTP
• Automatically, seamlessly using distributed file systems
• Semi automatically via the world wide web
File Sharing – Remote File Systems

• In Client-server model allows clients to mount remote file systems


from servers
• Server can serve multiple clients
• Client and user-on-client identification is insecure or complicated
• NFS is standard UNIX client-server file sharing protocol
• CIFS is standard Windows protocol
• Standard operating system file calls are translated into remote calls
File Sharing – Failure Modes

• All file systems have failure modes


• For example corruption of directory structures or other non-user data, called
metadata
• Remote file systems add new failure modes, due to network failure,
server failure
• Recovery from failure can involve state information about status of
each remote request
• Stateless protocols such as NFS v3 include all information in each
request, allowing easy recovery but less security
Protection

• File owner/creator should be able to control:


• what can be done
• by whom
• Types of access
• Read
• Write
• Execute
• Append
• Delete
• List
Access Lists and Groups

• Mode of access: read, write, execute


• Three classes of users on Unix / Linux
• RWX
• a) owner access 7  111
b) group access 6  110
• c) public access 1  001
Ex: chmod 761 f1

You might also like