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

OS CHAPTER-11_File Management

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

OS CHAPTER-11_File Management

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

1

CONTENTS
 File concept
 Access Methods
 Disk and directory structure
 File system mounting
 Protection
2

Introduction
File system is used to define storage devices and control
how data is stored and retrieved.
From the system point of view, file system helps to
organize and distribute storage spaces, and provides
some protective measures to ensure the data security.
Specifically, it can help to create file, store file, modify file,
and control access to file, and undo file when users don't
need it.
3

WHAT IS A FILE?
A file is a collection of related information that is recorded on
secondary storage.
It is a continuous logical address space provided to us in the
secondary memory.
WHAT IS A FILE SYSTEM THEN?
A file system is a process that manages how and where data on a
storage disk, typically a hard disk drive (HDD), is stored,
accessed and managed. It is a logical disk component that
manages a disk's internal operations as it relates to a computer
and is abstract to a human user.

Commonly used file systems include:


>File Allocation Table 32 (FAT 32)
>New Technology File System (NTFS)
4

File attributes
A file access classification that determines how a file can be viewed or
whether it can be edited. File attributes are maintained in the file system's
directories.
A file’s attributes vary from one operating system to another but typically consist of these:
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.
Size: The current size of the file (in bytes, words, or blocks) and possibly
the maximum allowed size are included in this attribute.
5

Protection: Access-control
information determines who can
do reading, writing, executing,
and so on.
Time, date, and user identification:
This information may be kept for
creation, last modification and,
last use. These data can be useful
for protection, security, and usage
monitoring.

A file info window on Mac OS X.


6

File operations
 Creating a file: finding a space in the file system directory
making an entry for the new file in the directory

 Writing a file: writer pointer


 Reading a file: read pointer
 Current file position pointer: saves space and reduces time
complexity
same can be used for reading and writing
 Reposition within file : seek (does not involve any actual I/O)
 Delete : releasing all the file space along with attributes
 Truncate : erasing only the contents of the file but keeping its attributes
7

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
Other file operations are also there:
Appending new
information, renaming a file, copying a
file, etc.
8

Open Files
Open-file table: contains information about all open files.
 No searching for specified file required while performing file operations
 The open() system call returns a pointer to the entry in the open file table
 To handle same files opened by multiple processes, 2 levels of internal tables
are used by the operating system:
 Per-process open file table: contains info about all open files of that
process,
plus pointer to entry in global open file table (can be many)
 System wide open file table: global table maintained by the OS
containing process independent open file information (only one)
Information related to an 9


open file
File pointer: pointer to last read/write location
unique to each process that has the file open
 File-open count: counter of number of times a file is open in the system wide
open file table – 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: access mode information
stored in per process table
Open file 10

locking
֍ Mediates access to a file (shared or exclusive)
֍ Useful for processes that are shared by several
processes
֍ Provided by some operating systems 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
only one process can acquire at a
time
11

Furthermore, locks can also be classified as:


Mandatory or advisory:
Mandatory – :Access is denied depending on locks
held and released.
:Integrity is assured. (Windows)
Advisory – :Processes can find status of locks and
decide what to do
:Depends on software developers that
locks are
appropriately acquired and released.
(Unix)
12

ACCESS
METHOD
S

SEQUENTIAL DIRECT OTHERS


13

SEQUENTIAL ACCESS
 A sequential access file emulates magnetic tape operation
 Information is accessed in order- one record after the other

Operation supported includes:

read_next() - read the next portion of file and advance the tape to
the next position.

write_next() – appends to the end of file and advance the tape to


new end of file.

rewind - file resets to beginning.

skip n records – can advance the tape forward or backward


14

SEQUENTIAL ACCESS FILE


TAPE MODEL OF FILE
15

DIRECT ACCESS
 The file is viewed as a numbered sequence of blocks or
records
 Allows arbitrary blocks to be read or written

Operations supported include:

Read n read record no. n (n=relative block number)

Write n write record no. n

Sequential access can be easily emulated using direct


access. The inverse is complicated and inefficient
16

Simulation of sequential access on a direct access file

Sequential access Implementation for direct access

reset cp:=0;

read next read cp;


cp:=cp+1;
write next write cp;
cp:=cp+1;
17

 allows immediate access to large amount of information.

 The block no provided by user is a relative block number


which is an index relative to the beginning of file.

 The actual absolute disk address of the block may be


14703 for the first block and 3192 for second but relative
block no. will be 0,1 and so on.

 Given a logical record length L , a request for record N is


turned into an I/O request for L bytes at location L+(N-1).
18

OTHER ACCESS
METHODS
 An indexed access method can be easily built on top of a direct
