File Systems

30
File Systems CSCI 4534

description

File Systems. CSCI 4534. What is a file?. A file is information that is stored on disks or other external media. Why do we use files?. We often need for several applications or users to share data That data needs to be stored and retrieved. What is a file system?. - PowerPoint PPT Presentation

Transcript of File Systems

Page 1: File Systems

File Systems

CSCI 4534

Page 2: File Systems

What is a file?

• A file is information that is stored on disks or other external media

Page 3: File Systems

Why do we use files?

• We often need for several applications or users to share data

• That data needs to be stored and retrieved

Page 4: File Systems

What is a file system?

• The part of the operating system that deals with files is called a file system

• This section discusses how files are structured, named, accessed, used, protected, and implemented

Page 5: File Systems

File Systems

• Consist of two parts– A collection of files with stored data

– A directory structure• With organization of and information about

all the files in the system

• There may be a third part– Partitions which separate directories

Page 6: File Systems

File Concepts

• The Operating System provides a uniform logical view of how information is stored– Physical: stored on nonvolatile media– Logical: named collection of related data

• Types of files– Data: numeric, alphabetic, alphanumeric,

binary, ASCII– Programs: source, object, executable

Page 7: File Systems

File Concepts

• Meaning of a file is defined by the creator (or the user?)

• Files have structure according to their type– Text: sequence of characters organized into lines

– Source: sequence of subprograms consisting of data and instructions

– Object: sequence of bytes organized into blocks understandable by linker

– Executable: binary code and data to be loaded into memory

and executed

Page 8: File Systems

File Types

• Regular files: contain user information– ASCII – good for being edited with a text editor– Binary – have an internal structure that is

meaningful to the programs that use them

• Directories: system files for maintaining the structure of the file system

Page 9: File Systems

File Attributes

• Typical Attributes – see also Figure 6-4

– Name– Type– Location– Size – Protection and access control– Time, date and user ID: for creation, last

modification, last use

Page 10: File Systems

File Operations

• System calls are provided for:– Create a file: find space, add to directory

– Delete: release file space, delete dir entry

– Open: system fetches attributes and disk addresses

– Close: space is freed

– Read: name and location

– Write: name and data

– Append: add data to end of file

– Seek: repositions file pointer

Page 11: File Systems

File Operations

• Other operations– Get attributes: see Make p. 388

– Set attributes: e.g. protection modes

– Rename– Copy

Page 12: File Systems

File Operations

• Before files are used, an open( ) system call is usually made– Avoids searching for the file each time– O.S. keeps a table about all open files

• May have a count of users if shareable

– File name is associated with index into table, open( ) returns a pointer (we have seen an int)

– The open( ) call can specify access-mode information and can check for permissions

Page 13: File Systems

File Operations

• What happens when a file (such as in UNIX) is shared by several users?– The O.S. uses two tables

• A system-wide table: location, access dates, size

• A per-process table– Current file pointer for this process

– Each entry points to the system-wide table

Page 14: File Systems

File Types

• What file types should an O.S. recognize?– See types in Figure 6-1

• File names are followed by an extension– Extension specifies type of file and type of

operations that can be done on the file• .com, .bat, .exe can all be executed

• .asm is extension that an assembler is expecting

Page 15: File Systems

File Structure

• O.S.s may support different types of files– Some may support many or a few– However, all must support executable files

• Files can be seen as:– A sequence of 8-bit bytes

• no interpretation is made; flexible

– A sequence of records– A tree (see Figure 6-2)

Page 16: File Systems

File Structure

• How can a specific logical record in a file be found?

• Disk I/O uses blocks– All blocks are the same size– Logical records are packed into physical blocks– In UNIX, files are simply a stream of bytes– Those bytes are stored into a specific # of bytes

per block (eg. 512, 1024)

Page 17: File Systems

File Structure

• What determines how many logical records are in each block?– Logical record size– Physical block size

• A file, then, is a sequence of blocks– Some part of the last block is wasted (internal

fragmentation)

Page 18: File Systems

Access Methods

• Sequential Access– One record is processed after the other

• Examples: compilers, editors

• Mostly reading and writing is done

• Works on sequential-access devices and on random-access devices

– Operations: read next, write next

Page 19: File Systems

Access Methods

• Random Access– Records are accessed by key, not position– File seen as a #ed sequence of blocks or records– Useful in databases

• Provides immediate access to large amounts of data

– Where to start reading?• Each Read operation gives reading position• Or Seek finds the first position, then reads

sequentially from there

Page 20: File Systems

Directory Structure

• File systems are organized:– Disks are split into one or more partitions

• IBM calls them minidisks, others are called volumes• Usually each disk has a partition that stores files and

directories

– Each partition contains information about the files within it

• Called a device directory or a volume table of contents which holds the file attributes for files on this partition

Page 21: File Systems

Directory Structure

• The directory can be viewed as a symbol table– Translates file names onto directory entries

• What do we want to do with directories?– Search for a file– Create, delete– Rename, list files– Traverse the file system

Page 22: File Systems

Directory Structure

• Single-Level Directory– All files have unique names

• Two-Level Directory– Each user has a UFD (user file directory)– A higher-level MFD (master) is indexed by

user name or account number

Page 23: File Systems

Directory Structure

• Hierarchical Directories– Must specify pathname

• Absolute: begins at root

• Relative: begins at current directory

– Directory contains pointers to files (0) or subdirectory (1)

– Must have current directory, be able to change directories, be able to delete directories

– Allow access to other users’ files if given access

Page 24: File Systems

Directory Operations

• Create• Delete• Opendir• Closedir• Readdir• Rename• Link

Page 25: File Systems

File-System Implementation

• Layout (see Figure 6-11)

– Master Boot Record– Boot Block– Superblock

Page 26: File Systems

File-System Implementation

• Contiguous Allocation

• Linked List Allocation

• File Allocation Table

• I-nodes

Page 27: File Systems

Implementing Directories

• Directories provide information to find disk blocks– Disk address of file – contiguous – Number of the first block – linked list schemes– Number of the i-node

• Where are attributes stored?– In directory entry– In the i-nodes

• See Figure 6-17 for ways to handle long file names in directories

Page 28: File Systems

File Sharing

• Directed Acyclic Graph (DAG)

Page 29: File Systems

File Protection

• We want to keep information safe from:– physical damage (reliability)– improper access (protection)

• We need protection for these operations:– Read, write, execute, append, list, delete

Page 30: File Systems

File Protection

• Access control

• Use an access control list– specifies user name and types of access allowed– O.S. checks access list when a request is made– lists are tough to maintain

• Three classifications:– Owner, Group, Universe– Example of Sara