160 likes | 419 Views
File Processing : File Organization and File Systems. 2011, Spring Pusan National University Ki-Joune Li. Fixed Size Record. Variable Size Record. Logical Structure of File. File. Field. Field. Field. Record (Tuple). Record. Record. Block. Fixed Size Record. Fixed Size
E N D
File Processing : File Organization and File Systems 2011, Spring Pusan National University Ki-Joune Li
Fixed Size Record Variable Size Record Logical Structure of File File Field Field Field Record (Tuple) Record Record Block
Fixed Size Record • Fixed Size • Fixed Number of Fields, and • Fixed Size of each Field • Easy to implement • Disk Address • (n-1)*srecord • Deletion of a record • Like Array but no movement • Free Record List or • Pointer to Next Record
Variable Length Record • Variable Length due to • Variable Number of Fields, or • Variable Size of each Field • Complicated to implement • Implementation • Delimiter (, size, or pointer) • Slotted Page • Fixed Length • Overflow Area • Reserved Space
Delimiters Pointer/Size Delimiters Record Record … Record Record Record … Record • Difficult to handle deletions and insertions
Pointer to Record Slotted Page • Records can be moved around within a page • to keep them contiguous with no empty space between them • entry in the header must be updated. • Pointers should not point directly to record • But to the entry for the record in header.
Maximum # of Fields Reserved Space
First field of record Rest records Overflow Area
Block size Name ID# Contiguous Reserved Block for BLOB Binary Large Object Block (BLOB) • If size (field) > size (block) • e.g. Image or Video • BLOB : Type of field where its size is greater than block size • cf. CLOB : Text rather than binary Name ID# Photo
File System • Example fd=open(”data.txt”,O_RDONLY,0); Nbytes=read(fd,buf,100); How to process these functions in OS ?
i-node Attributes Data Block Pointers to data block i (index)–node : information about file Name Type : directory, data, special Permission Ownership Last updated date/time Created date/time
Data Block . . . Data Block Data Block Pointer Block (1024 blocks) . . . Data Block i-node : Pointer to data block Attributes Pointers to data block (0-9: up to 40K bytes) Single direct Pointer Double direct Pointer
2 i-node 1 ~ 40 Given by formatting i-node 41 ~ 80 3 … Data block Data block … Data block Block configuration for i-node 0 Boot Block Reserved Block 1 Super Block User space
Directory block for /usr i-node 19 i-node 1 Root directoryblock i-node 6 Attributes Attributes Attributes 6 . 1 . 1 .. 1 .. 19 lik 4 bin 30 kimmk 7 dev 54 parksh 14 lib 9 etc 6 usr Directory block for /usr/lik 8 tmp i-node 107 19 . Attributes Data block for /usr/lik/data.txt 6 .. 107 data.txt i-node for /usr/lik/data.txt Implementation of File Hierarchy i-node for root directory i-node for /usr i-node for /usr/lik
FAT (File Allocation Table) • DOS or MS-Windows 98 • Same purpose of i-node in UNIX
open write fd=open(”data.txt”,O_RDONLY,0);Nbytes=read(fd,buf,100); • Step 1 : Find i-node for “data.txt” via i-node • from root or current directory • Step 2 : Check owner and access right • Step 3 : Register it to OpenFileTable • Initialize entry values : e.g. offset, mode • fd : array index of this table • Some entries : reserved for stdio, stderr, etc.. • Step 4 : Check ownership and right • Step 5 : Read 100 bytes to buf • Read 100 bytes from the OpenFileTable[fd].offset • OpenFileTable[fd].offset += 100;