file processing : file organization and file systems

16
1 File Processing : File Organization and File Systems 2011, Spring Pusan National University Ki-Joune Li

Upload: krikor

Post on 21-Jan-2016

88 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: File Processing : File Organization and File Systems

1

File Processing : File Organization and File Systems

2011, Spring

Pusan National University

Ki-Joune Li

Page 2: File Processing : File Organization and File Systems

STEMPNU

2

Logical Structure of File

FileFile

FieldField FieldField FieldField

Record (Tuple)Record (Tuple)

RecordRecord

RecordRecord

BlockBlock

Fixed Size RecordFixed Size Record

Variable Size RecordVariable Size Record

Page 3: File Processing : File Organization and File Systems

STEMPNU

3

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

Page 4: File Processing : File Organization and File Systems

STEMPNU

4

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

Page 5: File Processing : File Organization and File Systems

STEMPNU

5

Delimiters

RecordRecord RecordRecord …… RecordRecord

DelimitersDelimiters

RecordRecord RecordRecord …… RecordRecord

Pointer/SizePointer/Size

• Difficult to handle deletions and insertions

Page 6: File Processing : File Organization and File Systems

STEMPNU

6

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.

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.

Pointers should not point directly to record

But to the entry for the record in header.

Pointer to Record Pointer to Record

Page 7: File Processing : File Organization and File Systems

STEMPNU

7

Reserved Space

Maximum # of FieldsMaximum # of Fields

Page 8: File Processing : File Organization and File Systems

STEMPNU

8

Overflow Area

First field of recordFirst field of record

Rest recordsRest records

Page 9: File Processing : File Organization and File Systems

STEMPNU

9

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

NameName ID#ID# Photo Photo

Block sizeBlock size

NameName ID#ID#Contiguous Reserved

Block for BLOBContiguous Reserved

Block for BLOB

Page 10: File Processing : File Organization and File Systems

STEMPNU

10

File System

Example fd=open(”data.txt”,O_RDONLY,0);

Nbytes=read(fd,buf,100);

How to process these functions in OS ?

Page 11: File Processing : File Organization and File Systems

STEMPNU

11

i (index)–node : information about file

AttributesAttributesPointers to data blockPointers to data block

i-node

Data BlockData Block

NameName

PermissionPermissionOwnershipOwnershipLast updated date/timeLast updated date/timeCreated date/timeCreated date/time

Type : directory, data, specialType : directory, data, special

Page 12: File Processing : File Organization and File Systems

STEMPNU

12

i-node : Pointer to data block

AttributesAttributes

Pointers to data block(0-9: up to 40K bytes)Pointers to data block(0-9: up to 40K bytes)

Single direct PointerSingle direct Pointer

Data BlockData Block

. . .. . .

Data BlockData Block

Data BlockData Block

. . .. . .

Data BlockData Block

Pointer Block(1024 blocks)Pointer Block(1024 blocks)

Double direct PointerDouble direct Pointer

Page 13: File Processing : File Organization and File Systems

STEMPNU

13

Block configuration for i-node

Boot BlockBoot BlockSuper BlockSuper Block

0

1

i-node 1 ~ 40i-node 1 ~ 40i-node 41 ~ 80i-node 41 ~ 80……

2

3

Data blockData blockData blockData block……Data blockData block

Reserved Block

Given by formatting

User space

Page 14: File Processing : File Organization and File Systems

STEMPNU

14

Implementation of File Hierarchy

AttributesAttributes

i-node 6

AttributesAttributes

i-node 1

i-node for root directory

i-node for /usr

AttributesAttributes

i-node 19

11

11

44

77

1414

Root directoryblock

99

66

88

..

....

binbin

devdev

liblib

etcetc

usrusr

tmptmp

66

11

1919

3030

5454

Directory block for /usr

..

....

liklik

kimmkkimmk

parkshparksh

i-node for /usr/lik

1919

66

107107

Directory block for /usr/lik

..

....

data.txtdata.txt

Data block for /usr/lik/data.txt

AttributesAttributes

i-node 107

i-node for /usr/lik/data.txt

Page 15: File Processing : File Organization and File Systems

STEMPNU

15

FAT (File Allocation Table)

DOS or MS-Windows 98 Same purpose of i-node in UNIX

Page 16: File Processing : File Organization and File Systems

STEMPNU

16

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;

open

write