disk structure & file handling

Post on 23-Jan-2018

279 Views

Category:

Education

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

DISK STRUCTURES&

FILE HANDLING

FLOPPY DISK3 ½ INCH 5 ¼ INCH

HARD DISK

FILE ALLOCATION

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

DISK STRUCTURES

FILE FILE HANDLINGFILE HANDLEFILE ERRORS

FILE POINTER

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

FILE HANDLING

DISK STRUCTURES

The actual physical details of disk

FLOPPY DISK3 ½ INCH 5 ¼ INCH

HARD DISK

FILE ALLOCATION

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

DISK STRUCTURES

TWO KINDS OF DISK

Floppy diskHard disk

FLOPPY DISK

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.

3 ½ INCH 5 ¼ INCH

HARD DISK

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.

WORKING OF HARD DISK

STRUCTURE OF DISK

CAPACITY OF THE 5 ¼ INCH DOUBLE DENSITY FLOPPY DISK

CAPACITY OF HARD DISK

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.

FILE DIRECTORY:

ATTRIBUTE BYTE

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

disk) is called cluster”

(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

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.

FILE HANDLING

FILE FILE HANDLINGFILE HANDLEFILE ERRORS

FILE POINTER

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

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

FILE HANDLES

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

FILE ERRORS

OPERATIONS OF FLE

3CH

3DH

3EH

3FH40H

41H

42H

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

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

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;

Close File

MOV AH, 3EH ; 3EH FOR CLOSE FILE

MOV BX, HANDLE ; COPY RESOURCES HANDLE

INT 21H

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

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.

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).

Caption

top related