1 / 59

Subject Name: File Structures Subject Code: 10IS63

Subject Name: File Structures Subject Code: 10IS63. Engineered for Tomorrow. Chapter 1 Introduction Prepared By: Swetha G Department: Information Science & Engg Date : 02 / 02 / 2015. Overview What are File Structures? Why Study File Structure Design? Overview of File Structure Design.

cwoods
Download Presentation

Subject Name: File Structures Subject Code: 10IS63

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Subject Name: File Structures Subject Code: 10IS63 Engineered for Tomorrow

  2. Chapter 1 Introduction Prepared By: Swetha G Department: Information Science & Engg Date : 02 / 02 / 2015

  3. Overview • What are File Structures? • Why Study File Structure Design? • Overview of File Structure Design. • Introduction to secondary storage systems.

  4. Topics Covered • The Heart of the file structure Design • History of File Structures. • ConceptualTool kit using C++ • Physical Files and Logical Files • Fundamental File Operations • Secondary Storage and System Software • CD-ROM • Storage as Hierarchy

  5. The Chapter introduces to the file structures, the need and the design considerations. • Introduces the user to different basic file related operations • Discusses the various secondary storage devices • Strengths and weakness of storage devices. • Introduces to Buffers, its need and management.

  6. Definition • A File Structure is a combination of representations for data in files and operations for accessing the data. • A File Structure allows applications to read, write and modify data. • It might also support finding the data that matches some search criteria or reading through the data in some particular order.

  7. Why Study File Structure Design? • Data are generally stored in files. • Files can be stored locally or on secondary storage devices. • Keeping track of the information stored in file, its use , status of updation etc, requires file operations. • Therefore FS Design need to be addressed in 3 different ways. • Data Storage • Memory versus Secondary Storage • How Can Secondary Storage Access Time be Improved?

  8. Computer Data can be stored in three kinds of locations: • Primary Storage ==> Memory [Computer Memory] • Secondary Storage [Online Disk/ Tape/ CDRom that can be accessed by the computer] • Tertiary Storage ==> Archival Data [Offline Disk/Tape/ CDRom not directly available to the computer.]

  9. II. Memory storage vs Secondary storage devices • However, relative to Memory, access to secondary storage is extremely slow [E.g., getting information from slow RAM takes 120. 10-9 seconds (= 120 nanoseconds) while getting information from Disk takes 30. 10-3 seconds (= 30 milliseconds)] • To bridge the gap between MM and SS in terms of performance, cost and storage, a good design is necessary.

  10. III. How Can Secondary Storage Access Time be Improved? Since the details of the representation of the data and the implementation of the operations determine the efficiency of the file structure for particular applications, improving these details can help improve secondary storage access time.

  11. Design Goals • Get the information we need with one access to the disk. • If that’s not possible, then get the information with as few accesses as possible. • Group information so that we are likely to get everything we need with only one trip to the disk.

  12. History of File Structures • I. Early Work • Assumed that files were on tape, and access was sequential . • The cost of access grew in direct proportion to the size of file. • II. The emergence of Disks and Indexes • As files grew very large, unaided sequential access was not a good solution. • Disks allowed for direct access. • Indexes made it possible to keep a list of keys and pointers in a small file that could be searched very quickly. • With the key and pointer, the user had direct access to the large, primary file.

  13. III. Emergence of Tree structure • As indexes also have a sequential flavor, when they grew too much, they also became difficult to manage. • The idea of using tree structures to manage the index emerged in the early 60’s. • However, trees can grow very unevenly as records are added and deleted, resulting in long searches requiring many disk accesses to find a record.

  14. IV Balanced Trees • In 1963, researchers came up with the idea of AVL trees for data in memory. • AVL trees, however, did not apply to files because they work well when tree nodes are composed of single records rather than dozens or hundreds of them. • In the 1970’s came the idea of B-Trees which require an O(logk N) access time where N is the number of entries in the file and k, the number of entries indexed in a single block of the B-Tree structure --> B-Trees can guarantee that one can find one file entry among millions of others with only 3 or 4 trips to the disk.

  15. V Hash Tables • Retrieving entries in 3 or 4 accesses is good, but it does not reach the goal of accessing data with a single request. • From early on, Hashing was a good way to reach this goal with files that do not change size greatly over time. • Recently, Extendible Dynamic Hashing guarantees one or at most two disk accesses no matter how big a file becomes.

  16. Physical File: A collection of bytes stored on a disk or tape. Logical File: A “Channel” (like a telephone line) that hides the details of the file’s location and physical format to the program. When a program wants to use a particular file, “data”, the operating system must find the physical file called “data” and make the hookup by assigning a logical file to it. This logical file has a logical name which is what is used inside the program.

  17. Once we have a logical file identifier hooked up to a physical file or device, we need to declare what we intend to do with the file: • Open an existing file • Create a new file • That makes the file ready to use by the program • We are positioned at the beginning of the file and are ready to read or write.

  18. Opening files in C and C++ • fd = open(filename, flags [, pmode]); • fd = file descriptor • filename = physical file name • flags = O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY. • pmode = rwerwerwe • 111 101 001 • owner group world

  19. Closing Files • Makes the logical file name available for another physical file (it’s like hanging up the telephone after a call). • Ensures that everything has been written to the file [since data is written to a buffer prior to the file]. • Files are usually closed automatically by the operating system (unless the program is abnormally interrupted).

  20. Reading • Read(Source_file, Destination_addr, Size) • Source_file = location the program reads from, i.e., its logical file name • Destination_addr = first address of the memory block where we want to store the data. • Size = how much information is being brought in from the file (byte count).

  21. Writing • Write(Destination_file, Source_addr, Size) • Destination_file = the logical file name where the data will be written. • Source_addr = first address of the memory block where the data to be written is stored. • Size = the number of bytes to be written.

  22. Seeking • A program does not necessarily have to read through a file sequentially. It can jump to specific locations in the file or to the end of file so as to append to it. • The action of moving directly to a certain position in a file is often called seeking. • Seek(Source_file, Offset) • Source_file = the logical file name in which the seek will occur • Offset = the number of positions in the file the pointer is to be moved from the start of the file.

  23. The Unix Directory Structure Unix uses the term “File System” to organize files in computer. The Unix File System is a tree-structured organization of directories. The root of the tree represented by the character “/”. Each directory can contain regular files or other directories. The file name stored in a Unix directory corresponds to its physical name. Any file can be uniquely identified by giving it its absolute pathname. E.g., /usr6/mydir/addr. The directory you are in is called your current directory. You can refer to a file by the path relative to the current directory. “.” stands for the current directory and “..” stands for the parent directory.

  24. Stdin , StdoutStderr and IO redirection • Stdout --> Console • fwrite(&ch, 1, 1, stdout); • Stdin --> Keyboard • fread(&ch, 1, 1, stdin); • Stderr --> Standard Error (again, Console) • [When the compiler detects an error, the error message is written in this file] • < filename [redirect stdin to “filename”] • > filename [redirect stdout to “filename”] • E.g., a.out < my-input > my-output • program1 | program2 [take any stdout output from program1 and use it in place of any stdin input to program2. E.g., list | sort

  25. Disks : an overview • Disks belong to the category of Direct Access Storage Devices (DASDs) because they make it possible to access the data directly. • This is in contrast to Serial Devices (e.g., Magnetic Tapes) which allows only serial access [all the data before the one we are interested in has to be read or written in order]. • Different Types of Disks: • Hard Disk: High Capacity + Low Cost per bit. • Floppy Disk: Cheap, but slow and holds little data. (zip disks: removable disk cartridges) • Optical Disk (CD-ROM): Read Only, but holds a lot of data and can be reproduced cheaply. However, slow.

  26. Organization of Disk • The information stored on a disk is stored on the surface of one or more platters. • The information is stored in successive tracks on the surface of the disk. • Each track is often divided into a number of sectors which is the smallest addressable portion of a disk. • When a read statement calls for a particular byte from a disk file, the computer’s operating system finds the correct platter, track and sector, reads the entire sector into a special area in memory called a buffer, and then finds the requested byte within that buffer.

  27. Disk drives typically have a number of platters and the tracks that are directly above and below one another form a cylinder. • All the info on a single cylinder can be accessed without moving the arm that holds the read/write heads. • Moving this arm is called seeking. The arm movement is usually the slowest part of reading information from a disk. • To Estimating capacities and space needed • Track Capacity = number of sectors per track * bytes per sector • Cylinder Capacity = number of tracks per cylinder * track capacity • Drive Capacity = number of cylinders * cylinder capacity

  28. Track Sector Gaps Surface of disk showing tracks and sectors

  29. Data Organization: I. Organizing Tracks per Sector • The Physical Placement of Sectors • The most practical logical organization of sectors on a track is that sectors are adjacent, fixed-sized segments of a track that happens to hold a file. • Physically, however, this organization is not optimal: after reading the data, it takes the disk controller some time to process the received information before it is ready to accept more. • If the sectors were physically adjacent, we would use the start of the next sector while processing the info just read in, there by start of every successive sector information is lost.

  30. Traditional Solution: Interleave the sectors. Leave an interval of several physical sectors between logically adjacent sectors. However, the controller’s speed has improved so that no interleaving is necessary anymore. The file can also be viewed as a series of clusters of sectors which represent a fixed number of (logically) contiguous sectors. Once a cluster has been found on a disk, all sectors in that cluster can be accessed without requiring an additional seek. Operating systems can use FAT [ File Allocation Table ], to locate the clusters. FAT ties logical sectors to the physical clusters they belong to.

  31. Interleaving of 7 File Allocation Table.

  32. Extents: If there is a lot of free room on a disk, it may be possible to make a file consist entirely of contiguous clusters. ==> the file consists of one extent. ==> the file can be processed with a minimum of seeking time. If one extent is not enough, then divide the file into more extents. As the number of extents in a file increases, the file becomes more spread out on the disk, and the amount of seeking necessary increases.

  33. There are 2 possible organizations for records (if the records are smaller than the sector size: • Store 1 record per sector • Advantage : Each record can be retrieved from 1 sector. • Disadvantage : Loss of Space with each sector ==> Internal Fragmentation • 2. Store the records successively (i.e., one record may span two sectors • Advantage: No internal fragmentation • Disadvantage: sectors may need to be accessed to retrieve a single record. • The use of clusters also leads to internal fragmentation.

  34. II. Organizing Tracks by Block • The disk tracks may be divided into user-defined blocks. • When the data on a track is organized by block, this usually means that the amount of data transferred in a single I/O operation can vary depending on the needs of the software designer (not the hardware). • Blocks can be fixed or variable in length • Blocks don’t have the sector-spanning and fragmentation problem of sectors since they vary in size to fit the logical organization of the data. • The blocking factor indicates the number of records that are to be stored in each block in a file. • Each block is usually accompanied by subblocks: • key-subblock and count-subblock. – account for nondata overhead.

  35. NON DATA Overhead • Is the information stored on the disk during pre-formatting. • On sector-addressable disks, pre-formatting involves storing, at the beginning of each sector, sector address, track address and condition (usable or defective) + gaps and synchronization marks between fields of info to help the read/write mechanism distinguish between them. • On Block-Organized disks, subblock + interblock gaps have to be provided with every block. • The relative amount of non-data space necessary for a block scheme is higher than for a sector-scheme. • The greater the block-size, the greater potential amount of internal track fragmentation.

  36. Disk as Bottle neck • Processes are often Disk-Bound, i.e., the network and the CPU often have to wait inordinate lengths of time for the disk to transmit data. • Solution 1: Multiprogramming (CPU works on other jobs while waiting for the disk) • Solution 2: Stripping: splitting the parts of a file on several different drives, then letting the separate drives deliver parts of the file to the network simultaneously ==> Parallelism • Solution 3: RAID: Redundant Array of Independent Disks • Solution 4: RAM disk ==> Simulate the behavior of the mechanical disk in memory. • Solution 5: Disk Cache- large block of memory configured to contain pages of data from a disk. Check cache first. If not there, go to the disk and replace some page already in cache with page from disk containing the data.

  37. Description of Tape Systems • No direct accessing facility, but very rapid sequential access. • Compactness, resistance to rough environmental conditions, easy to store and transport, cheaper than disk • Used to be used for application data • Currently, tapes are primarily used as archival storage.

  38. Organization of Data on Nine-Track Tapes • On a tape, the logical position of a byte within a file corresponds directly to its physical position relative to the start of the file. • The surface of a typical tape can be seen as a set of parallel tracks each of which is a sequence of bits. These bits correspond to 1 byte + a parity bit. • One Byte = a one-bit-wide slice of tape called a frame. • In odd parity, the bit is set to make the number of bits in the frame odd. This is done to check the validity of the data. • Frames are organized into data blocks of variable size separated by interblock gaps (long enough to permit stopping and starting)

  39. Estimating Tape Length Requirements • Let b= the physical length of a data block • Let g= the length of an interblock gap, and • Let n= the number of data blocks. • The space requirement, s, for storing the file is s = n * (b+g) • b= blocksize (i.e., bytes per block)/ tape density (i.e., bytes per inch) • The number of records stored in a physical block is called the blocking factor. • Effective Record Density: a general measure of the effect of choosing different block sizes: (number of bytes per block)/ (number of inches required to store a block) • Space utilization is sensitive to the relative sizes of data blocks and interblock gaps.

  40. Estimating data transmission times. • Normal Data Transmission Rate = (Tape Density (bpi)) * (Tape Speed (ips)) • Interblock gaps, must be taken into consideration. Then, • Effective Transmission Rate = ((Effective Recording Density)* (Tape Speed))

  41. Disk Vs Tapes • In the past: Both Disks and Tapes were used for secondary storage. Disks were preferred for random access and tape was better for sequential access. • Now, • Disks have taken over much of secondary storage ==> Because of the decreased cost of disk + memory storage • Tapes are used as Tertiary storage (Cheap, fast & easy to stream large files or sets of files between tape and disk)

  42. Introduction to CD-ROM • A single disc can hold more than 600 megabytes of data (~ 400 books of the textbook’s size) • CD-ROM is read only. i.e., it is a publishing medium rather than a data storage and retrieval like magnetic disks. • CD-ROM Strengths: High storage capacity, inexpensive price, durability. • CD-ROM Weaknesses: extremely slow seek performance (between 1/2 a second to a second) ==> Intelligent File Structures are critical.

  43. Physical Organization of CD-ROM • CD-ROM is a descendent of CD Audios. i.e., listening to music is sequential and does not require fast random access to data. • Reading Pits and Lands: • CD-ROMs are stamped from a glass master disk which has a coating that is changed by the laser beam. When the coating is developed, the areas hit by the laser beam turn into pits (1’s) along the track followed by the beam. The smooth unchanged areas between the pits are called lands (0’s). • When we read the disc, a beam of laser light on the track is focused, as it moves under the optical pickup. The pits scatter the light, but the lands reflect most of it back to the pickup. This alternating pattern of high- and low-intensity reflected light is the signal used to reconstruct the original digital information.

  44. Given this scheme, it is not possible to have 2 adjacent 1s: 1s are always separated by 0s. Because of physical limitations, there must be at least two 0s between any pair of 1s. Raw patterns of 1s and 0s have to be translated to get the 8-bit patterns of 1s and 0s that form the bytes of the original data. EFM encofing (Eight to Fourteen Modulations) turns the original 8 bits of data into 14 expanded bits that can be represented in the pits and lands on the disk. Since 0s are represented by the length of time between transition, the disk must be rotated at a precise and constant speed. This affects the CD-ROM drive’s ability to seek quickly.

  45. CLV and CAV • Data on a CD-ROM is stored in a single, spiral track. This allows the data to be packed as tightly as possible since all the sectors have the same size (whether in the center or at the edge). • Constant Linear Velocity: • Is the “regular arrangement”, the data is packed more densely in the center than in the edge ==> Space is lost in the edge. • Since reading the data requires that it passes under the optical pick-up device at a constant rate, the disc has to spin more • slowly when reading the outer edges than • when reading towards the center

  46. The CLV format is responsible, in large part, for the poor seeking performance of CD-ROM Drives There is no straightforward way to jump to a location. Part of the problem is the need to change rotational speed. Constant Angular Velocity The data is written more densely in the inner tracks, less dense in outer tracks. With this, there is space wastage in outer tracks Disk spins at same speed.

  47. Comparision of CLV and CAV

  48. Addressing • Different from the “regular” disk method. • Each second of playing time on a CD is divided into 75 sectors. Each sector holds 2 Kilobytes of data. Each CD-ROM contains at least one hour of playing time. • ==> The disc is capable of holding at least 60 min * 60 sec/min * 75 sector/sec * 2 Kilobytes/sector = 540, 000 KBytes • Often, it is actually possible to store over 600, 000 KBytes. • Sectors are addressed by min:sec:sector

  49. CD-ROM Strengths & Weaknesses • Seek Performance: very bad • Data Transfer Rate: Not Terrible/Not Great • Storage Capacity: Great • Benefit: enables us to build indexes and other support structures that can help overcome some of the limitations associated with CD-ROM’s poor performance. • Read-Only Access: There can’t be any changes ==> File organization can be optimized. • No need for interaction with the user (which requires a quick response)

  50. A Journey of A Byte • What happens when the program statement: write(textfile, ch, 1) is executed ? • Part that takes place in memory: • Statement calls the Operating System (OS) which overseas the operation • File manager (Part of the OS that deals with I/O) • Checks whether the operation is permitted • Locates the physical location where the byte will be stored (Drive, Cylinder, Track & Sector) • Finds out whether the sector to locate the ‘P’ is already in memory (if not, call the I/O Buffer) • Puts ‘P’ in the I/O Buffer • Keep the sector in memory to see if more bytes will be going to the same sector in the file

More Related