Disk structure & File Handling

43

Transcript of Disk structure & File Handling

Page 1: Disk structure & File Handling
Page 2: Disk structure & File Handling
Page 3: Disk structure & File Handling

DISK STRUCTURES&

FILE HANDLING

Page 4: Disk structure & File Handling

FLOPPY DISK3 ½ INCH 5 ¼ INCH

HARD DISK

FILE ALLOCATION

DISK STRUCTURES:Tracks, sectors, and cylinders.Disk partitions.Disk capacity.

DISK STRUCTURES

Page 5: Disk structure & File Handling
Page 6: Disk structure & File Handling

FILE FILE HANDLINGFILE HANDLEFILE ERRORS

FILE POINTER

OPERATIONS OF FILE• 3CH• 3DH• 3EH• 3FH• 40H• 41H• 42H

FILE HANDLING

Page 7: Disk structure & File Handling

DISK STRUCTURES

The actual physical details of disk

Page 8: Disk structure & File Handling

FLOPPY DISK3 ½ INCH 5 ¼ INCH

HARD DISK

FILE ALLOCATION

DISK STRUCTURES:Tracks, sectors, and cylinders.Disk partitions.Disk capacity.

DISK STRUCTURES

Page 9: Disk structure & File Handling

TWO KINDS OF DISK

Floppy diskHard disk

Page 10: Disk structure & File Handling

FLOPPY DISK

Page 11: Disk structure & File Handling

1) Internal parts of a 3½-inch floppy disk.

2) A hole that indicates a high-capacity disk.

3) The hub that engages with the drive motor.

4) A shutter that protects the surface when

removed from the drive.

5) The plastic housing.

6) A polyester sheet reducing friction against the

disk media as it rotates within the housing.

7) The magnetic coated plastic disk.

8) A schematic representation of one sector of

data on the disk; the tracks and sectors are

not visible on actual disks.

9) The write protection tab (unlabeled) is upper

left.

Page 12: Disk structure & File Handling

3 ½ INCH 5 ¼ INCH

Page 13: Disk structure & File Handling

HARD DISK

Page 14: Disk structure & File Handling

1) Actuator that moves the read-write arm.

2) Read-write arm swings read-write head back and forth across platter.

3) Central spindle allows platter to rotate at high speed.

4) Magnetic platter stores information in binary form.

5) Plug connections link hard drive to circuit board in personal computer.

6) Read-write head is a tiny magnet on the end of the read-write arm.

7) Circuit board on underside controls the flow of data to and from the platter.

8) Flexible connector carries data from circuit board to read-write head and platter.

9) Small spindle allows read-write arm to swing across platter.

Page 15: Disk structure & File Handling

WORKING OF HARD DISK

Page 16: Disk structure & File Handling

STRUCTURE OF DISK

Page 17: Disk structure & File Handling
Page 18: Disk structure & File Handling

CAPACITY OF THE 5 ¼ INCH DOUBLE DENSITY FLOPPY DISK

Page 19: Disk structure & File Handling

CAPACITY OF HARD DISK

Page 20: Disk structure & File Handling

FILE ALLOCATION

To keep the track of data stored on a disk, DOS uses a directory structure. The first tracks and sectors of a disk contain information about the disk’s file structure.

Page 21: Disk structure & File Handling
Page 22: Disk structure & File Handling

FILE DIRECTORY:

Page 23: Disk structure & File Handling

ATTRIBUTE BYTE

Page 24: Disk structure & File Handling

CLUSTER“A fixed number of sector (depends on the kind of

disk) is called cluster”

Page 25: Disk structure & File Handling

(FILE ALLOCATION TABLE):

“A table that the operating system uses to locate files on a disk. Due to fragmentation, a file may be divided into many sections that are scattered around the disk. The FAT keeps track of all these pieces.”

FAT

Page 26: Disk structure & File Handling

DOSHOW DOS STORES A FILE? DOS locates an unused directory entry and stores the filename, attribute, creation time and date.

DOS searches the FAT for the first entry indicating unused cluster (000 means unused) and stores the starting cluster number in the directory. Let’s suppose it finds 000 in entry 9.

If the data will fit in a cluster, DOS stores them in cluster 9 and places FFFh in FAT entry 9. If there are more data, DOS looks for the next available next entry in the FAT; for example, AH. DOS stores more data in cluster AH, and places 00Ah in FAT entry 9. This process of finding unused cluster from the FAT, storing data in those clusters, making each FAT entry point to the next cluster continuous until all the data have been stored. The last FAT entry for the file contains FFFh.

