Docsity

Operating Systems basics document, Summaries of Operating Systems

Toggle sidebar
bg1
UNIT V: File Systems
1.
File Concept:
A file is a named collection of related information that is recorded on secondary storage.
A file contains either programs or data. A file has certain "structure" based on its type.
The information in a file is defined by its creator. Many different types of information may be
stored in a file—source or executable programs, numeric or text data, photos, music, video,
and so on
Example: text file, source file, executable file
1.1 File Attributes: A file is named, and is referred to by its name.
• 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 (ACL) – 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
• 1.2: File Operations: File is an abstract data type
Basic six operations on files:
– Creating a file
– Writing a file
– Reading a file
– Repositioning within a file Deleting a file
– Truncating a file
1.3 File Types – Name, Extension
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f

Partial preview of the text

Download Operating Systems basics document and more Summaries Operating Systems in PDF only on Docsity!

UNIT V: File Systems

1. File Concept: A file is a named collection of related information that is recorded on secondary storage. A file contains either programs or data. A file has certain "structure" based on its type. The information in a file is defined by its creator. Many different types of information may be stored in a file—source or executable programs, numeric or text data, photos, music, video, and so on Example: text file, source file, executable file 1.1 File Attributes: A file is named, and is referred to by its name. - 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 (ACL) – 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

  • 1.2: File Operations: File is an abstract data type Basic six operations on files:
  • Creating a file
  • Writing a file
  • Reading a file
  • Repositioning within a file Deleting a file
  • Truncating a file 1.3 File Types – Name, Extension

1.4 File Structure: 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. When an operating system defines different file structures, it also contains the code to support these file structure. Unix, MS-DOS support minimum number of file structure.

2. Access Methods: Files stores information, this information must be accessed and read into computer memory. There are so many ways that the information in the file can be accessed. I). Sequential Access Information in the file is processed in order i.e. one record after the other. Magnetic tapes are supporting this type of file accessing. Eg : A file consisting of 100 records, the current position of read/write head is 45 th^ record, suppose we want to read the 75th record then, it access sequentially from 45,46, 47…….. 74, 75. So the read/write head traverse all the records between 45 to 75.

Fig: File system organization: Directory OPERATION ON THE DIRECTORIES:

  1. Search for a file : Search a directory structure for required file.
  2. create file: New files need to be created, added to the directory.
  3. Delete file: When a file is no longer needed, we want to remove it from the directory.
  4. List a directory: We can know the list of files in the directory.
  5. Rename a file: Whenever we need to change the name of the file, we can change the name.
  6. Traverse the file system: We need to access every directory and every file within a directory structure we can traverse the file system The various directory structures are , Single Level Directory Two Level Directory Tree structured directory Single Level Directory The directory system having only one directory, it consisting of all files, it is said to be root directory.

Characteristics: If the sizes of the files are very small, then the searching becomes faster.

  • File creation, searching, deletion is very simple since we have only one directory.
  • We cannot have two files with the same name.
  • The directory may be very big therefore searching for a file may take so much time.
  • Protection cannot be implemented for multiple users.
  • There are no ways to group same kind of files. Two Level Directory In two level directory systems, we can create a separate directory for each user. There is one master directory which contains separate directories dedicated to each user. For each user, there is a different directory present at the second level, containing group of user's file. The system doesn't let a user to enter in the other user's directory without permission. Characteristics:
  • Each files have a path name as /User-name/directory-name/
  • Different users can have the same file name.
  • Searching becomes more efficient as only one user's list needs to be traversed.
  • The same kind of files cannot be grouped into a single directory for a particular use Tree structured directory
  • In Tree structured directory system, any directory entry can either be a file or sub directory.
  • Tree structured directory system overcomes the drawbacks of two level directory system.
  • The similar kind of files can now be grouped in one directory.

5. File system structure: Disk provides the bulk of secondary storage on which a file system is maintained. They have 2 characteristics that make them a convenient medium for storing multiple files. 1. A disk can be rewritten in place. It is possible to read a block from the disk, modify the block, and write it back into same place. 2. A disk can access directly any block of information it contains. Fig: layered file system File systems organize storage on disk drives, and can be viewed as a layered design: At the lowest layer are the physical devices, consisting of the magnetic media. I/O Control consists of device drivers , special software programs. The basic file system level works directly with the device drivers in terms of retrieving and storing raw blocks of data. The file organization module knows about files and their logical blocks, and how they map to physicalblocks on the disk The logical file system deals with all of the meta data associated with a file (UID, GID, mode, dates, etc.).

File-System Implementation File systems store several important data structures on the disk: A Boot Control Block (per volume) can contain information needed by the system to boot an OS from that volume. If the disk does not contain an OS, this block can be empty. A Volume Control Block (per volume) contains volume (or partition) details, such as number of blocks in the partition, size of the blocks, a free block, count and free block pointers, free FCB count, FCB pointers. A Directory Structure (per file system) is used to organize the files. A PER-FILE FCB contains many details about the file. Fig: A typical file-control block. There are also several key data structures stored in memory: An in-memory mount table. An in-memory directory cache of recently accessed directory information A system-wide open file table , containing a copy of the FCB for every currently open file in thesystem, as well as some other related information

A key-value pair for each file in the directory gets generated and stored in the hash table. The key can be determined by applying the hash function on the file name while the key points to the corresponding file stored in the directory A hash table can also be used to speed up searches. Hash tables are generally implemented in addition to a linear or other structure

