** Programmer's Technical Reference for MSDOS and the IBM PC ** 旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � Shareware Version, 03/21/90 � � Please Register Your Copy � 읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴� Copyright (c) 1987, 1990 Dave Williams C H A P T E R E I G H T DOS DISK INFORMATION THE DOS AREA쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� All disks and diskettes formatted by DOS are created with a sector size of 512 bytes. The DOS area (entire area for a diskette, DOS partition for hard disks) is formatted as follows: partition table - variable size (hard disk only) boot record - 1 sector first copy of the FAT - variable size second copy of the FAT - same size as first copy root directory - variable size data area - variable depending on disk size The following sections describe each of the allocated areas: THE BOOT RECORD쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 The boot record resides on track 0, sector 1, side 0 of every diskette formatted by the DOS FORMAT program. For hard disks the boot record resides on the first sector of the DOS partition. It is put on all disks to provide an error message if you try to start up with a nonsystem disk in drive A:. If the disk is a system disk, the boot record contains a JMP instruction pointing to the first byte of the operating system. If the device is IBM compatible, it must be true that the first sector of the first FAT is located at the same sector for all possible media. This is because the FAT sector is read before the media is actually determined. The information relating to the BPB for a particular media is kept in the boot sector for the media. In particular, the format of the boot sector is: 旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커 � D O S B O O T R E C O R D � 쳐컴쩡컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �00h�3 bytes� JMP to executable code. For DOS 2.x, 3 byte near jump (0E9h). � � � � For DOS 3.x, 2 byte near jump (0EBh) followed by a NOP (90h) � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �03h�8 bytes� optional OEM name and version (such as IBM 3.3) � 쳐컴탠컴컴컴탠컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �0Dh� byte � � sectors per allocation unit (must be a power of 2) � 쳐컴탠컴컴컴� 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �0Eh�2 bytes� B � reserved sectors (starting at logical sector 0) � 쳐컴탠컴컴컴� 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �10h� byte � � number of FATs � 쳐컴탠컴컴컴� 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �11h�2 bytes� � maximum number of root directory entries � 쳐컴탠컴컴컴� 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �13h�2 bytes� P � number of sectors in logical image (total number of � � � � � sectors in media, including boot sector directories, etc.)� � � � � If logical disk size is geater than 32Mb, this value is 0 � � � � � and the actual size is reported at offset XXXX � 쳐컴탠컴컴컴� 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �15h� byte � B � media descriptor byte � 쳐컴탠컴컴컴� 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �16h�2 bytes� � number of sectors occupied by a single FAT � 쳐컴탠컴컴컴탠컴컴좔컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �18h�2 bytes� sectors per track � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �1Ah�2 bytes� number of heads � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �1Ch�2 bytes� number of hidden sectors � 읕컴좔컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � EXTENDED BOOT RECORD (DOS 4.0+) � 旼컴쩡컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �1Eh�2 bytes� number of sectors per track � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �20h�2 bytes� number of heads � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �22h�2 bytes� number of hidden sectors � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �26h�4 bytes� total number of sectors in media (32MB or larger indicated here)� 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �27h� byte � physical drive number � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �28h� byte � reserved � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �29h� byte � extended boot record signature � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �30h�4 bytes� volume serial number (assigned with a random function) � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �34h�11bytes� volume label � 쳐컴탠컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 �3Fh�8 bytes� reserved � 읕컴좔컴컴컴좔컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸 The three words at the end return information about the media. The number of heads is useful for supporting different multihead drives that have the same storage capacity but a different number of surfaces. The number of hidden sectors is useful for drive partitioning schemes. DOS 3.2 uses a table called the BIOS Parameter Block (BPB) to determine if a disk has a valid File Allocation Table. The BPB is located in the first sector of a floppy disk. Although the BPB is supposed to be on every formatted floppy disk, some earlier versions of DOS did not create a BPB and instead assumed that the FAT begins at the second sector of the disk and that the first FAT byte (Media Descriptor Byte) describes the disk format. DOS 3.2 reads in the whole of the BPB and tries to use it - although, strangely enough, it seems as if DOS is prepared to cope with a BPB that is more or less totally blank (it seems to ignore the descriptor byte and treat it as a DSDD 9-sector disk). DOS 3.2 determines if a disk has a valid boot sector by examining the first byte of logical sector 0. If that byte it a jump instruction E9h, DOS 3.2 assumes the rest of the sector is a valid boot sector with a BPB. If the first byte is not E9h DOS 3.2 behaves like previous versions, assumes the boot sector is invalid and uses the first byte of the FAT to determine the media type. If the first byte on the disk happens to be E9h, but the disk does not have a BPB, DOS 3.2 will return a disk error message. The real problems occur if some of the BPB data is valid and some isn't. Apparently some OEMs have assumed that DOS would continue to ignore the formatting data on the disk, and have failed to write much there during FORMAT except the media descriptor byte (or, worse, have allowed random junk to be written there). While this error is understandable, and perhaps even forgiveable, it remains their problem, not IBMs, since the BPB area has always been documented as containing the format information that IBM DOS 3.2 now requires to be there. THE DOS FILE ALLOCATION TABLE (FAT)쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 The File Allocation Table, or FAT, has three pain purposes: 1) to mark bad sectors on the media 2) to determine which sectors are free for use 3) to determine the physical location(s) of a file on the media. DOS uses one of four different schemes for defining the File Allocation Table: 1) the 12-bit FAT, for DOS 1.x, 2.x, all floppies, and small hard disks 2) the 16-bit FAT, for DOS 3.x+ hard disks from 16.8 to 32Mb 3) the 32-bit FAT used by Compaq DOS 3.31 and others 4) the 32-bit FAT used by DOS 4.0 over-32Mb logical drives This section explains how DOS uses the FAT to convert the clusters of a file into logical sector numbers. We recommend that system utilities use the DOS handle calls rather than interpreting the FAT. The FAT is used by DOS to allocate disk space for files, one cluster at a time. In DOS 4.0, clusters are referred to as "allocation units." It means the same things; the smallest logical portion of a drive. The FAT consists of a 12 bit entry (1.5 bytes) for each cluster on the disk or a 16 bit (2 bytes) entry when a hard disk has more than 20740 sectors as is the case with fixed disks larger than 10Mb. The first two FAT entries map a portion of the directory; these FAT entries contain indicators of the size and format of the disk. The FAT can be in a 12 or 16 bit format. DOS determines whether a disk has a 12 or 16 bit FAT by looking at the total number of allocation units on a disk. For all diskettes and hard disks with DOS partitions less than 20,740 sectors, the FAT uses a 12 bit value to map a cluster. For larger partitions, DOS uses a 16 bit value. The second, third, and fourth bit applicable for 16 bit FAT bytes always contains 0FFFFh. The first byte is used as follows: 旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커 � M E D I A D E S C R I P T O R B Y T E � 쳐컴컴컴컴컫컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 쿴ex value � meaning � normally used � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � F0 � double sided 18 sector diskette � PS/2 1.44 meg DSHD � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � F8 � hard disk � bootable hard disk at C:800 � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � F9 � double sided 15 sector diskette � AT 1.2 meg DSHD � � � double sided 9 sector diskette � Convertible 720k DSQD � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FA � IBM Displaywriter System disk � 287k � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FB � IBM Displaywriter System disk � 1 meg � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FC � single sided 9 sector diskette � DOS 2.0, 180k SSDD � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FD � double sided 9 sector diskette � DOS 2.0, 360k DSDD � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FE � single sided 8 sector diskette � DOS 1.0, 160k SSDD � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FF � double sided 8 sector diskette � DOS 1.1, 320k SSDD � 쳐컴컴컴컴컨컴컴컴컴컴컫컴컴컴컴컴컴컴컴컴컴컴좔컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸 쿯or 8 inch diskettes: � 쳐컴컴컴컴컫컴컴컴컴컴컨컴컴컴컴컴컴컴컴컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커 � FD � double sided 26 sector diskette � IBM 3740 format DSSD � 쳐컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴캑 � FE � single sided 26 sector diskette � IBM 3740 format SSSD � � 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � � double sided 8 sector diskette � IBM 3740 format DSDD � 읕컴컴컴컴컨컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴좔컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸 The third FAT entry begins mapping the data area (cluster 002). NOTE: These values are provided as a reference. Therefore, programs should not make use of these values. Each entry contains a hexadecimal character (or 4 for 16 bit FATs). () indicates the high order four bit value in the case of 16 bit FAT entries. They can be: (0)000h if the cluster is unused and availible (0F)FF8h - (0F)FFFh to indicate the last cluster of a file (X)XXXh any other hexadecimal numbers that are the cluster number of the next cluster in the file. The cluster number is the first cluster in the file that is kept in the file's directory entry. The values (0F)FF0h - (0F)FF7h are used to indicate reserved clusters. (0F)FF7h indicates a bad cluster if it is not part of the allocation chain. (0F)FF8h - (0F)FFFh are used as end of file markers. The file allocation table always occupies the sector or sectors immediately following the boot record. If the FAT is larger than 1 sector, the sectors occupy consecutive sector numbers. Two copies of the FAT are written, one following the other, for integrity. The FAT is read into one of the DOS buffers whenever needed (open, allocate more space, etc). USE OF THE 12 BIT FILE ALLOCATION TABLE쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 Obtain the starting cluster of the file from the directory entry. Now, to locate each subsequent sector of the file: 1. Multiply the cluster number just used by 1.5 (each FAT entry is 1.5 bytes long). 2. The whole part of the product is offset into the FAT, pointing to the entry that maps the cluster just used. That entry contains the cluster number of the next cluster in the file. 3. Use a MOV instruction to move the word at the calculated FAT into a register. 4. If the last cluster used was an even number, keep the low order 12 bits of the register, otherwise, keep the high order 12 bits. 5. If the resultant 12 bits are (0FF8h-0FFFh) no more clusters are in the file. Otherwise, the next 12 bits contain the cluster number of the next cluster in the file. To convert the cluster to a logical sector number (relative sector, such as that used by int 25h and 26h and DEBUG): 1. Subtract 2 from the cluster number 2. Multiply the result by the number of sectors per cluster. 3. Add the logical sector number of the beginning of the data area. 12-bit FAT if DOS partition is smaller than 32,680 sectors (16.340 MB). USE OF THE 16 BIT FILE ALLOCATION TABLE쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 Obtain the starting cluster of the file from the directory entry. Now to locate each subsequent cluster of the file: 1. Multiply the cluster number used by 2 (each FAT entry is 2 bytes long). 2. Use the MOV word instruction to move the word at the calculated FAT offset into a register. 3. If the resultant 16 bits are (0FF8h-0FFFFh) no more clusters are in the file. Otherwise, the 16 bits contain the cluster number of the next cluster in the file. Compaq DOS makes availible a new disk type (6) with 32 bit partition values, allowing 512 megabytes per hard disk (Compaq DOS 3.3.1) USE OF THE 32 BIT FILE ALLOCATION TABLE쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 DOS 4.0's FORMAT program checks the size of the availible media. If the total number of 8 sector clusters is less than 4086 (not 4096) a 12 bit FAT is used. DOS DISK DIRECTORY쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� The FORMAT command initially builds the root directory for all disks. Its location (logical sector number) and the maximum number of entries are availible through the device driver interfaces. Since directories other than the root directory are actually files, there is no limit to the number of entries that they may contain. All directory entries are 32 bytes long, and are in the following format: 旼컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � BYTES � DISK DIRECTORY ENTRY 쳐컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 0-7 � 8 bytes filename 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � The first byte of the filename indicates the file status. � The file status byte can contain the following values: 쳐컴컴컫컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 00h � Directory entry has never been used. This is used to limit � � the length of directory searches, for performance reasons. � 05h � Indicates that the first character of the filename actually � � has an 0EDh character. � 0E5h � Filename has been used but the file has been erased. � 2Eh � This entry is for a directory. If the second byte is also � � 2Eh, the cluster field contains the cluster number of this � � directory's parent directory. (0000h if the parent directory � � is the root directory). 쳐컴컴컨컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � Any other character is the first character of a filename. Filenames � are left-aligned and if nescessary padded with blanks. 旼컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 8-A � 3 bytes filename extension if any 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � Three characters, left-aligned and padded with blanks if nescessary. � If there is no file extension, this field contains all blanks 旼컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � B � 1 byte file attributes 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � The attribute byte is mapped as follows: 쳐컴컴쩡컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � hex 쿫it� meaning 쳐컴컴탠컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 00h � � (no bits set) normal; can be read or written w/o restriction � 01h � 0 � file is marked read-only. An attempt to open the file for � � � output using function call 3Dh will fail and an error code � � � will be returned. This value can be used with other values � � � below. � 02h � 1 � indicates a hidden file. The file is excluded from normal � � � directory searches. � 04h � 2 � indicates a system file. This file is excluded from normal � � � directory searches. � 08h � 3 � indicates that the entry contains the volume label in the � � � first 11 bytes. The entry has no other usable information � � � and may exist only in the root directory. � 10h � 4 � indicates that the file is a subdirectory � 20h � 5 � indicates an archive bit. This bit is set on whenever the � � � file is written to and closed. Used by BACKUP and RESTORE. � � 6 � reserved � � 7 � reserved 쳐컴컴좔컴좔컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � Bits 6 and 7 are reserved, and must be 0. They may be used in OS/2. � note: Attributes 08h and 10h cannot be changed using int21/43h. � � The system files IBMBIO.COM and IBMDOS.COM (or customized equivalent) � are marked as read-only, hidden, and system files. Files can be � marked hidden when they are created. Also, the read-only, hidden, � system and archive attributes may be changed with int21/43h. 旼컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 0C-15 � 10 bytes reserved by DOS; value unknown 쳐컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 16-17 � 2 bytes file timestamp 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � These bytes contain the time when the file was created or last � updated. The time is mapped in the bits as follows: 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � B Y T E 16h � B Y T E 17h � 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � F E D C B A 9 8 � 7 6 5 4 3 2 1 0 � 쳐컴컴컴컴컴컴컴컴컴쩡컴컴컴컴컴좔컴컴컴컴컴쩡컴컴컴컴컴컴컴컴컴� � H H H H H � M M M M M M � D D D D D � 쳐컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴� � binary # hrs 0-23 � binary # minutes 0-59 � bin. # 2-sec incr � 쳐컴컴컴컴컴컴컴컴컴좔컴컴컴컴컴컴컴컴컴컴컴좔컴컴컴컴컴컴컴컴컴� � note: The time is stored with the least significant byte first. 旼컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 18-19 � 2 bytes file datestamp 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � This area contains the date when the file was created or last � updated. The mm/dd/yy are mapped in the bits as follows: 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � B Y T E 18h � B Y T E 19h � 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � F E D C B A 9 8 � 7 6 5 4 3 2 1 0 � 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴쩡컴좔컴컴컴컴컴쩡컴컴컴컴컴컴컴컴컴� � Y Y Y Y Y Y Y � M M M M � D D D D D � 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴탠컴컴컴컴컴컴컴컴컴� � 0-119 (1980-2099) � 1-12 � 1-31 � 쳐컴컴컴컴컴컴컴컴컴컴컴컴컴좔컴컴컴컴컴컴컴좔컴컴컴컴컴컴컴컴컴� � note: The time is stored with the least significant byte first. 旼컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 1A-1B � 2 bytes first file cluster number 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � * (reserved in DOS 2, documented in DOS 3+) � This area contains the starting cluster number of the first cluster � in the file. The first cluster for data space on all fixed disks and � floppy disks is always cluster 002. The cluster number is stored � with the least significant byte first. 旼컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 1C-1F � 4 bytes filesize 읕컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � This area contains the file size in bytes. The first word contains � the low order part of the size. Both words are stored with the least � significant byte first. 읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� THE DATA AREA쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 Allocation of space for a file (in the data area) is done only when needed (it is not preallocated). The space is allocated one cluser (unit allocation) at a time. A cluster is always one or more consecutive sector numbers, and all of the clusters in a file are "chained" together in the FAT. The clusters are arranged on disk to minimize head movement for multisided media. All of the space on a track (or cylinder) is allocated before moving on to the next track. This is accomplished by using the sequential sector numbers on the lowest-numbered head, then all the sector numbers on the next head, and so on until all sectors of all heads of the track are used. Then the next sector used will be sector 1 of head 0 on the next track. An interesting innovation that was introduced in MS-DOS 3.0: disk space that is freed by erasing a file is not re-used immediately, unlike earlier versions of DOS. Instead, free space is obtained from the area not yet used during the current session, until all of it is used up. Only then will space that is freed during the current session be re-used. This feature minimizes fragmentation of files, since never-before-used space is always contiguous. However, once any space has been freed by deleting a file, that advantage vanishes at the next system boot. The feature also greatly simplifies un-erasing files, provided that the need to do an un-erase is found during the same session and also provided that the file occupies contiguous clusters. However, when one is using programs which make extensive use of temporary files, each of which may be created and erased many times during a session, the feature becomes a nuisance; it forces the permanent files to move farther and farther into the inner tracks of the disk, thus increasing rather than decreasing the amount of fragmentation which occurs. The feature is implemented in DOS by means of a single 16-bit "last cluster used" (LCU) pointer for each physical disk drive; this pointer is a part of the physical drive table maintained by DOS. At boot time, the LCU pointer is zeroed. Each time another cluster is obtained from the free-space pool (the FAT), its number is written into the LCU pointer. Each time a fresh cluster is required, the FAT is searched to locate a free one; in older versions of DOS this search always began at Cluster 0000, but in 3.x it begins at the cluster pointed to by the LCU pointer. For hard disks, the size of the file allocation table and directory are determined when FORMAT initializes it and are based on the size of the DOS partition. Files in the data area are not nescessarily written sequentially on the first. The data area space is allocated one cluster at a time, skipping over clusters already allocated. The first free cluster found is the next cluster allocated, regardless of its physical location on the disk. This permits the most efficient utilization of disk space because clusters freed by erasing files can be allocated for new files. Refer back to the description of the DOS FAT in this chapter for more information. SSDD single sided, double density (160-180k) 5� DSDD double sided, double density (320-360k) 5� DSQD double sided, quad density (720k) 5�, 3� DSHD double sided, high density (1.2-1.44M) 5�, 3� Much of the trouble with AT 1.2 meg drives has been through the inadverdent use of quad density disks in the high density drives. The high density disks use a higher-coercivity media than the quads, and quads are not completely reliable as 1.2M. Make sure you have the correct disk for your application. HARD DISK LAYOUT쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� The DOS hard disk routines perform the following services: 1) Allow multiple operating systems to utilize the hard disk without the need to backup and restore files when changing operating systems. 2) Allow a user-selected operating system to be started from the hard disk. I) In order to share the hard disk among operating systems, the disk may be logically divided into 1 to 4 partitions. The space within a given partition is contiguous, and can be dedicated to a specific operating system. Each operating system may "own" only one partition in DOS versions 2.0 through 3.2. PCDOS 3.3 introduced the "Extended DOS Partition" which allows multiple DOS partitions on the same hard disk. The FDISK.COM (or similar program from other DOS vendors) utility allows the user to select the number, type, and size of each partition. The partition information is kept in a partition table that is embedded in the master fixed disk boot record on the first sector of the disk. The format of this table varies from version to version of DOS. II) An operating system must consider its partition to be the entire disk, and must ensure that its functions and utilities do not access other partitions on the disk. III) Each partition may contain a boot record on its first sector, and any other programs or data that you choose - including a copy of an operating system. For example, the DOS FORMAT command may be used to format and place a copy of DOS in the DOS partition in the same manner that a diskette is formatted. With the FDISK utility, you may designate a partition as "active" (bootable). The master hard disk boot record causes that partition's boot record to receive control when the system is started or reset. Additional disk partitions could be FORTH, UNIX, Pick, CP/M-86, or the UCSD p-System. SYSTEM INITIALIZATION쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 The boot sequence is as follows: 1. System initialization first attempts to load an operating system from diskette drive A. If the drive is not ready or a read error occurs, it then attempts to read a master hard disk boot record on the first sector of the first hard disk in the system. If unsuccessful, or if no hard disk is present, it invokes ROM BASIC in an IBM PC or displays a disk error message on most compatibles. 2. If initialization is successful, the master hard disk boot record is given control and it examines the partition table embedded within it. If one of the entries indicates an active (bootable) partition, its boot record is read from the partition's first sector and given control. 3. If none of the partitions is bootable, ROM BASIC is invoked on an IBM PC or a disk error on most compatibles. 4. If any of the boot indicators are invalid, or if more than one indicator is marked as bootable, the message INVALID PARTITION TABLE is displayed and the system stops. 5. If the partition's boot record cannot be successfully read within five retries due to read errors, the message ERROR LOADING OPERATING SYSTEM appears and the system stops. 6. If the partition's boot record does not contain a valid "signature", the message MISSING OPERATING SYSTEM appears, and the system stops. NOTE: When changing the size or location of any partition, you must ensure that all existing data on the disk has been backed up. The partitioning program will destroy the data on the disk. System programmers designing a utility to initialize/manage a hard disk must provide the following functions at a minimum: 1. Write the master disk boot record/partition table to the disk's first sector to initialize it. 2. Perform partitioning of the disk-that is, create or update the partition table information (all fields for the partition) when the user wishes to create a partition. This may be limited to creating a partition for only one type of operating systewm, but must allow repartitoning the entire disk, or adding a partition without interfering with existing partitions (user's choice). 3. Provide a means for marking a user-specified partition as bootable and resetting the bootable indicator bytes for all other partitions at the same time. 4. Such utilities should not change or move any partition information that belongs to another operating system. BOOT RECORD/PARTITION TABLE쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 A boot record must be written on the first sector of all hard disks, and must contain the following: 1. Code to load and give control to the boot record for one of four possible operating systems. 2. A partition table at the end of the boot record. Each table entry is 16 bytes long, and contains the starting and ending cylinder, sector, and head for each of four possible partitions, as well as the number of sectors preceding the partition and the number of sectors occupied by the partition. The "boot indicator" byte is used by the boot record to determine if one of the partitions contains a loadable operating system. FDISK initialization utilities mark a user-selected partition as "bootable" by placing a value of 80h in the corresponding partition's boot indicator (setting all other partitions' indicators to 0 at the same time). The presence of the 80h tells the standard boot routine to load the sector whose location is contained in the following three bytes. That sector is the actual boot record for the selected operating system, and it is responsible for the remainder of the system's loading process (as it is from the diskette). All boot records are loaded at absolute address 0:7C00. The partition table with its offsets into the boot record is: (except for Wyse DOS 3.2 with 32 bit allocation table, and DOS 3.3-up) 旼컴컴컫컴컴컴컴쩡컴컴컴컴컴컴컴컴컫컴컴컴컴컴쩡컴컴컴컴컫컴컴컴컴컴쩡컴컴컴컴커 쿚ffset쿛artit'n� Purpose � � Head � Sector � Cylinder � 쳐컴컴컵컴컴컴컴탠컴컴컴컴컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴캑 � 1BEh � part 1 � begin � boot ind � H � S � cyl � 쳐컴컴컵컴컴컴컴탠컴컴컴컴컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴캑 � 1C2h � � end � syst ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴캑 � 1C6h � � relative sector � low word � high word � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴캑 � 1CAh � � # sectors � low word � high word � 쳐컴컴컵컴컴컴컴탠컴컴컴컴컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴캑 � 1CEh � part 2 � begin � boot ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴캑 � 1D2h � � end � syst ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴캑 � 1D6h � � relative sector � low word � high word � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴캑 � 1DAh � � # sectors � low word � high word � 쳐컴컴컵컴컴컴컴탠컴컴컴컴컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴캑 � 1DEh � part 3 � begin � boot ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴캑 � 1E2h � � end � syst ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴캑 � 1E6h � � relative sector � low word � high word � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴캑 � 1EAh � � # sectors � low word � high word � 쳐컴컴컵컴컴컴컴탠컴컴컴컴컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴캑 � 1EEh � part 4 � begin � boot ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴컵컴컴컴컴컴탠컴컴컴컴캑 � 1F2h � � end � syst ind � H � S � cyl � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴컵컴컴컴컴컴좔컴컴컴컴캑 � 1F6h � � relative sector � low word � high word � 쳐컴컴캑 쳐컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴캑 � 1FAh � � # sectors � low word � high word � 쳐컴컴컵컴컴컴컴좔컴컴컴컴컴컴컴컴컵컴컴컴컴컴쩡컴컴컴컴컵컴컴컴컴컴컴컴컴컴컴켸 � 1FEh � signature � hex 55 � hex AA � 읕컴컴컨컴컴컴컴컴컴컴컴컴컴컴컴컴컨컴컴컴컴컴좔컴컴컴컴켸 Boot indicator (boot ind): The boot indicator byte must contain 0 for a non- bootable partition or 80h for a bootable partition. Only one partition can be marked as bootable at a time. System Indicator (sys ind): The sys ind field contains an indicator of the operating system that "owns" the partition. IBM PC-DOS can only "own" one partition, though some versions of MSDOS allow all four partitions to be used by DOS. The system indicators are: 旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � System Indicator (sys ind) � 쳐컴컴컴쩡컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 00h � unknown or unspecified � 쳐컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 01h � DOS 12 bit FAT (DOS 2.x all and 3.x under 10 Mb) � 쳐컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 04h � DOS 16 bit FAT (DOS 3.x+. Not recognized by 2.x) � 쳐컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 0DBh � DRI Concurrent DOS � 쳐컴컴컴탠컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� � 0F2h � 2nd DOS partition, some 3.2 and all 3.3 � 읕컴컴컴좔컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴� There are bytes for XENIX, and other operating systems. Some manufacturers (such as Zenith, Wyse, and Tandon) diddle with these system bytes to implement more than one DOS partition per disk. Cylinder (CYL) and Sector (S): The 1 byte fields labelled CYL contain the low order 8 bits of the cylinder number - the high order 2 bits are in the high order 2 bits of the sector (S) field. This corresponds with the ROM BIOS interrupt 13h (disk I/O) requirements, to allow for a 10 bit cylinder number. The fields are ordered in such a manner that only two MOV instructions are required to properly set up the DX and CX registers for a ROM BIOS call to load the appropriate boot record (hard disk booting is only possible from the first hard disk in the system, where a BIOS drive number of 80h corresponds to the boot indicator byte). All partitions are allocated in cylinder multiples and begin on sector 1, head 0, with the exception that the partition that is allocated at the beginning of the disk starts at sector 2, to account for the hard disk's master boot record. Relative Sector (rel sect): The number of sectors preceding each partition on the disk is kept in the 4 byte field labelled "rel sect". This value is obtained by counting the sectors beginning with cylinder 0, sector 1, head 0 of the disk, and incrementing the sector, head, and then track values up to the beginning of the partition. This, if the disk has 17 sectors per track and 4 heads, and the second partition begins at cylinder 1, sector 1, head 0,and the partition's starting relative sector is 68 (decimal) - there were 17 sectors on each of 4 heads on 1 track allocated ahead of it. The field is stored with the least significant word first. Number of sectors (#sects): The number of sectors allocated to the partition is kept in the "# of sects" field. This is a 4 byte field stored least significant word first. Signature: The last 2 bytes of the boot record (55AAh) are used as a signature to identify a valid boot record. Both this record and the partition boot record are required to contain the signature at offset 1FEh. HARD DISK TECHNICAL INFORMATION쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 Western Digital's hard disk installation manuals make the claim that MSDOS can support only 2 hard drives. This is entirely false, and their purpose for making the claim is unclear. DOS merely performs a function call pointed at the hard disk driver, which is normally in one of three locations; a ROM at absolute address C:800, the main BIOS ROM if the machine is an AT, or a device driver installed through the CONFIG.SYS file. Two hard disk controller cards can normally not reside in the same machine due to lack of interrupt arbitration. Perstor's ARLL controller and some cards marketed by Novell can coexist with other controllers. Perstor's technical department has had four controllers and eight hard disks in the same IBM XT functioning concurrently. A valid hard disk has a boot record arranged in the following manner: DB drive ; 0 or 80h (80h marks a bootable, active partition) DB head1 ; starting heads DW trksec1 ; starting track/sector (CX value for INT 13) DB system ; see below DB head2 ; ending head DW trksec2 ; ending track/sector DD sector1 ; absolute # of starting sector DD sector2 ; absolute # of last sector The master disk boot record invokes ROM BASIC if no indicator byte reflects a bootable system. When a partition's boot record is given control, it is passed its partition table entry address in the DS:SI registers. DETERMINING FIXED DISK ALLOCATION쳐컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 DOS determines disk allocation using the following formula: D * BPD TS - RS - 컴컴컴컴컴� BPS SPF = 컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴 BPS * SPC CF + 컴컴컴컴컴컴컴 BPC where: TS total sectors on disk RS the number of sectrs at the beginning of the disk that are reserved for the boot record. DOS reserves 1 sector. D The number of directory entries in the root directory. BPD the number of bytes per directory entry. This is always 32. BPS the number of bytes per logical sector. Typically 512, but you can specify a different number with VDISK. CF The number of FATS per disk. Usually 2. VDISK is 1. SPF the number of sectors per FAT. Maximum 64. SPC The number of sectors per allocation unit. BPC the number of bytes per FAT entry. BPC is 1.5 for 12 bit FATs. 2 for 16 bit FATS. To calculate the minimum partition size that will force a 16-bit FAT: CYL = (max clusters * 8)/(HEADS * SPT) where: CYL number of cylinders on the disk max clusters 4092 (maximum number of clusters for a 12 bit FAT) HEADS number of heads on the hard disk SPT sectors per track (normally 17 on MFM) DOS 2.0 uses a "first fit" algorithm when allocating file space on the hard disk. Each time an application requests disk space, it will scan from the beginning of the FAT until it finds a contiguous piece of storage large enough for the file. DOS 3.0 keeps a pointer into the disk space, and begins its search from the point it last left off. This pointer is lost when the system is rebooted. This is called the "next fit" algorithm. It is faster than the first fit and helps minimize fragmentation. In either case, if the FCB function calls are used instead of the handle function calls, the file will be broken into pieces starting with the first availible space on the disk.