HOW DOS READ A FILE?

DOS gets the starting cluster number from directory.

DOS read that particular cluster number from disk and stored in DTA (Data Transfer Area). The program that initiated the read retrieves data from DTA as needed.

Since entry 2 contains 4 the next cluster in the file cluster is 4. If the program need more data DOS reads cluster 4 into the DTA.

Entry 4 in the FAT contain FFFh, which indicates the last cluster in the file. In general, the process of obtaining cluster numbers from the FAT and reading data into the DTA continues until a FAT entry contains FFFh.

Page 27: Disk structure & File Handling

FILE HANDLING

Page 28: Disk structure & File Handling

FILE FILE HANDLINGFILE HANDLEFILE ERRORS

FILE POINTER

OPERATIONS OF FILE• 3CH• 3DH• 3EH• 3FH• 40H• 41H• 42H

FILE HANDLING

Page 29: Disk structure & File Handling

File ?

File Handling ?

A file is an object on a computer that stores data, information, settings, or

commands that are used with a computer program.

Through file handling, one can perform operations like create, modify , delete etc on File.

File Create Write Rename Delete

Page 30: Disk structure & File Handling

FILE HANDLES

When file is created or open in a program, DOS assign it a unique number called file handle.

Page 31: Disk structure & File Handling
Page 32: Disk structure & File Handling

FILE ERRORS

Page 33: Disk structure & File Handling
Page 34: Disk structure & File Handling

OPERATIONS OF FLE

Page 35: Disk structure & File Handling

3CH

3DH

3EH

3FH40H

41H

42H

Page 36: Disk structure & File Handling

3CH

42H

3EH3DH

40H 41H3FH

OPEN A NEW FILE / REWRITE A NEW FILE

MOVE A FILE POINTER

DELETE A FILEWRITE A FILEREAD A FILE

CLOSE A FILEOPEN AN EXISTING

A FILE

Page 37: Disk structure & File Handling

Creating File & Writing

FILE DB "c:\example_new\hello.txt",0

TEXT DB "HELLO I AM TEXT",0

TEXT_SIZE = $ - OFFSET TEXT

HANDLE DW ?

System Call AH BX CX DX

File Open 3CH 0 Offset Filename

File Write 40H Handle Text Size Offset Text

File Close 3EH Handle

Handle ?Handle is some resources/memory to store temporary data , used in file operation

Page 38: Disk structure & File Handling

Create File Operation

MOV CX,0

MOV DX, OFFSET FILE ; FILENAME

MOV AH, 3CH ; 3CH FOR CREATING FILE

INT 21H

Write into File

MOV HANDLE, AX ; MAKE RESOURCES HANDLE

MOV AH, 40H ; 40H FOR WRITING INTO FILE

MOV BX, HANDLE ; COPY RESOURCES HANDLE

MOV DX, OFFSET TEXT ; TEXT TO WRITE

MOV CX, TEXT_SIZE ; TEXT SIZE

INT 21H;

Page 39: Disk structure & File Handling

Close File

MOV AH, 3EH ; 3EH FOR CLOSE FILE

MOV BX, HANDLE ; COPY RESOURCES HANDLE

INT 21H

Page 40: Disk structure & File Handling

Delete File

System Call AH BX CX DX

File Delete 41H Offset OldFilename

.DATA

FILE DB "C:\EXAMPLE_NEW\WORLD.TXT",0

.CODE

MOV DX, OFFSET FILE ; OLD FILENAME

MOV AH, 41H ; 41H FOR DELETE FILE

INT 21H

Page 41: Disk structure & File Handling

FILE POINTER

The file pointer is used to locate a position in the file. File is opened – file pointer is at the beginning of file. After read operation – it the next byte to be read. After writing – file pointer at end of file.

Page 42: Disk structure & File Handling

File pointer

System Call AH BX CX:DX

File pointer 42H File handle

Number ofbyte to move

Move File pointer INT 21H, FUNCTION 42H

INPUT AH = 42HAL = MOVEMENT CODE:

• 0 MOVE RELATIVE TO BEGINNIG• 1 MOVE RELATIVE TO CUUERENT POINTER LOCATION• 2 MOVE RELATIVE TO THE EOF

BX = FILE HANDLE CX:DX = NUMBER OF BYTES TO MOVE

OUTPUT DX:AX = NEW POINTER LOCATION IN BYTES FROM THE BEGNNING OF FILE. IF CF = 1 ERROR CODE IN AX (1,6).

Page 43: Disk structure & File Handling

Caption