7. Allocation Methods: An allocation method refers to how disk blocks are allocated for files. They are 1. Contiguous allocation 2. Linked allocation 3. Indexed allocation Contiguous allocation:

  • each file occupies set of contiguous blocks
  • Provides efficient direct access.
  • Simple – only starting location (block #) and length (number of blocks) are required
  • Both sequential and direct access can be supported
  • First fit and best fit are the most common used strategies.
  • External fragmentation can be a problem
  • Best performance in most cases Problems include finding space for file, knowing file size, external fragmentation, need for compaction off-line ( downtime ) or on-line. 2 Linked Allocation
  • Each file is a linked list of fixed-size disk blocks.
  • Blocks may be scattered anywhere on the disk.
  • Allocate blocks as needed as the file grows, wherever they are available on the disk
  • The directory contains a pointer to the first and last blocks of the file.
  • Each block contains a pointer to the next block (not accessible by users)
  • No external fragmentation. Any free block can be used to satisfy a request for more space.
  • Pointers saved in the blocks consume some space
  • Use of clusters (a set of blocks which the system deals with as a unit) Decreases overhead of pointers (4 blocks = 1 cluster needs 1 ptr) Increases throughput (fewer head seeks). Increases internal fragmentation.
  • Reliability: if a pointer is lost, blocks (clusters) can’t be traversed 3. Indexed Allocation
  • Each file has its own index block, which is an array of disk-block addresses
  • The directory contains the address of the index block, from which the ith^ block can be accessed directly
  • More efficient direct access than linked allocation.
  • No external fragmentation. Any free block can be used to satisfy a request for more space.
  • Suffers from a wasted space due to the use of index block. (pointer overhead is larger)
  • Linked scheme: use one block. To allow larger files, link several index blocks
  • Multilevel index: use a first-level index block to point to a second-level index blocks
  • Combined scheme: used in UNIX.

Fig: Linked free-space list on disk. Grouping

  • Modify linked list to store address of next n- 1 free blocks in first free block, plus a pointer to next block that contains free-block-pointers (like this one) Counting
  • Because space is frequently contiguously used and freed, with contiguous- allocation allocation, extents, or clustering.
  • Keep address of first free block and count of following free blocks.
  • Free space list then has entries containing addresses and counts

14.2 Principles of Protection

  • The principle of least privilege dictates that programs, users, and systems be given just enough privileges to perform their tasks.
  • This ensures that failures do the least amount of harm and allow the least of harm to be done.
  • For example, if a program needs special privileges to perform a task, it is better to make it a SGID program with group ownership of "network" or "backup" or some other pseudo group, rather than SUID with root ownership. This limits the amount of damage that can occur if something goes wrong.
  • Typically each user is given their own account, and has only enough privilege to modify their own files.
  • The root account should not be used for normal day to day activities - The System Administrator should also have an ordinary account, and reserve use of the root account for only those tasks which need the root privileges 14.3 Domain of Protection
  • A computer can be viewed as a collection of processes and objects ( both HW & SW ).
  • The need to know principle states that a process should only have access to those objects it needs to accomplish its task, and furthermore only in the modes for which it needs access and only during the time frame when it needs access.
  • The modes available for a particular object may depend upon its type. 14.3.1 Domain Structure
  • A protection domain specifies the resources that a process may access.
  • Each domain defines a set of objects and the types of operations that may be invoked on each object.
  • An access right is the ability to execute an operation on an object.
  • A domain is defined as a set of < object, { access right set } > pairs, as shown below. Note that some domains may be disjoint while others overlap.

Figure 14.1 - System with three protection domains.

  • The association between a process and a domain may be static or dynamic. o If the association is static, then the need-to-know principle requires a way of changing the contents of the domain dynamically. o If the association is dynamic, then there needs to be a mechanism for domain switching.
  • Domains may be realized in different fashions - as users, or as processes, or as procedures. E.g. if each user corresponds to a domain, then that domain defines the access of that user, and changing domains involves changing user ID. 14.3.2 An Example: UNIX
  • UNIX associates domains with users.
  • Certain programs operate with the SUID bit set, which effectively changes the user ID, and therefore the access domain, while the program is running. ( and similarly for the SGID bit. ) Unfortunately this has some potential for abuse.
  • An alternative used on some systems is to place privileged programs in special directories, so that they attain the identity of the directory owner when they run. This prevents crackers from placing SUID programs in random directories around the system.
  • Yet another alternative is to not allow the changing of ID at all. Instead, special privileged daemons are launched at boot time, and user processes send messages to these daemons when they need special tasks performed. 14.3.3 An Example: MULTICS
  • The MULTICS system uses a complex system of rings, each corresponding to a different protection domain, as shown below:

o If i > b2, then the call is allowed only if i <= b3 and the call is directed to one of the entries on the list of gates.

  • Overall this approach is more complex and less efficient than other protection schemes. 14.4 Access Matrix
  • The model of protection that we have been discussing can be viewed as an access matrix, in which columns represent different system resources and rows represent different protection domains. Entries within the matrix indicate what access that domain has to that resource. Figure 14.3 - Access matrix.
  • Domain switching can be easily supported under this model, simply by providing "switch" access to other domains:

Figure 14.4 - Access matrix of Figure 14.3 with domains as objects.

  • The ability to copy rights is denoted by an asterisk, indicating that processes in that domain have the right to copy that access within the same column, i.e. for the same object. There are two important variations: o If the asterisk is removed from the original access right, then the right is transferred, rather than being copied. This may be termed a transfer right as opposed to a copy right. o If only the right and not the asterisk is copied, then the access right is added to the new domain, but it may not be propagated further. That is the new domain does not also receive the right to copy the access. This may be termed a limited copy right, as shown in Figure 14. below: