Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Files and file allocation.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

More on File Management
File Systems.
Allocation Methods - Contiguous
ICS Principles of Operating Systems
Chapter 11: File System Implementation
Operating Systems File Systems CNS 3060.
File System Implementation
File System Implementation
Operating Systems File Systems (in a Day) Ch
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
File Systems Topics –File –Directory –File System Implementation Reference: Chapter 5: File Systems Operating Systems Design and Implementation (Second.
Chapter 12: File System Implementation
1 File Management in Representative Operating Systems.
1 Outline File Systems Implementation How disks work How to organize data (files) on disks Data structures Placement of files on disk.
File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Chapter 12: File System Implementation
Contiguous Allocation of Disk Space. Linked Allocation.
Chapter 5 Part 2 Secondary Storage Mgt. File Mgt. in Popular OSs
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
File Implementation. File System Abstraction How to Organize Files on Disk Goals: –Maximize sequential performance –Easy random access to file –Easy.
Operating Systems CMPSC 473 I/O Management (4) December 09, Lecture 25 Instructor: Bhuvan Urgaonkar.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
Chapter 11: File System Implementation Hung Q. Ngo KyungHee University Spring 2009
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 11: File System Implementation.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
Chapter 11: File System Implementation Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 File-System Structure.
CSC 322 Operating Systems Concepts Lecture - 20: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CSCI-375 Operating Systems Lecture Note: Many slides and/or pictures in the following are adapted from: slides ©2005 Silberschatz, Galvin, and Gagne Some.
Chapter 11: Implementing File Systems Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 11: Implementing File Systems Chapter.
Dr. T. Doom 11.1 CEG 433/633 - Operating Systems I Chapter 11: File-System Implementation File structure –Logical storage unit –Collection of related information.
Silberschatz and Galvin  Operating System Concepts File-System Implementation File-System Structure Allocation Methods Free-Space Management.
Page 111/15/2015 CSE 30341: Operating Systems Principles Chapter 11: File System Implementation  Overview  Allocation methods: Contiguous, Linked, Indexed,
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
File System Implementation
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 11: File System Implementation.
Module 4.0: File Systems File is a contiguous logical address space.
10.1 CSE Department MAITSandeep Tayal 10 :File-System Implementation File-System Structure Allocation Methods Free-Space Management Directory Implementation.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 11 File-System Implementation Slide 1 Chapter 11: File-System Implementation.
Page 112/7/2015 CSE 30341: Operating Systems Principles Chapter 11: File System Implementation  Overview  File system structure – layered, block based.
CE Operating Systems Lecture 17 File systems – interface and implementation.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
Fall 2000M.B. Ibáñez Lecture 24 File-System III File System Implementation.
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
11.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 11.5 Free-Space Management Bit vector (n blocks) … 012n-1 bit[i] =  1  block[i]
Allocation Methods An allocation method refers to how disk blocks are allocated for files: Contiguous allocation Linked allocation Indexed allocation.
Chapter 5 Record Storage and Primary File Organizations
Operating Systems Files, Directory and File Systems Operating Systems Files, Directory and File Systems.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
Part III Storage Management
W4118 Operating Systems Instructor: Junfeng Yang.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 3.
File System Implementation
File-System Implementation
File System Structure How do I organize a disk into a file system?
Chapter 11: File System Implementation
Operating Systems (CS 340 D)
Filesystems.
Chapter 11: File System Implementation
Chapter 11: File System Implementation
Overview: File system implementation (cont)
File System Implementation
File-System Structure
Chapter 14: File-System Implementation
Chapter 11: File System Implementation
File Systems CSE 2431: Introduction to Operating Systems
Presentation transcript:

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Files and file allocation

Copyright ©: Nahrstedt, Angrave, Abdelzaher 2 What is an inode? An inode (index node) is a control structure that contains key information needed by the OS to access a particular file. Several file names may be associated with a single inode, but each file is controlled by exactly ONE inode. On the disk, there is an inode table that contains the inodes of all the files in the filesystem. When a file is opened, its inode is brought into main memory and stored in a memory-resident inode table. [classbook at pag.700]

Copyright ©: Nahrstedt, Angrave, Abdelzaher 3 Information in the inode

Copyright ©: Nahrstedt, Angrave, Abdelzaher 4 Directories In Unix a directory is simply a file that contains a list of file names plus pointers to associated inodes Inode table i1 i2 i3 i4 Name1 Name2 Name3 Name4 … Directory …

Copyright ©: Nahrstedt, Angrave, Abdelzaher 5 Directories DIR *opendir(const char *name); The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream. The stream is positioned at the first entry in the directory.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 6 Directories struct dirent *readdir(DIR *dir); The readdir() function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dir. It returns NULL on reaching the end-of- file or if an error occurred. The dirent structure is defined as follows: struct dirent { ino_t d_ino; /* inode number */ char d_name[256]; /* filename */ … };

Copyright ©: Nahrstedt, Angrave, Abdelzaher 7 Directories // error handling is not included! struct dirent *entry; DIR *dirp; dirp = opendir("."); while((entry = readdir(dirp)) != NULL) printf("%s\n",entry->d_name); closedir(dirp);

Copyright ©: Nahrstedt, Angrave, Abdelzaher 8 readdir() is not thread safe readdir() returns a pointer to a statically allocated structure; hence the returned pointer points to data which may be overwritten by another call to readdir() on the same directory stream. The data is not overwritten by another call to readdir() on a different directory stream. The reentrant version of readdir() is: int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); pointer to storage allocated by the user

