523354 OPERATING SYSTEMS File Management •
• • • • • • • • • •
File Systems File Attributes File Operations File Types File Structure Access Methods Directory Structure File Sharing Protection File-System Implementation Allocation Methods
File Systems
A file is
Contiguous logical address space Managed by
◦ OS ◦ Program
Logical address is the address generated by the CPU exchange info Physical address is the actual address of the process in the memory.
File Systems
Files represent ◦ programs Source object forms ◦ Data files numeric, alphabetic, alphanumeric, or binary ◦ Free form text files Formatted file
Many different types of information may be stored in a file 1. text file
1.
source file ◦ is a sequence of subroutines and functions, each of which is further organized as declarations followed by executable statements
2.
object file
3.
executable file ◦ is a series of code sections that the loader can bring into memory and execute.
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 Information about files are kept in the directory structure, which is maintained on the disk
File Operations
Create ◦ Step1 : ◦ Step2 :
Write
Read ◦ Use a system call that specifies the name of the file and where (in memory) the next block of the file should be put.
Reposition within file – file seek ◦ Move pointer to new location
Delete ◦ Release all file space
Truncate ◦ Erase the contents of a file but keep its attributes
Open(Fi)
Close (Fi)
Example: Unix open() int open(char *path, int flags [, int mode]) path is name of file flags is bitmap to set switch
◦ O_RDONLY, O_WRONLY… ◦ O_CREATE then use mode for perms
On success, returns index
Several pieces of information are associated with an open file ◦ File pointer: pointer to last read/write location
◦ 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: Identify a disk location when a modification occurred with a file cache of data access information
◦ Access rights: per-process access mode information OS decides
File Types – Name, Extension
Filename.extension
File Structure
An OS ◦ Have to understand a file structure for processing ◦ supported file structures. Executable File – run program
Access Methods
Access methods determine the way that files are accessed and read into memory. Sequential Access
Access Methods
Direct Access
Sequential Access read next write next reset no read after last write (rewrite) Direct Access read n write n position to n read next write next rewrite n n = relative block number
Simulation of Sequential Access on Direct-access File
Access Methods
Index and Relative Files
Directory Structure
A collection of nodes containing information about all files.
Directory
Files
F1
F2
F3
F4 Fn
Both the directory structure and the files reside on disk. Backups of these two structures are kept on tapes.
Disk Structure
Partitions (or Volumes) – can be viewed as the abstraction of virtual disks.
Partitions can store multiple operating systems such that a system can boot more than one OS
Each partition contains information about files in a device directory, called directory
Each directory records file attribute information.
A Typical File-system Organization
Directory Design Goal To organize the logical structure to obtain:
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, …)
Directory Structure
Single-Level Directory ◦ The simplest solution
◦ Advantages Easy to support and understand. ◦ Disadvantages The naming problem The grouping problem
Directory Structure
Single-Level Directory
Two-Level Directory
◦ Advantages Solves the name-collision problem. Isolates users from one another a form of protection. Efficient searching. ◦ Disadvantages Restricts user cooperation. No logical grouping capability (other than by user).
Two-Level Directory
Tree-Structured Directories
◦ Advantages Efficient searching Grouping Capability ◦ Each process has a current directory (working directory)
Tree-Structured Directories
Tree-Structured Directories ◦ Absolute or relative path name ◦ Creating a new file is done in current directory. ◦ Delete a file rm ◦ Creating a new subdirectory is done in current directory. mkdir
Example: if in current directory /mail mkdir count mail prog
copy
prt exp count
Deleting “mail” deleting the entire subtree rooted by “mail”.
relative path name
Absolute path name
Acyclic-Graph Directories
New directory entry type ◦ Link – another name (pointer) to an existing file
Acyclic-Graph Directories
General Graph Directory
When links are added to an existing treestructured directory, a general graph structure can be created.
General Graph Directory
File Sharing
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
File Sharing 1.
Multiple Users ◦ User IDs identify users, allowing permissions and protections to be per-user ◦ Group IDs allow users to be in groups, permitting group access rights
2.
Remote File Systems Files are shared on network FTP, world wide web, distributed file systems Client-server model allows clients to mount remote file systems from servers NFS is standard UNIX client-server file sharing protocol CIFS is standard Windows protocol
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 RWX a) owner access 7 111 RWX b) group access 6 110 RWX c) public access 1 001 Ask manager to create a group (unique name), say G, and add some users to the group. For a particular file (say game) or subdirectory, define an appropriate access. owner
chmod
Attach a group to a file chgrp
group 761
G
public
game
game
Windows Access control List Management
A Sample UNIX Directory Listing Drwxr-xr-x DirectoryOwnerGroupOtheruser
File-System Implementation
File system resides on secondary storage (disks) File control block – storage structure consisting of information about a file Device driver controls the physical device Boot control block contains info needed by system to boot OS from that volume Per-file File Control Block (FCB) contains many details about the file
A Typical File Control Block
Allocation Methods
An allocation method refers to how disk blocks are allocated for files:
1.
Contiguous allocation
2.
Linked allocation
3.
Indexed allocation
Contiguous Allocation
Advantage
◦ Simple – only starting location (block #) and length (number of blocks) are required ◦ Provide a high efficiency for searching data
Disadvantage
◦ Wasteful of space (dynamic storage-allocation problem) ◦ Files cannot grow
CD (read only)
Linked Allocation
Advantage ◦ Simple – need only starting address ◦ Free-space management system – no waste of space
Disadvantage ◦ Spend more time for searching data ◦ Waste space to pointers block =
pointer
File-allocation table (FAT) ◦ disk-space allocation
Indexed Allocation I-nodes bring all the pointers together into one location
◦ index block.
Inside i-nodes, there are 4 block types 1. 2. 3. 4.
Direct blocks Single direct blocks Double direct blocks Triple direct blocks
File size <= 10 Kb ◦ Used only direct blocks 10 blocks ◦ 10 blocks : each blocks has 1 kb
File size > 10 kb and <= 266 kb ◦ Used direct blocks 10 blocks and Single direct blocks 1 block
◦ ◦ ◦ ◦
Single direct blocks = 1kb(1024 bytes) Links used per 4 bytes 1024/4 = 256 links 256 links can pointer to another 1 Kb block 10 kb + 256 kb = 266 kb
File size > 266 and <=65802 kb ◦ Used direct blocks 10 blocks, 1 Single direct block and 1 double direct block ◦ Double direct block : 256*256 blocks
File size > 65802 kb ◦ Used 1 Triple direct blocks
◦ Triple direct block : 256*256*256 blocks