View
185
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Rushdi Shams, Dept of CSE, KUET 1
Operating SystemsOperating SystemsFile SystemsFile Systems Version 1.0
Rushdi Shams, Dept of CSE, KUET 2
Introduction• Processes can store a limited amount of
information within its own address space.• For some applications this size is adequate
but for others (airline reservations, banking), the space is too small
Rushdi Shams, Dept of CSE, KUET 3
Introduction• Information stored must survive the
termination of the process using it. Typically, processes were designed in a way such that after their usage on variables, the values are lost when processes release them.
• Inappropriate for applications like database systems
Rushdi Shams, Dept of CSE, KUET 4
Introduction• Multiple processes must be able to access the
information concurrently. Truly speaking, while a process operates on an information, it was not accessible for others
Rushdi Shams, Dept of CSE, KUET 5
Introduction• So, we have three essential requirements for
long-term information storage-1. Store a large amount of information2. The information must be stored for a long
time3. Multiple processes must be able to access
the information concurrently• These requirements led us towards keeping
the information in files
Rushdi Shams, Dept of CSE, KUET 6
Introduction• Information in files must be persistent-
process termination and creation must not affect them
• Only the owner can modify/delete the information if she likes.
Rushdi Shams, Dept of CSE, KUET 7
File NamingWhen a process creates a file, it gives a file
nameWhen the process terminates, the file
continues to exist and can be accessed by other processes using its name.
Some file systems distinguish between upper and lower case letters, whereas others do not.
Are the file names cat.doc, cAt.doc, caT.doc and CAT.doc same in windows? What about in UNIX?
Rushdi Shams, Dept of CSE, KUET 8
File NamingMany OS support two-part file names- two
parts separated with a period (.). The part after the period is called file
extension. Filename extensions can be considered a type
of metadata. They are commonly used to infer information
about the way data might be stored in the file.
Rushdi Shams, Dept of CSE, KUET 9
File Structure
Generally, there are three kinds of files-1. Byte Sequence2. Record Sequence3. Tree Sequence
Rushdi Shams, Dept of CSE, KUET 10
File Types Generally, there are
two types of files-1. ASCII files2. Binary files
ASCII files are easy to understand if you use a text editor whereas binary files are completely glibberish if you print them
Rushdi Shams, Dept of CSE, KUET 11
File Access StrategiesSequential access
read all bytes/records from the beginningcannot jump around, could rewind or back up
Random accessbytes/records read in any orderessential for data base systemsread can be …
move file marker (seek), then read or … read and then move file marker
Rushdi Shams, Dept of CSE, KUET 12
File Access StrategiesThere are also several file usage patterns.Most files are small (e.g., .login and .c files),
and most file references are too small files.Large files use up most of the disk space
(e.g., mp3 files).Large files account for most of the bytes
transferred between memory and disk.
Rushdi Shams, Dept of CSE, KUET 13
File Access StrategiesThese usage patterns are bad news for file
system designers. To achieve high performance, a designer
needs to make sure that small files are accessed efficiently, since there are many of them, and they are used frequently.
A designer also needs to make sure that large files are accessed efficiently, since they consume most of the disk space, and account for most of the data movement.
Rushdi Shams, Dept of CSE, KUET 14
Directories To keep track of files, file systems normally
have directories or folders In many systems directories themselves are
files! Simply put, there are three types of
directory systems-1. Single-level directory systems2. Two-level directory systems3. Hierarchical directory systems
Rushdi Shams, Dept of CSE, KUET 15
Single-level directory systemSimplest form of directory
systemOne directory contains all
the filesSometimes called root
directoryGood choice when number
of user is only oneThe directory in figure has
two owners- A and B having four files
Problem- different users may accidentally use same names for their files
Rushdi Shams, Dept of CSE, KUET 16
Two-level directory systemEach user will have
separate directories containing their owned files
The problem with naming is resolved.
Log in procedure is required
May allow one user to access others’ files
Rushdi Shams, Dept of CSE, KUET 17
Hierarchical Directory SystemsThe problem of two-level
directory system is the absence of grouping facility
You may group your works like- games in one place, movies in the other.
Hierarchical directory systems have the facility of two-level directory systems plus the organization facility
Rushdi Shams, Dept of CSE, KUET 18
File System LayoutFile systems are stored on disksDisks are divided up into one or more
partitionsEach partition has independent file systemsSector 0 of the disk is called Master Boot
Record (MBR)Computer uses MBR to boot itselfThe end of MBR contains the partition table-
that has the start and end address of each partition
Rushdi Shams, Dept of CSE, KUET 19
File System LayoutOne of the partitions in the partition table is
marked as activeWhen computer is booted, the BIOS reads in
and executes MBRThe first thing MBR program does is to locate
the active partitionThe first block of this active partition is Boot
Block.MBR reads and executes it.The program in Boot Block loads the OS
contained in that partition
Rushdi Shams, Dept of CSE, KUET 20
File System LayoutEvery partition starts with a Boot BlockBut only the partition having the OS will be
marked as activeOther partitions hold the Boot Block as you
can change your mind and copy another version of the OS into one of them
Rushdi Shams, Dept of CSE, KUET 21
File System Layout
Rushdi Shams, Dept of CSE, KUET 22
File System Layout
Super Block contains all the key parameters about the file system
It is read into memory when the computer is booted or the file system is first touched
Typically holds a Magic Number to identify the file system type (.exe or .bmp?), number of blocks, etc
Rushdi Shams, Dept of CSE, KUET 23
File System Layout
Free space management reveals the free blocks in the file system
i-nodes is an array of data structures, one per file, simply telling about the file
Root directory contains the top of the file system treeRemainder of the disk contains all other directory and files
for that partition
Rushdi Shams, Dept of CSE, KUET 24
Implementing Files: Contiguous AllocationSimplest allocation scheme to store each file
as a contiguous run of disk blocksDisk with 1 KB blocks, a 50 KB file would
need 50 consecutive blocks; Disk with 2 KB blocks would make it okay with 25 consecutive blocks
Rushdi Shams, Dept of CSE, KUET 25
Implementing Files: Contiguous Allocation
Rushdi Shams, Dept of CSE, KUET 26
Implementing Files: Contiguous AllocationAdvantages
Simple to implement You only need to know the disk address of the first
block and the distance of the file block from itRead performance is excellent, as you need only
two seek operations (boot block and file block) and one read operation (one contiguous stream of bytes)
DisadvantagesDisks become fragmentedWastage of storage is possible
Rushdi Shams, Dept of CSE, KUET 27
Implementing Files:Linked List AllocationEvery block will have two sections- a pointer
to next one (the first word of the block) and data (the rest of the words)
Unlike contiguous allocation, every disk block can be used in this method
No space is lost due to disk fragmentation
Rushdi Shams, Dept of CSE, KUET 28
Implementing Files:Linked List AllocationReading a file sequentially is straight forward
but random access is slow.To get block n, the OS has to start at the
beginning and read the n-1 blocks prior to itOverhead due to pointer information
Rushdi Shams, Dept of CSE, KUET 29
Implementing Files:Linked List Allocation
Rushdi Shams, Dept of CSE, KUET 30
Linked List Allocation:using Table in MemoryThe disadvantages are eliminated by taking
the pointer word from each block and putting it into a table in memory
Such a table in main memory is called FAT (File Allocation Table)
Rushdi Shams, Dept of CSE, KUET 31
Linked List Allocation:using Table in Memory
Rushdi Shams, Dept of CSE, KUET 32
Linked List Allocation:using Table in MemoryEntire block is available for data (no pointer
information)Faster random accessThe primary disadvantage-
the table must be in memory all the time to make it work
a 20 GB disk and with 1 KB block size, the table needs 20 million entries one for each of 20 million blocks
each entry is 4 bytes longso, FAT will occupy 80 MB space in memory all
the time
Rushdi Shams, Dept of CSE, KUET 33
i-nodesIt is a data structure that lists the attributes
and disk addresses of the file’s blocksWith i-nodes, it is possible to find all the
blocks of a filei-nodes need only be in memory when the
corresponding file is openIf each i-node contains n-bytes and there are
k-files are opened at a time, that instant, kn-bytes are reserved in memory
Rushdi Shams, Dept of CSE, KUET 34
i-nodes
Rushdi Shams, Dept of CSE, KUET 35
i-nodesThis array is usually far smaller than the space
occupied by the FATTable for holding the linked list is proportional to
disk itself.If the disk has n blocks, the table needs n-entriesAs the disks grow, the table grows linearly with
themi-node requires an array whose size is
proportional to the maximum number of files that may be open at once (it does not matter if you have 1 petabyte HDD )
Rushdi Shams, Dept of CSE, KUET 36
i-nodesThe disadvantage is if you fix the size of i-
node and your files have a tendency to grow larger (obviously you cannot say your file will be always 6MB in size )