Chapter 12 - File management. After studying this chapter, you should be able to: Describe the basic concepts of files and file systems, understand the principal techniques for file organization and access, define B-trees, explain file directories, understand the requirements for file sharing,...
Trang 1Chapter 12 File Management
Dave Bremer Otago Polytechnic, N.Z.
Trang 2• Secondary Storage Management
• File System Security
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 3applications
important part of the OS to a user
– Long-term existence
– Sharable between processes
– Structure
Trang 4File Management
system utility programs that run as privileged applications
Trang 5Typical Operations
can be performed on files, typically:
Trang 7Fields and Records
– Basic element of data
– Contains a single value
– Characterized by its length and data type
– Collection of related fields
– Treated as a unit
Trang 8File and Database
• File
– Have file names
– Is a collection of similar records
– Treated as a single entity
– May implement access control mechanisms
– Collection of related data
– Relationships exist among elements
– Consists of one or more files
Trang 9File Management Systems
applications in the use of files
– The way a user or application accesses files
management software
Trang 10Objectives for a File Management System
• Meet the data management needs of the user
• Guarantee that the data in the file are valid
• Optimize performance
• Provide I/O support for a variety of storage
device types
• Minimize lost or destroyed data
• Provide a standardized set of I/O interface
routines to user processes
• Provide I/O support for multiple users (if needed)
Trang 11Requirements for a general purpose system
delete, read, write and modify files
other users’ files
accesses are allowed to the users’ files
the user’s files in a form appropriate to
the problem
Trang 12Requirements cont.
between files
recover the user’s files in case of damage
user’s files by using symbolic names
Trang 13Typical software
organization
Trang 15Basic File System
outside the computer system
memory
Trang 16Basic I/O Supervisor
Trang 18Access Method
applications and the file systems and
devices that hold the data
ways to access and process data for the device
Trang 19Elements of
File Management
Trang 20• Secondary Storage Management
• File System Security
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 21File Organization
structure of records
– Physical organization discussed later
accessed
Trang 22Criteria for File Organization
– Short access time
– Ease of update
– Economy of storage
– Simple maintenance
– Reliability
(e.g read-only CD vs Hard Drive)
– Some may even conflict
Trang 24mass of data and save it
fields
search
Trang 25The Sequential File
• Fixed format used for records
• Records are the same length
• All fields the same (order and
length)
• Field names and lengths are
attributes of the file
• Key field
– Uniquely identifies the record
– Records are stored in key
sequence
Trang 26Indexed Sequential File
• Maintains the key
characteristic of the
sequential file:
• records are organized in
sequence based on a key
field.
Two features are added:
• an index to the file to support
random access,
• and an overflow file
Trang 27Indexed File
different key fields
– May contain an exhaustive index that contains one entry for every record in the main file
– May contain a partial index
to the main file, all of the index files must be updated
Trang 28File Organization
address
– Directly access a block at a known address
– Key field required for each record
Trang 29Performance
Trang 30• Secondary Storage Management
• File System Security
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 31the files themselves
Trang 32Directory Elements: Basic Information
Trang 34Directory Elements:
Access Control Information
– The owner may be able to grant/deny access
to other users and to change these privileges.
– May include the user’s name and password for each authorized user.
– Controls reading, writing, executing,
transmitting over a network
Trang 35Directory Elements: Usage Information
• Date Created
• Identity of Creator
• Date Last Read Access
• Identity of Last Reader
• Date Last Modified
• Identity of Last Modifier
• Date of Last Backup
• Current Usage
– Current activity, locks, etc
Trang 36Simple Structure for a
Directory
information varies widely between
systems
file
– Sequential file with the name of the file
serving as the key
– Provides no help in organizing the files
– Forces user to be careful not to use the same name for two different files
Trang 37Operations Performed
on a Directory
number of operations including:
Trang 38Two-Level Scheme
for a Directory
directory
– Master directory contains entry for each user
– Provides address and access control
information
for that user
– Does not provide structure for collections of files
Trang 39Hierarchical, or Tree-Structured Directory
Trang 40file by following the directory path
– Duplicate filenames are possible if they have different pathnames
Trang 41Example of Tree-Structured Directory
Trang 42Working Directory
awkward and tedious
associated with a current or working
directory
– All file names are referenced as being relative
to the working directory unless an explicit full pathname is used
Trang 43• Secondary Storage Management
• File System Security
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 44File Sharing
shared among users
– Access rights
– Management of simultaneous access
Trang 45Access Rights
used by various systems
– often as a hierarchy where one right implies previous
– User may not even know of the files existence
– User can only determine that the file exists
and who its owner is
Trang 46Access Rights cont…
– The user can load and execute a program but cannot copy it
– The user can read the file for any purpose,
including copying and execution
– The user can add data to the file but cannot modify or delete any of the file’s contents
Trang 47Access Rights cont…
Trang 49Simultaneous Access
updated
during the update
for shared access
Trang 50• Secondary Storage Management
• File System Security
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 51Blocks and records
structured file
– But blocks are the unit for I/O with secondary storage
– Fixed length blocking
– Variable length spanned blocking
– Variable-length unspanned blocking
Trang 52Fixed Blocking
integral number of records are stored in a block
internal fragmentation
Trang 53Fixed Blocking
Trang 54Variable Length Spanned Blocking
packed into blocks with no unused space
– Continuation is indicated by a pointer to the successor block
Trang 55Variable Blocking:
Spanned
Trang 56Variable-length unspanned blocking
spanning
the inability to use the remainder of a
block if the next record is larger than the remaining unused space
Trang 57Variable Blocking:
Unspanned
Trang 58• File System Security
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 59Secondary Storage
Management
allocating blocks to files
– Space must be allocated to files
– Must keep track of the space available for allocation
Trang 60File allocation issues
space allocated at once?
‘portions’
– What size should be the ‘portion’?
keep track of the file portions?
Trang 61Preallocation vs Dynamic Allocation
time of creation
potential size of the file
run out of space
Trang 62Portion size
– Portion large enough to hold entire file is
allocated
– Allocate space one block at a time
of view of a single file, or the overall
system efficiency
Trang 63File Allocation Method
– contiguous,
– chained, and
– indexed.
Trang 64Contiguous Allocation
the time of creation
table
– Starting block and length of the file
– Need to perform compaction
Trang 65Contiguous File Allocation
Trang 66External fragmentation
Trang 67Chained Allocation
block in the chain
– Starting block and length of file
Trang 68Chained Allocation
Trang 69Chained Allocation
Consolidation
Trang 70Indexed Allocation
one-level index for each file
allocated to the file
number for the index
Trang 71Indexed Allocation
Method
– Fixed size blocks or
– Variable sized blocks
fragmentation
consolidation
Trang 72Indexed allocation with Block Portions
Trang 73Indexed Allocation with Variable Length Portions
Trang 74Free Space Management
so must the unallocated space
which blocks are available
to a file allocation table
Trang 75Bit Tables
bit for each block on the disk
Trang 76Chained Free Portions
by using a pointer and length value in
each free portion
Trang 77index table as it would for file allocation
basis of variable-size portions rather than blocks
– Thus, there is one entry in the table for every free portion on the disk.
for all of the file allocation methods
Trang 78Free Block List
sequentially
– the list of the numbers of all free blocks is maintained in a reserved portion of the disk
Trang 79• A collection of addressable sectors in secondary memory that an OS or application can use for
data storage.
• The sectors in a volume need not be
consecutive on a physical storage device;
– instead they need only appear that way to the OS or application
• A volume may be the result of assembling and merging smaller volumes.
Trang 80• Secondary Storage Management
• Unix File Management
• Linux Virtual File System
• Windows File System
Trang 81Access Control
the user is identified
– Granting access to files and applications (or denying)
Trang 82Access Matrix
Trang 83Access Control Lists
Trang 85• Secondary Storage Management
• File System Security
• Linux Virtual File System
• Windows File System
Trang 86UNIX File Management
Trang 87information for a particular file
a single inode
– But an active inode is associated with only
one file, and
– Each file is controlled by only one inode
Trang 88Free BSD Inodes include:
Trang 89FreeBSD Inode and
File Structure
Trang 90File Allocation
– Blocks may not be contiguous
– Part of index stored in the file inode.
– And three indirect pointers
Trang 92UNIX File Access Control
Trang 93UNIX File
Access Control
Trang 94• Secondary Storage Management
• File System Security
• Unix File Management
• Windows File System
Trang 95Linux Virtual File System
processes
general feature and behavior
properties regardless of the target file
system
Trang 96Key ingredients of
VFS Strategy
• A user process issues
a file system call (e.g.,
read) using the VFS
file scheme.
– The VFS converts this
into an internal file
Trang 97The role of VFS within the Kernel
Trang 99• Secondary Storage Management
• File System Security
• Unix File Management
• Linux Virtual File System
Trang 100Windows File System
– Recoverability
– Security
– Large disks and large files
– Multiple data streams
– Journaling
– Compression and Encryption
Trang 101NTFS Volume and File Structure
– The smallest physical storage unit on the disk
– Almost always 512 bytes
Trang 102Efficient with Large Files
Trang 103NTFS Volume Layout
every file consists of a collection of
attributes
– Even the data contents of a file is treated as
an attribute.
Trang 104Windows NTFS Components