The File Concept-Operating Systems-Lecture Notes, Study notes of Operating Systems

Operating Systems is necessary course in Computer Science. Its about threading, process scheduling, deadlocks, memory management etc. This lecture includes: File, Operating, Concept, Syste, Type, Operation, Access, Structure, Directory, Data, Storage

Typology: Study notes

2011/2012

Uploaded on 08/06/2012

sarang
sarang 🇮🇳

4.5

(47)

86 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
214
Operating Systems Lecture No.42
Operating Systems
Lecture No. 42
Reading Material
Chapter 11 of the textbook
Lecture 42 on Virtual TV
Summary
File Concept
File Types
File Operations
Access Methods
Directories
Directory Operations
Directory Structure
The File Concept
Computers can store information on several different storage media, such as magnetic
disks, magnetic tapes and optical disks. The operating system abstracts from the physical
properties of its storage devices to define a logical storage unit (the file). Files are
mapped by the OS onto physical devices. These storage devices are usually non-volatile,
so the contents are persistent through power failures, etc. A file is a named collection of
related information that is recorded on secondary storage. Data cannot be written to
secondary storage unless they are within a file. Commonly, files represent programs
(source and object forms) and data. Data files may be numeric, alphabetic, alphanumeric
or binary. In essence it is a contiguous logical address space.
File Structure
A file has certain defined structure characteristics according to its type. A few common
types of file structures are:
N
No
on
ne
e – file is a sequence of words, bytes
S
Si
im
mp
pl
le
e
r
re
ec
co
or
rd
d
s
st
tr
ru
uc
ct
tu
ur
re
e
Lines
Fixed length
Variable length
C
Co
om
mp
pl
le
ex
x
S
St
tr
ru
uc
ct
tu
ur
re
es
s
Formatted document
Relocatable load file
UNIX considers each file to be a sequence of bytes; no interpretation of these bytes is
made by the OS. This scheme provides maximum flexibility but little support. Each
application program must include its own code to interpret an input file into the
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download The File Concept-Operating Systems-Lecture Notes and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems Lecture No.

Operating Systems

Lecture No. 42

Reading Material

 Chapter 11 of the textbook  Lecture 42 on Virtual TV

Summary

 File Concept  File Types  File Operations  Access Methods  Directories  Directory Operations  Directory Structure

The File Concept

Computers can store information on several different storage media, such as magnetic disks, magnetic tapes and optical disks. The operating system abstracts from the physical properties of its storage devices to define a logical storage unit (the file). Files are mapped by the OS onto physical devices. These storage devices are usually non-volatile, so the contents are persistent through power failures, etc. A file is a named collection of related information that is recorded on secondary storage. Data cannot be written to secondary storage unless they are within a file. Commonly, files represent programs (source and object forms) and data. Data files may be numeric, alphabetic, alphanumeric or binary. In essence it is a contiguous logical address space.

File Structure

A file has certain defined structure characteristics according to its type. A few common types of file structures are: NNoonnee – file is a sequence of words, bytes SSiimmppllee rreeccoorrdd ssttrruuccttuurree Lines Fixed length Variable length CCoommpplleexx SSttrruuccttuurreess Formatted document Relocatable load file

UNIX considers each file to be a sequence of bytes; no interpretation of these bytes is made by the OS. This scheme provides maximum flexibility but little support. Each application program must include its own code to interpret an input file into the

appropriate structure. However all operating systems must support at least one structure- that of an executable file-so that the system is able to load and run programs.

File Attributes

Every file has certain attributes, which vary from one OS to another, but typically consist of these: Name: The symbolic file name is the only information kept in human-readable form Type: This information is needed for those systems that support different types. Location: This location 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. Protection: Access control information determines who can do reading , writing, etc. Owner Time and date created: useful for security, protection and usage monitoring. Time and date last updated: useful for security, protection and usage monitoring. Read/write pointer value

Where are Attributes Stored? File attributes are stored in the directory structure, as part of the ddiirreeccttoorryy eennttrryy for a file, e.g., in DOS, Windows, or in a separate data structure; in UNIX/Linux this structure is known as the ininooddee for the file.

Directory Entry

