FILES
PREPEARED BY- BIBHUDENDRA SARANGI
What are files?
𝗈 In general, a file is a sequence of bits, bytes, lines or
records whose meaning is defined by the files
creator and user.
The file can be indexed, structured, etc. The file is an entry in a directory.
The file may have attributes (name, creator, date, type, permissions).
𝗈
𝗈
𝗈
File structure
𝗈 File structure is a structure, which is according to a
required format that operating system can
understand.
𝗈 A file has a certain defined structure according to its type.
𝗈 A text file is a sequence of characters organized into lines.
𝗈 A
source file is a sequence of procedures and
functions.
𝗈 An object file is a sequence of bytes organized into blocks that are understandable by the machine.
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
𝗈 Write
𝗈 Read
𝗈 Reposition within file
𝗈 Delete
𝗈 Truncate
File types
Functions of file system
𝗈 File system in OS provide the way to create and access the files.
𝗈 How the memory is allocated to files and how the addresses are saved regarding to each file.
File access methods
𝗈 File access refers to the manner in which the records of a file may be accessed.
𝗈
Sequential access
𝗈 A sequential access is that in which the records are accessed in some sequence i.e the information in the file is processed in order, one record after the other.
𝗈 This access method is the most common one.
𝗈 Example: Compilers usually access files in this fashion.
𝗈 Retrieving from sequential file:
𝗈 Appending a sequential file:
The append operation refers to adding more records to an existing file.
The following operations are done for the purpose of appending a file.
➢
➢
➢
➢
Read the file till EOF is encountered. Read the data to be added.
Write the data on the file. Close the file.
Direct / random access
𝗈 Random access file organization provides, accessing the records directly.
𝗈 Each record has its own address on the file with by the help of which it can be directly accessed for reading or writing.
𝗈 The records need not be in any sequence within the file and they need not be in adjacent locations on the storage medium.
𝗈 Method useful for disks.
𝗈 There are no restrictions on which blocks are read/written in any order.
𝗈 User now says "read n" rather than "read next".
Indexed sequential access
𝗈 This approach combines the advantages of both sequential and direct file access.
𝗈 An index is created for each file which contains pointers to various blocks.
𝗈 Index is searched sequentially and its pointer is used to access the file directly.
Example to understand Indexed Sequential Access
(Prime Area)
File allocation methods
𝗈 Files are allocated disk spaces by operating system.
𝗈 Allocation methods are for
𝗈 Operating systems deploy following three main
ways to allocate disk space to files.
Contiguous allocation
𝗈 Each file occupies a set of contiguous blocks on the disk.
𝗈 Simple – only starting location (block ) and length (number of blocks) are required.
𝗈 Random access.
𝗈 Can be used for both sequential and direct files.
Example:
𝗈 If file is n block long and starts at location b, then, the blocks occupied are b, b+1, b+2…..b+n-1 .
𝗈 The directory entry for file has
problems
𝗈
Finding space for a new file or a resized file.
𝗈 Determining size requirements.
𝗈 External fragmentation of the hard disk.
Linked allocation
𝗈 Each file is a linked list of disk blocks, scattered anywhere on the disk.
𝗈 Directory contains link / pointer to first block of a file.
𝗈 There's no external fragmentation since each request is for one block.
𝗈 Method can only be effectively used for sequential files.
𝗈 This method is inefficient for direct files.
EXAMPLE
Indexed allocation
𝗈 Provides solutions to problems of contiguous and linked allocation.
𝗈 A index block is created having all pointers to files.
𝗈 Each file has its own index block which stores the addresses of disk space occupied by the file.
𝗈 Directory contains the addresses of index blocks of files.
example
𝗈 Method suffers from wasted space since, for small files, most of the index block is wasted
𝗈 If the index block is too small, we can:
➢
Link several together Use a multilevel index Combined scheme
➢
➢
protection
𝗈 We want to keep our information safe from physical damage(reliability) and improper access(protection).
𝗈 We can protect our information by controlled access.
𝗈 Types of access
Access control
𝗈 This is the most common approach.
𝗈 ALCs(access control lists) are maintained.
𝗈 The main problem of ALCs is their length.
𝗈 The technique has two undesirable consequences:
𝗈 This problem can be resolved by using condense access list.
𝗈 Three classifications of users is defined:
𝗈 Eg. UNIX system defines three fields i.e. rwx
𝗈 DIFFICULTY: assigning the precedence when permission and ACLs conflict.
Other methods of protection
𝗈 PROTECTION THROUGH PASSWORD:
Thank you