Copyright ©: Nahrstedt, Angrave, Abdelzaher 9 UNIX file structure implementation Each user has a "file descriptor table“. Each entry in the "file descriptor table" is a pointer to an entry in the system-wide "open file table" Each entry in the open file table contains a file offset (file pointer) and a pointer to an entry in the "memory-resident i- node table" If a process opens an already-open file, a new open file table entry is created (with a new file offset), pointing to the same entry in the memory-resident i-node table If a process forks, the child gets a copy of the "file descriptor table" (and thus the same file offset)

Copyright ©: Nahrstedt, Angrave, Abdelzaher 10 UNIX file structure implementation [figure from

Copyright ©: Nahrstedt, Angrave, Abdelzaher 11 File opening A call to open() creates a new entry (open file description) in the system-wide table of open files. This entry records the file offset and the file status flags. A file descriptor is a reference to one of these entries. The new open file description is initially not shared with any other process, but sharing may arise via fork.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 12 File Allocation on Disk Low level access methods for a file depend upon the disk allocation scheme used to store file data Contiguous Linked list Block or indexed

Copyright ©: Nahrstedt, Angrave, Abdelzaher 13 #1. Contiguous Allocation

Copyright ©: Nahrstedt, Angrave, Abdelzaher 14 Contiguous Allocation Issues Access method suits sequential and direct access Directory table maps files into starting physical address and length Easy to recover in event of system crash Fast, often requires no head movement and when it does, head only moves one track

Copyright ©: Nahrstedt, Angrave, Abdelzaher 15 Contiguous Allocation Issues File is allocated large contiguous chunks Expanding the file requires copying Dynamic storage allocation - first fit, best fit External fragmentation occurs on disk

Copyright ©: Nahrstedt, Angrave, Abdelzaher 16 External Fragmentation Solution: Linked allocation

Copyright ©: Nahrstedt, Angrave, Abdelzaher 17 #2. Linked Allocation

Copyright ©: Nahrstedt, Angrave, Abdelzaher 18 Linked List Allocation Each file is a linked list of nodes Pointers in list are not accessible to user Directory table maps files into head of list for a file A node in the list can be a fixed size physical block or a contiguous collection of blocks Easy to use - no estimation of size necessary

Copyright ©: Nahrstedt, Angrave, Abdelzaher 19 Linked List Allocation Can grow in middle and at ends Space efficient, little fragmentation Slow - defies the principle of locality. Need to read through linked list of nodes sequentially to find the needed blocks of data Suited for sequential access but not direct access

Copyright ©: Nahrstedt, Angrave, Abdelzaher 20 Linked List Allocation Issues Disk space must be used to store pointers (if disk block is 512 bytes, and disk address requires 4 bytes, then the user sees blocks of 508 bytes) Not very reliable. System crashes can scramble files being updated Important variation on linked allocation method: `file-allocation table' (FAT) - OS/2 and MS-DOS

Copyright ©: Nahrstedt, Angrave, Abdelzaher 21 Linked List Allocation Issues Summary: linked allocation solves the external fragmentation and size- declaration problems of contiguous allocation, However, it can't support efficient direct access

Copyright ©: Nahrstedt, Angrave, Abdelzaher 22 #3. Indexed Allocation

Copyright ©: Nahrstedt, Angrave, Abdelzaher 23 Indexed Allocation Solves external fragmentation Supports sequential, direct and indexed access Access requires at most one access to index block first. This can be cached in main memory

Copyright ©: Nahrstedt, Angrave, Abdelzaher 24 Indexed Allocation Requires extra space for index block, possible wasted space How to extend to big files? A file can be extended by using linked indexed files or multilevel indexed files

Copyright ©: Nahrstedt, Angrave, Abdelzaher 25 Linked Indexed Files Link full index blocks together using last entry.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 26 Multilevel Indexed File Multiple levels of index blocks

Copyright ©: Nahrstedt, Angrave, Abdelzaher 27 Layout of a UNIX file on disk File allocation is done on a block basis and allocation is dynamic (as needed). UNIX uses a multilevel indexing mechanism for file allocation on disk. Addresses of first 10 data blocks + 3 index blocks (first, second, and third level of indexing) In UNIX System V the length of a block is 1 Kbyte and each block can hold a total of 256 block addresses According to above parameters, maximum size for a file is slightly over 16Gbytes

Copyright ©: Nahrstedt, Angrave, Abdelzaher 28 Layout of a UNIX file on disk First ten addresses point to the first 10 data blocks of the file The inode includes 39 bytes of address information that is organized as thirteen 3-byte addresses