A file is represented in a directory by its directory entry. Contents of a directory entry vary from system to system. For example, in DOS/Windows a directory entry consists of file name and its attributes. In UNIX/Linux, a directory entry consists of file name and inode number. Name can be up to 255 characters in BSD UNIX compliant systems. Inode number is used to access file’s inode. The following diagrams show directory entries for DOS/Windows and UNIX/Linux systems.

DO DOSS//WWiinnddoowwss

UUNNIIXX//LLiinnuuxx

File Operations

Various operations can be performed on files. Here are some of the commonly supported operations. In parentheses are written UNIX/Linux system calls for the corresponding operations.

FAT

Poi

File Name Date

Inode Number

File Name

The following tables shows some of the commonly supported file extensions on different operating systems.

Common file types

File Types in UNIX

UNIX does not support supports seven types of file:  Ordinary file : used to store data on secondary storage device, e.g., a source program(in C), an executable program. Every file is a sequence of bytes.  Directory : contains the names of other files and/or directories.  Block-special file : correspond to block oriented devices such as a disk. They are used to access such hardware devices.  Character-special file : correspond to character oriented devices, such as keyboard  Link file (created with the ln –s command): is created by the system when a symbolic link is created to an existing file, allowing you to rename the existing file and share it without duplicating its contents without  FIFO (created with the mkfifo or mknod commands or system calls): enable processes to communicate with each other. A FIFO(name pipe) is an area in the kernel that allows two processes to communicate with each other provided they are running on the same system , but the processes do not have to be related to each other.  Socket (in BSD-compliant systems—socket): can be used by the process on the same computer or on different computers to communicate with each other.

File Access

FFiilleess ssttoorree iinnffoorrmmaattiioonn tthhaatt ccaann bbee aacccceesssseedd iinn sseevveerraall wwaayyss::

SSeeqquueennttiiaall AAcccceessss Information in the file is processed in order, one record after the other. A read operation reads the next potion of the file and automatically advances a file pointer which tracks the I/O location. Similarly, a write operation appends to the end of the file and advances to the end of the newly written material. Such a file can be rest to the beginning and on some systems; a program may be able to skip forward or backward, n records.

Sequential Access File

DDiirreecctt AAcccceessss A file is made up of fixed length logical record that allow program to read and write records in no particular order. For the direct-access method, the file operations must be modified to include the block number as a parameter (read n (n = relative block number), write n for instance). An alternate approach is to retain read next and write next and to add an operation, position file to n , where n is the block number. The block number provided by the user to the OS is normally a relative block number , an index relative to the beginning of the file.

Sequential Access on a Direct Access File

Directory Structure

It is a collection of directory entries. To manage all the data, first disks are split into one or more partitions. Each partition contains information about files within it. This information is kept within device directory or volume table of contents.

F 1 F 2 F 3 F 4 F n

Directory

Files and Directories

When a user refers to a particular file, only his own user file directory (UFD) is searched. Thus different users can have the same file name as long as the file names within each UFD are unique. This directory structure allows efficient searching. However, this structure effectively isolates one user from another, hence provides no grouping capability.

Tree Directory Here is the tree directory structure. Each user has his/her own directory (known as user’s home directory) under which he/she can create a complete directory tree of his/her own.

Tree directory structure

The tree has a root directory. Every file in the system has a unique pathname. A path name is the path from the root, through al the subdirectories to a specified file. A directory/subdirectory contains a set of files or subdirectories. In normal use, each user has a current directory. The current directory should contain most of the files that are of current interest to the user. When a reference to a file is made, the current directory is searched. If a file is needed that is not in the current directory, then the user must either specify a path name or change the directory to the directory holding the file( using the cd system call).This structure hence supports efficient searching. Allowing the user to define his own subdirectories permits him to impose a structure on his files.A lso users can access files of other users.

UNIX / Linux Notations and Concepts  Root directory (/)  Home directory o ~, $HOME, $home o cd ~ o cd  Current/working directory ( .. ) o pwd  Parent of Current Directory ( .... )  Absolute Pathname o Starts with the root directory o For example, /etc, /bin, /usr/bin, /etc/passwd, /home/students/ibraheem  Relative Pathname

o Starts with the current directory or a user’s home directory o For example, ~/courses/cs604, ./a.out