Upload
claribel-willis
View
218
Download
2
Tags:
Embed Size (px)
Citation preview
Assembly Language for Intel-Based Computers, 5th Edition Chapter 14: Disk Fundamentals(c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.Slide show prepared by the authorRevision date: June 4, 2006Kip R. Irvine
Web site Examples
Chapter OverviewDisk Storage SystemsFile SystemsDisk DirectoryReading and Writing Disk Sectors (7305h)System-Level File Functions
Web site Examples
Disk Storage SystemsTracks, Cylinders, and SectorsDisk Partitions (Volumes)
Web site Examples
Tracks and SectorsPhysical disk geometry - a way of describing the disks structure to make it readable by the system BIOSTrack - concentric circle containing dataSector - part of a track
Web site Examples
Cylinders and SeekingCylinder - all tracks readable from one head positionSeek - move read/write heads between tracks
Web site Examples
Disk FormattingPhysical formattingaka low-level formattingUsually done at the factory. Must be done before logical formattingDefines the tracks, sectors, and cylindersLogical formattingPermits disk to be accessed using sequentially numbered logical sectorsInstalls a file system (ex: NTFS)May install an operating system
Web site Examples
FragmentationA fragmented file is one whose sectors are no longer located in contiguous areas of the disk. causes read/write heads to skipslower file accesspossible read/write errors
Web site Examples
TranslationTranslation - conversion of physical disk geometry to a sequence of logical sector numbersPerformed by a hard disk controller (firmware)Logical sector numbers are numbered sequentially, have no direct mapping to hardware
Web site Examples
Disk PartitionsLogical units that divide a physical hard diskAlso called volumesPrimary partitionUp to four permittedEach may boot a different OSExtended partitionMaximum of one permittedMay be divided into multiple logical partitions, each with a different drive letterPrimary and ExtendedUp to three primary and one extended
Web site Examples
Logical PartitionsCreated from an extended partitionNo limit on the numberEach has a separate drive letterUsually contain dataCan be bootable (ex: Linux)
Web site Examples
Disk Partition TableLocated in the disk's Master Boot Record (MBR), following a block of executable codeFour entries, one for each possible partitionEach entry contains the following fields:state (non-active, bootable)type of partition (BigDOS, Extended, . . .)beginning head, cylinder, & sector numbersending head, cylinder, & sector numbersoffset of partition from MBRnumber of sectors in the partitionSee also: www.datarescue.com/laboratory/partition.htm
Web site Examples
Cascading Partition TablesBoot, BigDOSNA, ExtendedNA, BigDOSNA, BigDOSDrive DDrive EPrimary partitionlinks toBoot = bootable (system)NA = non activeBigDOS = over 32 MBLogical partitions (D, E)Drive C
Web site Examples
Dual-Boot ExampleSystem 98 and Win2000-A are bootable partitionsOne is called the system partition when activeDATA_1 and BACKUP are logical partitionsTheir data can be shared by both operating systems
Web site Examples
Master Boot Record (MBR)The MBR contains the following elements:Disk partititon tableA program that jumps to the boot sector of the system partition
Web site Examples
What's NextDisk Storage SystemsFile SystemsDisk DirectoryReading and Writing Disk Sectors (7305h)System-Level File Functions
Web site Examples
File SystemsDirectory, File, Cluster RelationshipsClustersFAT12FAT16FAT32NTFSPrimary Disk Areas
Web site Examples
File SystemThis is what it does for you:Keeps track of allocated and free spaceMaintains directories and filenamesTracks the sector location of each file and directory
Web site Examples
Directory, File, Cluster, Sector Relationships
Web site Examples
Cluster (1 of 2)Smallest unit of space used by a fileConsists of one or more adjacent sectorsSize depends on both the type of file system in use and the disk partition sizeA file is a linked sequence of clusters. Example:
Web site Examples
Cluster (2 of 2)A file always uses at least one clusterA high percentage of space may be wastedExample: 8,200-byte file requires three 4K clusters:
Web site Examples
FAT12Designed for diskettesEach FAT entry is 12 bitsVery little fault tolerancetwo copies of the FAT (cluster table)Optimal storage for small files512-byte clusters
Web site Examples
FAT16MS-DOS format for hard disks16-bit FAT entriesLarge cluster size when disk > 1 GBinneficient for small filesMax 2 GB size under MS-DOSLittle or no recovery from read/write errors
Web site Examples
FAT32Supports long filenamesSupported by all version of MS-Windows from Windows 95 onward(except Windows NT)32-bit FAT entries32 GB maximum volume sizeImproved recovery from read/write errors
Web site Examples
NTFSSupported by Windows NT, 2000, and XPHandles large volumescan span multiple hard drivesEfficient cluster size (4K) on large volumesUnicode filenamesPermissions on files & foldersShare folders across networkBuilt-in compression and encryptionTrack changes in a change journalDisk quotas for individuals or groupsRobust error recoveryDisk mirroring
Web site Examples
Primary Disk AreasA disk or volume is divided into predefined areas and assigned specific logical sectors.Example: 1.44 MB disketteBoot record (sector 0)File allocation table (sectors 1 18)Root directory (sectors 19 32)Data area (sectors 33 2,879)
Web site Examples
Your turn . . .1. A 1.44 MB diskette has 512 bytes per cluster. Suppose a certain file begins in cluster number 5. Which logical disk sector contains the beginning of the file? (Hint: see page 503).2. Suppose a certain hard drive has 4 KB per cluster, and we know that the data area begins in sector 100. If a particular file begins in cluster 10, which logical sectors are used by the cluster?(answers on next panel . . .)
Web site Examples
Answers1. The data area begins in Sector 33 (see page 503). Each cluster = 1 sector, so the file begins in sector 33 + 5 = sector 38.2. The hard drive has 8 sectors per cluster. The starting cluster number of the file is 100 + (8 * 10) = 180. Therefore, sectors 180 187 are used by the file's first cluster.
Web site Examples
Boot Record (1 of 2)Fields in a typical MS-DOS boot record:Jump to boot code (JMP instruction)Manufacturer name, version number Bytes per sectorSectors per clusterNumber of reserved sectors (preceding FAT #1)Number of copies of FATMaximum number of root directory entriesNumber of disk sectors for drives under 32 MBMedia descriptor byteSize of FAT, in sectorsSectors per track
Web site Examples
Boot Record (2 of 2)(continued)Number of drive headsNumber of hidden sectorsNumber of disk sectors for drives over 32 MBDrive number (modified by MS-DOS)ReservedExtended boot signature (always 29h)Volume ID number (binary)Volume labelFile-system type (ASCII)Start of boot program and data
Web site Examples
What's NextDisk Storage SystemsFile SystemsDisk DirectoryReading and Writing Disk Sectors (7305h)System-Level File Functions
Web site Examples
Keeping Track of FilesMS-DOS Directory StructureLong Filenames in MS-WindowsFile Allocation Table
Web site Examples
MS-DOS Directory Structure (1 of 2)
Web site Examples
MS-DOS Directory Structure (2 of 2)Time field equals 4DBDh (9:45:58), and the Date field equals 247Ah (March 26, 1998). Attribute is normal:
Web site Examples
Date and Time FieldsDate stamp field:
Time stamp field:
Web site Examples
Your turn . . .What time value is represented here?
Web site Examples
File Attribute ValuesWhat type of file has attribute 00100111 . . . ?
Web site Examples
Long Filenames in MS-Windows Filename: ABCDEFGHIJKLMNOPQRSTUV.TXT
Web site Examples
File Allocation Table (1 of 2)A map of all clusters on the disk, showing their ownership by specific filesEach entry corresponds to a cluster numberEach cluster contains one or more sectorsEach file is represented in the FAT as a linked list, called a cluster chain.Three types of FAT's, named after the length of each FAT entry:FAT-12FAT-16FAT-32
Web site Examples
File Allocation Table (2 of 2)Each entry contains an n-bit integer that identifies the next entry. (n=12,16, or 32)Two cluster chains are shown in the following diagram, one for File1, and another for File2:
Web site Examples
What's NextDisk Storage SystemsFile SystemsDisk DirectoryReading and Writing Disk Sectors (7305h)System-Level File Functions
Web site Examples
Reading and Writing Disk Sectors (7305h)INT 21h, Function 7305h (absolute disk read and write) Reads and writes logical disk sectorsRuns only in 16-bit Real-address mode Does not work under Windows NT, 2000, or XPTight security!
Web site Examples
DISKIO StructureUsed by Function 7305h:DISKIO STRUCTstartSector DWORD 0; starting sector numbernumSectors WORD 1; number of sectorsbufferOfs WORD buffer; buffer offsetbufferSeg WORD @DATA; buffer segmentDISKIO ENDS
Web site Examples
Example.databuffer BYTE 512 DUP(?)diskStruct DISKIO .codemov ax,7305h; absolute Read/Writemov cx,0FFFFh ; always this valuemov dl,3; drive Cmov bx,OFFSET diskStructmov si,0; read sectorint 21hExample: Read one or more sectors from drive C:
Web site Examples
Sector Display ProgramPseudocode:Ask for starting sector number and drive numberdo while (keystroke ESC)Display headingRead one sectorIf MS-DOS error then exitDisplay one sectorWait for keystrokeIncrement sector numberend doView the source code
Web site Examples
What's NextDisk Storage SystemsFile SystemsDisk DirectoryReading and Writing Disk Sectors (7305h)System-Level File Functions
Web site Examples
System-Level File FunctionsCommon Disk-Related FunctionsGet Disk Free SpaceCreate SubdirectoryRemove SubdirecrorySet Current DirectoryGet Current Directory
Web site Examples
Common Disk-Related Functions
Web site Examples
ExtGetDskFreSpcStruc Structure (1 of 2)StructSize: A return value that represents the size of the ExtGetDskFreSpcStruc structure, in bytes. Level: Always 0. SectorsPerCluster: The number of sectors inside each cluster. BytesPerSector: The number of bytes in each sector. AvailableClusters: The number of available clusters. TotalClusters: The total number of clusters in the volume. Structure data returned by Fucntion 7303h:
Web site Examples
ExtGetDskFreSpcStruc (2 of 2)AvailablePhysSectors: The number of physical sectors available in the volume, without adjustment for compression. TotalPhysSectors: The total number of physical sectors in the volume, without adjustment for compression. AvailableAllocationUnits: The number of available allocation units in the volume, without adjustment for compression. TotalAllocationUnits: The total number of allocation units in the volume, without adjustment for compression. Rsvd: Reserved member.
Web site Examples
Function 7303h Get Disk Free SpaceAX = 7303hES:DI points to a ExtGetDskFreSpcStrucCX = size of the ExtGetDskFreSpcStruc variableDS:DX points to a null-terminated string containing the drive nameView the DiskSpc.asm program
Web site Examples
Create Subdirectory.datapathname BYTE "\ASM",0
.codemov ah,39h; create subdirectorymov dx,OFFSET pathnameint 21hjc DisplayError..DisplayError:
Web site Examples
Remove Subdirecrory.datapathname BYTE 'C:\ASM',0
.codemov ah,3Ah ; remove subdirectorymov dx,OFFSET pathnameint 21hjc DisplayError..DisplayError:
Web site Examples
Set Current Directory.datapathname BYTE "C:\ASM\PROGS",0
.codemov ah,3Bh; set current directorymov dx,OFFSET pathnameint 21hjc DisplayError..DisplayError:
Web site Examples
Get Current Directory.datapathname BYTE 64 dup(0) ; path stored here by MS-DOS
.codemov ah,47h; get current directory pathmov dl,0; on default drivemov si,OFFSET pathname int 21hjc DisplayError..DisplayError:
Web site Examples
Your turn . . .Write a program that creates a hidden, read-only directory named __secret. Create a hidden file inside the new directory named $$temp. Try to remove the directory by calling Function 3Ah. Display the error code returned by MS-DOS.
Web site Examples
SummaryDisk controller: acts as a broker between the hardware and the operating systemDisk characteristicscomposed of tracks, cylinders, sectorsaverage seek time, data transfer rateFormatting & logical characteristicsmaster boot record, contains disk partition tableclusters logical storage unitsfile allocation table used by some systemsdirectory root directory, subdirectories
Web site Examples
The End