File Processing - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

File Processing

Description:

CL is attribute. Returns file handle in AX or error code 3, 4, or 5. Open Existing. AH is 3Dh ... 11 attribute. 22-25 timestamp. 26-27 starting cluster number ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 17
Provided by: timma87
Category:

less

Transcript and Presenter's Notes

Title: File Processing


1
File Processing
  • Assembly Language Programming
  • University of Akron
  • Dr. Tim Margush

2
File Handle
  • An integer assigned to a file by DOS
  • Used to refer to the file in programs
  • DOS provides file handle functions to manipulate
    files
  • These are available through the DOS interrupt
    (21h)

3
Predefined File Handles
  • DOS manages standard input output devices through
    these handles
  • 0 keyboard (stdin)
  • 1 screen (stdout)
  • 2 error output (stderr)
  • 3 auxiliary device
  • 4 printer

4
File Errors
  • Many file handling routines return an error code
  • carry clear indicates no error
  • carry set indicates an error
  • AX will contain an error number
  • 1 invalid function number
  • 2 file not found
  • 3 path not found
  • 4 no free handles
  • 5 access denied
  • 6 invalid handle
  • C invalid access code
  • F invalid drive
  • 10 can't remove current dir
  • 11 not the same device
  • 12 no more files to be found

5
Opening a File
  • Open new/Rewrite
  • AH is 3Ch
  • DSDX is the address of filename (ASCIIZ)
  • CL is attribute
  • Returns file handle in AX or error code 3, 4, or 5
  • Open Existing
  • AH is 3Dh
  • DSDX is the address of filename (ASCIIZ)
  • AL is access code
  • 0 read
  • 1 write
  • 2 read/write
  • Returns file handle in AX or error code 2,4,5,12

6
Attribute Byte
  • Each entry in a disk directory contains an
    attribute byte identifying the entry
  • ?? ?? ar sd vl sy hd ro
  • archive set until file is backed up
  • subdirectory entry is a subdirectory name
  • volume label entry is disk volume label
  • system a system file
  • hidden file does not appear in directory list
  • read only cannot change or delete

7
Changing a File's Attributes
  • Get/Change File Attribute
  • AH is 43h
  • AL is change code
  • 0 get attribute
  • 1 set attribute
  • DSDX is the address of filename (ASCIIZ)
  • CX is attribute if setting
  • Returns file attribute in CX or error 2, 3, or 5
  • You cannot change bits 3 or 4 (volume label and
    subdirectory settings)

8
Disk Organization
  • Each byte of data stored on a disk has a four
    part address
  • Surface - 0 through n (floppies have 0 and 1)
  • Track - 0 through m (concentric circles on data
    on a surface)
  • Sector - 1 through k (512 byte section of a
    track)
  • Offset - 0 through 511 (location within sector)

9
Special Sectors
  • Boot record
  • A small program used to boot an operating system
  • File Allocation Table
  • A map showing where files are stored on the disk
  • Root Directory File Entries
  • sequence of 32 byte records, each representing a
    directory or file name
  • Data Area for File Data and Subdirectory
    information

10
File Directory Entry
  • Bytes Contents
  • 0-7 filename (byte 0 is also a status byte)
  • 00 (never used), E5 (deleted), 2E (directory)
  • 8-10 extension
  • 11 attribute
  • 22-25 timestamp
  • 26-27 starting cluster number
  • 28-31 file size (bytes)

11
FAT
  • A map of disk storage
  • This is an array based linked list
  • FATi tells what cluster (if any) follows
    cluster i (-1 is end of chain)
  • Each entry is a fixed number of bits (12, 16, or
    32)
  • FAT cell contents
  • 000 available
  • FF0-FF7 reserved
  • FF7 means bad
  • FF8-FFF chain end
  • 002-FEF next cluster
  • The cluster code for cluster n is at FATn

12
Finding A File's Data
  • The file directory entry for a file contains the
    starting cluster number, say n
  • This cluster contains the first x bytes of the
    file
  • FATn will tell the next cluster number
  • By following the chain if clusters, all of the
    file's data may be located.

13
Closing a File
  • Closing a file frees the file handle and updates
    file info (size, timestamp) in directory
  • AH is 3Eh
  • BX is the file handle
  • Returns error code 6 in AX if unsuccessful

14
Reading a File (or keyboard)
  • Read a File
  • AH is 3Fh
  • BX is file handle
  • CX is number of bytes to read
  • DSDX is address of buffer
  • Returns number of bytes read in AX or error code
    5 or 6
  • If a file is open for reading, this function will
    copy a specified number of bytes from the file to
    a memory buffer
  • EOF is detected by comparing CX and AX after the
    read

15
Writing to a File (or screen or printer)
  • Write File
  • AH is 40h
  • BX is file handle
  • CX is number of bytes to write
  • DSDX is address of bytes to be written
  • Returns number of bytes written in AX or error
    code 5 or 6
  • This function sends one or more bytes to a file
    that is open for output
  • A full disk will result in less than the
    specified number of bytes being written

16
File Pointer
  • The position in a file where the next I/O
    operation will take place
  • A byte offset from the beginning of the file
  • File pointers are 32-bit integers
  • Move File Pointer
  • AH is 42h
  • Al is movement code
  • 0 relative to start
  • 1 relative to current
  • 2 relative to eof
  • BX is file handle
  • CXDX is the number of bytes to move (signed)
  • Returns new file pointer in DXAX or error code 1
    or 6
Write a Comment
User Comments (0)
About PowerShow.com