access system.

 Used to search large files doing little I/O memory.

 multi-tiered indexing scheme, i.e. indexes of indexes.

 ISAM(indexed sequential access method) uses master index that


points to disk blocks of secondary index files which would point to
actual data items.

 The process include at most two direct access reads.


19

EXAMPLE OF INDEX AND RELATIVE FILES


20

DISK STRUCTURE
 A storage device(disk) can be used in its entirety for a file
system.

 Alternatively a physical disk can be broken up into


multiple partitions, slices, or mini-disks, each of which
becomes a virtual disk and can hold separate file
systems. ( or be used for raw storage, swap space, etc. )

 Or, multiple physical disks can be combined together into RAID


sets
.
 Entity containing file system known as a volume

 Each volume containing file system also contain information


about the files which is kept in device directory or volume
table of contents or directory
21

A TYPICAL FILE SYSTEM ORGANIZATION


22

FILE
special-purpose file SYSTEM
Along with general-purpose file systems there are many
systems, frequently all within the same
operating system or computer like:
TYPES
tmpfs —“temporary” file system in volatile main memory,
contents erased if the system reboots or crashes
objfs —a “virtual” file system (essentially an interface to the
kernel that looks like a file system) that gives debuggers access to
kernel symbols
Ctfs — a virtual file system that maintains “contract” information
to manage which processes start when the system boots and must
continue to run during operation
lofs—a “loop back” file system that allows one file system to be
accessed in place of another one
procfs—a virtual file system that presents information on all
processes as a file system
Ufs,zfs — general purpose file systems
23

Directory Overview
The directory can be viewed as a symbol table that translates file names
into their directory entries. The organisation of the directory must allow
us to perform many operations with these entries.
These include:

 Search for a file


 Create a file
 Delete a file
 List a directory
 Rename a file
 Traverse the file system
24

Single Level Directory


In this structure, all files are contained in the same single directory

Advantages:
 Easy to support, understand and maintain
 Convenient to implement for the developer due to its simple structure

Limitations:
 All files needs to be associated with a unique name to avoid name-space
collisions
 Keeping track of large number of files in this scheme becomes very difficult
and daunting
 Difficult to use for when multiple users are supported
 All in all, brings down user convenience
25

directory cat bo a test data mail count hex records

files

Single-Level directory
26

Two-Level Directory
In this view, each user has his own user file directory (UDF). The UDFs have
similar structures, but each lists only the files of a single user.
When a user first logs in, the system’s master file directory (MDF) is
searched. The MFD is indexed by user name or account number, and each entry
points to the UDF for that user.

(MDF) user1 user2 user3 user4

(UDF) cat bo a test a data a test x data a

files
27

Features of Two-Level Directory structure:

 Solves the problem of name-collision among different users


 Effectively isolates one user from another
Advantage:
ensures protection and privacy of files for each user, making each user
independent
Disadvantage:
makes working on cooperative tasks difficult as then each user have to
explicitly give the filename and the username, in whose UDF the file exists, to
access the file, and that too when the user has the required permissions.
28

Specifying a user name and a file name defines a path in the tree from the root
(MFD) to a leaf (the specified file). Thus, in this structure, a user name and a file
name defines a path name. Every file has a unique path name. To name a file
uniquely, one must know the path name of the desired file. E.g. if user2 wants to
access “data” in its own UFD, “data” is the path name while if he wants to
access “test” of user1, the path name becomes “/user1/test”. Path names are
relative to users.

In Windows, a volume is specified followed by a colon. E.g. C:\userb\test. UNIX


and Linux simply treat the volume name as a part of directory name.

Whenever a file needs to be executed, the current directory is searched first. If


found, it is used. Otherwise, the system automatically searches directories,
owned by special user, that contains system files and utilities like loaders,
compilers and command files like ls, cut, pwd, etc. The sequence of
directories searched when a file is named is called the search path.
29

In UNIX, search path of the kernel is saved in the environment variable “PATH”

When we talk about adding Java to the path of our system, it is to this
variable that we append the java file’s path name

path name for the command file “ls”


30
Tree-Structured Directories

In this structure, the users are allowed to make subdirectories within their own
UFDs. Therefore, improving organisation of files

root spell bin programs

stat mail dist find count hex reorder p e mail

prog copy prt exp reorder list find hex count

list obj spell all last first


Single An Example: UNIX file 31

system structure
/

bin boot dev etc home lib usr root mnt val
(MFD)

alice tanisha bob (UFDs)

Desktop Documents Downloads Pictures

File1.txt Project3.pdf

Here, “home” is the MFD while “tanisha” is one of the 3 UFDs.


