External memory management

advertisement
External memory management
In consideration of disk structure we follow Mazidi A.M., Mazidi J.G. The 80x86
IBM PC and Conmpatible Computers (Volumes 1&2). Assembly Language, Design, and
Interfacing. 3rd Edition, Prentice Hall, Upper Saddle River, 1995, 984 p. ISBN 0-13016568-9
Magnetic disks are used nowadays as main on-line secondary storage. Let’s
consider briefly file organization on disks and problems of optimization access to data
time. Magnetic platters of disk are split into concentric tracks, which are split in sectors
(we shall consider floppy disks). First sector (side 0, track 0, sector 0) is always used to
hold the boot record. Then some sectors are used for storage of the FAT (file allocation
table) copies 1 and 2. The number of sectors set aside for FAT depends on upon the disk
density. After the FAT, the directory is stored in consecutive sectors. Again, the number
of sectors for directory depends on disk density. In assigning sectors for FATs and
directory, DOS uses all the sectors of track 0, side 0, then goes to side 1 and uses track 0,
then comes to side 0 track 1, then goes to side 1 track 1, and so on. When a disk is
formatted (sectors and tracks are organized during formatting so that it makes possible
for disk controller to access the information; some sectors are set for system functions –
boot sector, FATs, directory - other may be used by user’s files), the first sector is used as
a boot record. It is from the boot record that the computer will know the disk type, sector
density, total number of sectors, and the other essential information needed by BIOS and
operating system. Place for files is allocated in units of clusters – some number of
sequential sectors; this cluster size is stored in boot record in one byte with offset 0x0D.
Number of sectors per FAT is stored 2 bytes with offset 0x16. , number of root-directory
entries is stored in 2 bytes with offset 0x11. Each directory entry is of 32 bytes with the
following layout:
Bytes (H)
Possible contents
Interpretation
0-7
45 44 20 20 20 20 20 “ED “ – Name
20
8-A
45 48 45
“EXE” – extension
B
20
Archive file – Attribute:
Bits used: 0 – read only;
1 – hidden; 2 – system;
3 – volume label; 4 –
subdirectory; 5 - archive
C-15
Reserved
16-17
E0 96 (use 96 E0)
1001 0110 1110 0000
00000 =0 2-second
increment: bits 4-0
represent number of
seconds
110111 = 55 min: bits
10-5 represent minutes
10010=hour
18
(6
p.m.):
bits 15-11 represent
hour
18-19
98 0C (use 0C 98)
0000 1100 1001 1000
11000= day 24: bits 4-0
represent day
0100 =month 4: bits 8-5
represent month
0000110=year
6
1980+6=1986: bits 15-9
represent year
1A-1B
02 00
Starting cluster 0002
1C-1F
9B 10 00 00
File size in bytes 00 00
10 9B=4251
Entries in directory point to the 1st respective file’s cluster. Other clusters of the
file forming a chain of file clusters may be found in FAT. FAT is crucial for file access,
hence it is maintained on disk in 2 copies to enhance reliability. FAT consists of the set of
elements; size of these elements may differ for different types of disks, with larger size
there may be used larger disk space (FAT12 – uses 12-bit elements, FAT16 – 16-bit
elements and so on). The first 2 elements (entries) of FAT contain the media descriptor
byte (for example, F9 – double-sided 5 1/4” diskette; 15 sectors/track - followed by F’s to
pad the remaining space. Other entries are in one-to –one correspondence with clusters on
disk: each FAT entry reflects state (free, reserved, bad, part of a file) of respective
cluster. Layout of disk is: boot sector, reserved sectors, FAT#1, FAT#2, data. When
converting cluster number to sector number, it must be taken into account that first data
cluster is numbered by 2 (sector=data_start+(cluster_number-2)*sectors_per_cluster).
FAT entries may have following values (for FAT12)
Code
Meaning
0x000
Unused cluster: cluster has never been used
0x001
Free cluster: was used previously, but now
is free
0x002-0xFEF
Cluster is used by a file
0xFF0-0xFF6
Reserved
0xFF7
Bad cluster, cannot be used
0xFF8-0xFFF
Last cluster of a file
Example of FAT contents:
Byte: 0 1 2 3 4 5 6 7 8 9 A B C D E ..
Data:F9 FF FF 03 60 00 00 10 00 FF 7F FF 00 00 00 ..
First 2 elements are in bytes 0-2. 3rd element (corresponds to cluster_number=2)
has digits in bytes 3-4 (offset in FAT=floor(cluster_number*3/2)): 03 60, after reversing
we get 60 03, and 3 junior (for even cluster numbers) digits 003 form contents of entry 2,
referencing to entry 3. Entry 3 is in bytes 4-5: 60 00, after reversing – 00 60, 3 senior (for
odd cluster numbers) digits are 006, i.e. it refers to cluster 6. Entry for cluster 6 is in bytes
9-A: FF 7F, after reversing – 7F FF, junior 3 digits (for even cluster number) are FFF, so
it the last cluster in the chain of clusters allocated to file.
File clusters may be allocated in different parts of a disk, and a problem of disk access
optimization for the system of several running processes arises. For example, order of
service of requests may depend on current position of a magnetic read-write head, and on
places of target data, so that to minimize time on magnetic head movements.
Strategies are: 1) FIFO (First-In-First-Out); 2) with the least seek time first; 3)
scan – magnetic head cyclically moves forward from external track to internal, and
backward, serving requests which are passed by – elevator algorithm. Direction of
movement is changed when there are no requests further in current direction. 4) Cyclic
scan – requests are served only on moving to internal track, then head jumps back, and
process is repeated. 5) N-step scan – head moves forward and backward, serving
requests, which have appeared before beginning current way. New requests are
rearranged for best serving on the back way
Download