When user logs in, the MFD is searched for a matching UFD entry
and access is granted if user is authenticated. The user’s current
directory is now its own UFD i.e., $HOME=“/home/tanisha/”
32

Current directory should contain most of the files that are of current interest of
the process. If a reference to a file is made, first “.” Is checked. If found, it is used.
Otherwise, the user must change directory or specify file’s path name. Path
name is the sequence of directories that needs to be traversed to get to
the desired file. It is of two types:

Absolute path name: path name begins at the root(MFD) and follows a path
down to the specified file, giving the directory names on the path. E.g. in the UNIX
example, absolute path to file “Project3.pdf” is
/home/tanisha/Documents/Project3.pdf

Relative path name: path name defined from the current directory. E.g. if
current directory (.) is Downloads then , relative path to “Project3.pdf” is
../Documents/Project3.pdf
33

Deletion of a directory in a tree structure can be done in several ways:


1. If the directory is empty, use “rmdir”

2. If the directory is not empty, then


• Contents can of the directory can be deleted manually and then rmdir can
be used to delete the now empty directory
• Else the deletion can be done in one step, by using recursive option of rm
i.e. “rm –r mydir”
Acyclic-Graph Directories
A tree structure prohibits the sharing of files or directories. An acyclic graph-i.e.
A graph with no cycles- allows implementation of shared files and dirs. The
acyclic graph is a natural generalisation of the tree-structured directory
scheme.
root dict spell

list all w count count words list

list rade w7
35

A shared file is different from having copies of the same file.

Working with copies, changes made into one is not reflected on others. With
shared files, only one actual file exist. So any changes made by one user is
immediately visible to others, therefore, making working on projects easier.

Shared files can be implemented using links. There are two types of links in
UNIX:

Hard Link: hard links to a files are actually dynamic copies of a file such that
whenever any changes are made, it adopts the same. They share the same
inode number as the original file.

Symbolic/soft links: symbolic links are pointers to a file. They can be thought
of as aliases of a file.

In UNIX/Linux, links can be made using the “ln” command


36

Link count
File type

Link count is the number of hard links to a file, including the original.

orphan link
37
Difference between hard link and symbolic link
 Deleting the original file doesn’t  Deleting the original file cause
affect the hard link and it the symbolic link to become
preserves its contents orphan. Therefore, results in
dangling pointers
  Deleting the original file is
When hard link exists, then to
truly delete a file, one must enough to delete desired
delete the original file and all of contents. However, these
its hard links. Bring down link dangling pointers must be
count to 0 to deallocate handled to prevent problems
memory

symbolic links can be deleted using “unlink”


38

PROTECTION
• prevention of improper or illegal access of data/files
• Protection Mechanism provides controlled access by limiting the types of files
access that can be made

Types of Accesses:

Read – read from the file


Write – write or rewrite the file
Execute - load the file into the memory and execute it
Append – write new info. at the end of the file
Delete – delete the file and free space for possible use
List – list the name and attributes of the file
39

ACCESS CONTROL
• access dependant on the identity of the user
• Access Control List – list specifying user names
and type of access allowed for each user , associated with
each file and directory

Advantages :
1. enables complex methodologies

Disadvantages:
1. tedious
2. directory entry of variable size – more complicated
space management
40

Three Classifications of Users :

1. Owner : the user who created the file

2. Group : a set of users who are sharing a file and need similar
access

3. Universe : all other users present in the system

Mostly these days a combination of access-control lists and


owner , group and universe access-control scheme is
used
this method also suffers from some disadvantages
41

Example
 Sara is writing a new book
 hires three graduate students Jill , Dawn and Jill
 text of the book kept in file named ‘book.tex’

 Sara should be able to invoke all the


operations on the file
 Jim , Dawn and Jill should be allowed to
read and write to the file and not delete
it
 All other users should only be able to
read the file
 so Sara creates a group ‘text’ with
members Jim , Dawn and Jill
Associates it with ‘book.txt’ and gives the group permissions
to read and write to the file

 But now suppose Sara wants some other


user to read Chapter 1. She cannot add
42

UNIX/LINUX
• three fields of 3 bits each
r – read access
w -write access
x -execution
R W X

Owner 7 >> 1 1 1

1 1 0
Group
6 >>
0 0 1
Universe 1 >>
43

• Windows
manages
access control
list via GUI

Windows 7
access
control list
management
44

OTHER PROTECTION
APPROACHES
• associate Password with each file
• Effective in limiting access to a file – password chosen
randomly and changed often
Disadvantages:
1. User needs to remember a large number of passwords
2. If only one password is used then, all files become accessible
once it is discovered.
• as a solution to this problem , many systems allow
users to associate password with a subdirectory than a
individual file

You might also like