An Inside Look at MS-DOS The design decisions behind the popular

Tim Paterson Computer Products 1114 Industry Dr. Seattle, WA 98188

The purpose of a personal com- often on the first try. Unfortunately, read-only memory). Both of these puter operating system is to provide many of the software developers tools had been developed in house. the user with basic control of the Seattle Computer talked to in the machine. A less obvious function is to earlier days preferred to simply ig- MS-DOS Organization furnish the user with a high-level, nore MS-DOS. Until the IBM Per- The core of MS-DOS is a device- machine-independent interface for sonal Computer was announced, independent input/output (I/O) han- application programs, so that those these developers felt that CP/M-86 dler, represented on a system disk by programs can run on two dissimilar would be the operating system of the hidden file MSDOS.SYS. It ac- machines, despite the differences in 8086/8088 computers. cepts requests from application pro- their peripheral hardware. Having Other concerns crucial to the grams to do high-level I/O, such as designed an 8086 microprocessor card design of MS-DOS were speed and ef- sequential or random access of named for the S-100 bus and not finding an ficiency. Efficiency primarily means disk files, or communication with appropriate disk operating system on making as much disk space as possi- character devices such as the console. the market, Seattle Computer Prod- ble available for storing data by mini- The handler processes these requests ucts set about designing MS-DOS. mizing waste and overhead. The and converts them to a very low level Today MS-DOS is the most widely problem of speed was attacked three form that can be handled by the I/O used disk operating system for per- ways: by minimizing the number of system. Because MSDOS.SYS is sonal computers based on Intel's 8086 disk transfers, making the needed hardware independent, it is nearly and 8088 microprocessors. disk transfers happen as quickly as identical in all MS-DOS versions pro- possible, and reducing the DOS's vided by manufacturers with their MS-DOS Design Criteria "compute time," considered overhead equipment. Its relative location in The primary design requirement of by an application program. The en- memory is shown in figure 1. MS-DOS was CP/M-80 translation tire file structure and disk interface The I/O system is totally device compatibility, meaning that, if an were developed for the greatest speed dependent and is represented on the 8080 or Z80 program for CP/M were and efficiency. disk by the hidden file IO.SYS. It is translated for the 8086 according to The last design requirement was normally written by hardware manu- Intel's published rules, that program that MS-DOS be written in assembly facturers (who know their equipment would execute properly under MS- language. While this characteristic best, anyway) with the notable excep- DOS. Making CP/M-80 translation does help meet the need for speed and tion of IBM, whose I/O system was compatibility a requirement served to efficiency, the reason for including it written to IBM's specifications by promote rapid development of 8086 is much more basic. The only 8086 . The tasks required of the software, which, naturally, Seattle software-development tools available I/O system, such as outputting a Computer was interested in. There to Seattle Computer at that time were single byte to a character device or was partial success: those software an assembler that ran on the Z80 reading a contiguous group of developers who chose to translate under CP/M and a monitor/de- physical disk sectors into memory, their CP/M-80 programs found that bugger that fit into a 2K-byte are as simple as possible. they did indeed run under MS-DOS, EPROM (erasable programmable The command processor furnishes

230 June 1963 © BYTE Publications Inc Circle 122 on Inquiry card. --p- the standard interface between the -TOP OF MEMORY cludes error trapping, batch-file pro- user and MS-DOS and is contained in COMMAND TRANSIENT cessing, and reloading of the tran- the visible file COMMAND.COM. sient . The transient interprets user The processor's purpose is to accept commands; it resides at the high end commands from the console, figure of memory where it can be overlaid out what they mean, and execute the with any applications program (some correct sequence of functions to get of which need as much memory as the job done. It is really just an or- PROGRAM MEMORY they can get). This feature is of dinary application program that does limited value in systems with large its work using only the standard MS- main memory, and it need not be im- DOS function requests. In fact, it can itated by programs used as a replace- be replaced by any other program ment for COMMAND. that provides the needed user inter- COMMAND provides both a use- face. ful set of built-in commands and the There are, however, two special COMMAND RESIDENT ability to execute program files features of the COMMAND file. located on the disk. Any file ending First, it sets up all basic error trapping MS-DOS with the extensions COM, EXE, or for either hard-disk errors or the Con- .BAT can be executed by COM- trol-C abort command. MSDOS.SYS 1/0 SYSTEM MAND simply by typing the first provides no default error handling 00400 part of the file name (without exten- but simply traps through a vector INTERRUPT VECTORS sion ). You can normally enter 00000 that must have been previously set. parameters for these programs on the Setting the trap vector and providing command line, as with any of the Figure 1: Map of memory areas as as- a suitable error response is up to signed by MS-DOS. built-in commands. Overall, the ef- COMMAND (or whatever program fect is to give you a command set that might be used to replace it). can be extended almost without limit The second special feature is that sient sections . The resident, which just by adding the command as a pro- COMMAND splits itself into two sits just above MS-DOS in low gram file on the disk. pieces, called the resident and tran- memory, is the essential code and in- The three different extensions

t. %I[Clil PRODUCT DESCRIPTION LIST YOUR COST*11 UDS 103LP, 300 bps, Modem 145 130 UDS 202LP , 1200 bps , Half Duplex Modem 195 150 ZX FORTH LIDS 212LP, 1200 bps, Full Duplex (212A) Modem 445 CALL U.S. Robotics Auto Dial 212A , 300/1200 Full Duplex Modem 599 475 Incomm Auto Dial 212A , 300/1200 Full Duplex Modem 599 450 Simplicity of BASIC with the speed Cermetec Auto Dial 212A , 300/1200 Full Duplex Modem 595 495 Microband Auto Dial 212A , 300/1200 Full Duplex Modem 695 495 of machine code! Rixon Intelligent Modem , 300/1200 ( 10 Number ) 495 CALL Rixon PC 212A ( IBM PC Modem Card) 300 / 1200 495 CALL Incomm Multi Dial 300/ 1200 ( 10 Number ) 795 550 U.S. Robotics Password 300 /1200 (Auto Dial ) Modem 495 CALL U.S. Robotics Courier, Osborne, 300/1200 Modem 518 CALL U.S. Robotics 5.100 , 300/1200 Auto Dial Modem 495 CALL A complete implementation of the FORTH language for computer. Visua150 CRT 695 550 the ZX81 and TS1000 FORTH 's most dis- Freedom 100 CRT, w/20 F. keys & Editing 595 550 tinctive feature is its flexability. It can turn your computer Incomm Remote Station I, w/Integrated 300/1200 Modem 1295 995 into a "word processor". The basic unit is the WORD - Epson MX60 /Graftrax + 650 399 the programmer uses existing WORDS to define his Epson MX80 FT/Graftrax + 700 498 Epson MX100 /Graftrax + 900 700 own which can then be used in further definitions. This Epson FX80 750 656 makes program development much faster than other Star Micranics Gemini 10 399 350 Star Micranics Gemini 15 649 548 languages. FORTH is an interactive compiled language AJ letter Quality Printer , 30 CPS (KSR) 1450 1250 that expands the capabilities of your own ZX81 /TS1000. Inc- AB Switch , 8 Pin 120 84 Programs run up to 10 times faster than BASIC. The Inc,,, AB Switch , 25 Pin 159 98 Incomm ABC Switch , 25 Pin 198 138 more programs you have written, the more words, therefore you can draw on those for further programs. ID SBreakout Box (Blue Box ) 159 140 Incomm Breakout Box (Bob ) 150 120 FORTH is supplied on cassette and is accompanied by -70 a 56 page users manual and an 8 page editors manual. Epson , HX-20 .AA /95 CALL Epson OX -10/256K 2995 CALL Z43 $29.95 Zenith Z -100 4000 CALL

T-7MM, 7 Pin, 4 Wire, Telephone Cable ( Modular Plugs) 10 7 5.975, Modular Double Adapter 7 5 EIA 9/5 , RS 232 . 9 Pin Cable , 5 FT MM / FF/MF 15 12 EIA 25/5, RS 232 , 25 Pin Cable , 25 FT MM/FF/MF 22 14 EIA 50 /5, Centronics Parallel Cable , 5 FT (36 Pin) 30 21 Call toll free 1-800-833-8400 MC 0050/ 10, Centronics 10 Ft . MM Cable , 36 Pin (10 FT) 38 25 N.Y.(716)874-5510 7010/5, IBM PC Printer Cable w /36 Pin 40 22 In Canada call toll free 1 -800-268-3640 8010/5 Apple II Printer Cable w/36 Pin 27 18 9010/5, Atari Printer Cable w /36 Pin 30 21

U.S. Robotic, Telpac 79 CALL Rixon PC Core 1 (IBM PC Software ) 69 CALL GLansTonF'l'y I'rELECTRonIcs

ORDER TOLL FREE - 1-S00-323-2666 1585 Kenmore Ave., Buffalo, N.Y. 14217 TOUMAYAN & ASSOCIATES We Welcome :Visa, M astercharge Checks Cheques or money orders . No C.O .D.s. Add shipping N , Wolf Rd iCompa nY P.O. , IL 60090 312-459-8866 Wheeling •C.O.D. (Add 51 50/Shipment) In Canada : 1736 Avenue Rd., Toronto , Ont. M5M 3Y7 Canada : Prices may vary

232 June 1963 © BYTE Publications Inc Circle 452 on Inquiry card . Circle 451 on inquiry card. allowed on program files represent different internal file formats.

•.COM files are pure binary pro- grams that will run in any 8086 mem- ory segment; in order for this to be possible, the program and data would ordinarily have to be entirely in one 64K-byte segment. •.EXE files include a header with relocation information so that the program may use any number of seg- ments ; all intersegment references are adjusted at load time to account for the actual load segment. •.BAT (batch) files are text files with commands to be executed in sequence by COMMAND.

File Structure Disks are always divided up into tracks and sectors, as shown in figure 2. To access any particular block of data, the program first moves to the correct track, then has you wait while the spinning disk moves the correct sector under the head. A somewhat more abstract view of disks was taken in developing MS- DOS. MS-DOS views the disk, not in Figure 2: Placement of disk sectors in IBM Personal Computer (single-sided) . terms of tracks and sectors, but as a continuous array of n logical sectors, numbered from 0 to n -1. Figure 2 MS-DOS file system. Any other strap loader . Because the loader is shows the usual method of number- method may be used, and MS-DOS usually very simple, only one sector ing the logical sectors. Logical sector wouldn't know the difference. Hav- is normally reserved. 0 is the first sector of the outermost ing a standard mapping, however, is The FAT (), a track; the rest of the track (and the essential for interchanging disks be- map of how space is distributed next, etc.) is numbered sequentially. tween computer systems with dif- among all files on the disk, comes Logical sector n-1 is the last sector ferent peripheral hardware. next . Because it is so important, two on the innermost track. As shown in table 1, the MS-DOS copies are usually kept side by side. If The mapping of logical sectors to file system divides the linear array of one cannot be read because of a physical track and sector is done by logical sectors into four groups. The failure in the medium, the second will the hardware-dependent I/O System first of these is the reserved area, be used. and is completely transparent to the whose purpose is to hold the boot- The directory follows the FAT.

BYTE Logical 0 1 2 3 4 7 LOCATION 5 6 Sector Numbers Use 0 NAME 0 Reserved for bootstrap loader ATTRI- 8 EXTENSION ZEROS 1-6 FAT 1 file allocation BUTES 7-12 FAT 2 tables (FATS) 13-29 Directory 16 ZEROS TIME 30-2001 Data POINTER 24 DATE SIZE IN BYTES TO FAT Table 1: Map of disk areas on an 8-inch single-sided, single-density flop- py disk. Figure 3 : Arrangement of bytes in disk directory entry.

234 June 1983 © BYTE Publications Inc 64, or 128 logical sectors, but the ly. It is, however, present in more number is fixed for a given disk for- Logical Allocation Unit primitive systems, such as the UCSD Sector Number mat. Allocation units are numbered p-System. Numbers sequentially. The numbering starts It would certainly seem desirable to with 2; the first two numbers, 0 and 30-33 2 (first allocation minimize internal fragmentation by unit) 1, are reserved. Table 2 shows this making the allocation unit as small as 34-37 3 numbering system applied to the possible-always one sector, for ex- 38-41 4 8-inch single-density disk format. 42-45 5 ample. However, for any given disk The allocation unit is the smallest size, the smaller the unit, the more unit of space MS-DOS can keep track there must be. Keeping track of all of. The amount of space used on the those units can get to be a problem. 1998 • 2001 494 disk for each file is some whole num- Specifically, the amount of space re- ber of allocation units. Even if the file quired in the file allocation table Table 2: Allocation unit numbering for is only 1 byte long, an entire unit will would be quite large if there were too the 8-inch single-density format. To be dedicated to it. many small allocation units. For compute the logical sector number of For example, the standard format every unit, 1.5 bytes are required in the first sector in an allocation unit, for 8-inch single-density disks uses the FAT; there are normally two you use the following equation: sector four 128-byte sectors per allocation FATs on the disk, each of which is number = 4 X allocation unit number + 22. unit. When a new file is first created, rounded up to a whole number of sec- no space is allocated, but an entry is tors. made in the directory. Then when the Now take a standard 8-inch single- first byte is written to the file, one density floppy disk that has 2002 sec- LOGICAL allocation unit (four sectors) is as- tors of 128 bytes. To minimize inter- SECTOR NUMBER signed to the file from the available nal fragmentation, choose the small-

38 free space. As each succeeding byte is est possible allocation-unit size of one written, the size of the file is kept up- sector. Two thousand allocation units 39 ALLOCATION UNIT 4 dated to the exact byte, but no more will require 3000 bytes (24 sectors) 40 space is allocated until those first four per FAT, or 48 sectors for two FATS. 41 sectors are completely full. Then to If the average file size is 16K bytes 42 FILE DATA write 1 byte more than those four sec- (128 sectors), the disk will be full 43 ALLOCATION tors worth, another four-sector allo- when there are 16 files on it. Waste UNIT 5 44 cation unit is taken from free space due to internal fragmentation would 45 and assigned to the file. be PARTIALLY 46 When writing stops, the last alloca- UNUSED Il SECTOR - 47 tion unit will be filled by some ran- 16 files X 64 bytes per file = ALLOCATION UNIT 6 dom amount of data (figure 4). The 1024 bytes (8 sectors) COMPLETELY 48 UNUSED unused space in the last allocation 49 SECTORS unit is wasted and can never be used Far more space is occupied by the as long as the file remains unchanged FATs on the disk than is wasted by on the disk. This wasted space is internal fragmentation! Figure 4: Assignment of logical sectors to called internal fragmentation, To provide maximum usable data allocation units. Note that, in the file because it is part of the space space on the disk, both internal frag- shown, more than two sectors are wasted allocated to the file but is an unusable mentation and FAT size must be con- because they are in an unused part of the fragment. On the average, the last sidered because both consume data last allocation unit. allocation unit (regardless of size) will area . The standard MS-DOS format be half filled and, therefore, half for 8-inch single-density disks strikes wasted. Because each file wastes an a balance by using four sectors per Each file on the disk has one 32-byte average of one-half an allocation allocation unit. Two sectors per unit entry in the directory, which includes unit, the total amount of space would have been just as good (assum- the file name, size, date and time of wasted on a disk due to internal frag- ing a 16K-byte average file size), but last write, and special attributes. Each mentation is the number of files times there is another factor that always entry also has a pointer to a place in one-half the allocation unit size. favors smaller FATs and larger allo- the FAT that tells where to find the The phenomenon called external cation units: the entire FAT is kept in data in the file. Figure 3 shows the fragmentation occurs when a piece of main memory at all times. layout of a directory entry. data space is unallocated yet remains The file allocation table contains all The rest of the disk is the data area. unused because it is too small. This information regarding which alloca- It is divided into many small, equal- cannot happen in the MS-DOS file tion units are part of which file. Thus sized areas called allocation units. system because MS-DOS does not re- by keeping it in main memory, any Each unit may have 1, 2, 4, 8, 16, 32, quire files to be allocated contiguous- file can be accessed either sequentially

236 June 1983 © BYTE Publications Inc (5a) FILE or randomly without going to disk are also allocation unit numbers. ALLOCATION TABLE except for the data access itself. Think of the FAT as a map, or trans- DIRECTORY RESERVED 0 Schemes used in other operating - lation table, that takes an allocation ENTRY ENTRIES 1 tems (including CP/M and Unix) may unit number as input and returns a 7 different allocation unit number as 3 9 require one or more disk reads simply 4 -1 to find out where the data is, par- output. The input can be any unit -s ticularly with a random access. In an that is part of a file; the number 6 1633 7 8 application such as a database in- returned is the next sequential unit of 8 quiry, where frequent random access that file. 9 10 10 is the rule, this can easily make a 2 to Let's look at the example in figure 10 1 11 22 1 difference in performance. 5a. Suppose that the directory entry for a file specifies allocation unit How the FAT Works number 5 as the first of the file. This The directory entry for each file locates the first four logical sectors has one allocation unit number in it: (512 bytes). To find the next alloca- (5b) the number of the first unit in the file. tion unit of the file, look at entry 5 in the file allocation table. The 6 there FF FF FF 07 90 00 FF 6F If, as in the previous example, an allocation unit consists of four sectors tells you two things: first, the next 00 03 80 00 FF AF 00 FF of 128 bytes each, then just by look- four logical sectors of the file are in ing at the directory you know where allocation unit number 6; and second, 6F 01 to find the first 512 bytes of the file. If to find the unit after that, look at the file is larger than this, you go to FAT entry number 6. Figure 5: Finding data via the directory the FAT. This process is repeated as you and the file allocation table. Figure 5a The FAT is a one-dimensional ar- locate each allocation unit in the file. shows how pointers are used to direct the ray of allocation unit numbers. As After number 6 comes number 3, then operating system to the sequential parts of with any array, a given element is number 9, then number 10. In each a file. The data stored in the sample file- found with a numeric index. The case, the allocation unit number allocation table is displayed in hexadeci- returned by the FAT tells you both mal in figure 5b. numbers used as indexes into the FAT

I RS.TEL•IARtDRI,VE .1^ ^ A SOLID ST^SK EM+TOR 1 Save valuable time! 5 to 5 0 times faster performance than floppy disks and Winchester drives PION'S INTERSTELLAR DRIVE is designed for use with a family of interfaces and software packages. Currently avail- able are interfaces for IBM, 5100, TRS80, Apple, SS50, and most Z80 uP, and software for most popular operating systems. Additional interfaces are continually being developed for the most popular computers. SAVE MONEY! Basic Price for 256KB unit [includes interface and software] Increase your noIC n plus tax (where applicable) and shipping VISA computer's productivity Visa and Master Card accepted . '^^ ^nv The INTERSTELLAR DRIVE is a high performance data storage subsystem with independent power PION ,INC. Tel.(6171923-8009 supply, battery backup, and error detection. It has 101 R Walnut St.,Watertown, MA 02172 256KB to I Megabyte of solid state memory integrated TRS80 trademark of Tandy Corp. Apple trademark of Apple Computers to perform with your operating system. Interstellar Drive trademark of PION, Inc.

Inc Circle 304 on inquiry card. 238 June 1983 © BYTE Publications Circle 56 on inquiry card.

where the data is (i.e., in which unit) CARTRIDGE DUAL SPOOL RIBBONS FOR RIBBONS FOR CARTRIDGE RIBBONS FOR and where to look in the FAT for the OKIDATA APPLE PRINTERS EPSON next allocation unit number. NEC 8023A PRINTERS If you followed the example all the way through, you should have no- C. ITOH PROWRITER MX-80 MX-100 80, 82, 83 EA DOZ ticed that entry 10 in the FAT con- S6.SEA S11. 5EA 92, 93 S2.7 529.92 tains a -1. This, as you might have 19.95 E. . 46 .0, . 586."EA 5129.06DOZ 1107 84 55.99 564.69 guessed, is the end-of-file mark. Allo- INNOVATIVE cation unit number 10 is last in the LABEL MAXELL CONCEPTS file, so its entry contains this special SPECIAL DISKETTES flag. (Another special value in the 5's" SINGLE SIDE FLIP'N'FILE DISC STORAGE BOX FAT is 0, which marks a free alloca- DUAL DENSITY HOLDS UP TO 60 DISKETTES MD-1 tion unit.) 51/4 " 8" $ 209 9/ K Now you know that this file oc- 5) $ cupies five allocation units, numbers 1 ACROSS 3 • 1516 CONTINUOUS LABELS $29.91°(r S24. 95EA 29 n ^JEA 5, 6, 3, 9, and 10 in order. The file could be extended by finding any free COMPLETE LINE OF OTHER RIBBONS AVAILABLE, PLEASE CALL unit, say 27, putting its number in en- ALL ABOVE PRICES INCLUDE SHIPPING 4 try 10 (where the -1 is now), and marking it with the -1 for end of file. That is, entry 10 in the FAT will con- Check-Mat^ tain 27, and entry 27 will contain -1. 5 1 DIAUTO DR. P.O . BOX 103 ws This demonstrates how you can ex- ii § RANDOLPH, MA 02368 tend any file at will and that you can TOLL FREE 800-343-7706 IN MASS 617-963-7694 use any free space on the disk when WE ACCEPT MASTER CARD & VISA needed, without regard to its physical MASS. RESIDENTS ADD 5% SALES TAX PHONES OPEN 9AM-7PM EASTERN TIME location. If you ever want to look at a real FAT, there's one more thing you'll need to know. Each FAT entry is 12 bits (1.5 bytes) long. These entries are packed together, so two of them fit in 3 bytes. From a programming view- point, you would look up an entry in the FAT this way: Multiply the entry number by 11/2, truncating it to an in- teger if necessary. Fetch the 16-bit word at that location in the FAT. If the original entry number was odd (so that truncation was necessary in L a the first step), shift the word right 4 for any wtord'or bits; the lowest 12 bits of the word is phrase. Any portion of the the contents of the FAT entry. Read- Bible can be printed or ing a FAT from a hexadecimal dump displayed. Create your own isn't nearly as simplel Figure 5b library of research materials shows the hexadecimal version of the or use ours, called TOPICS: sample FAT I've been using. TOPICS contains cross-reference indexes on over 200 of the primary subjects discussed in Scripture. File System in Action To put all this in perspective, you Bible Research Systems applies computer technology need to look at how MS-DOS handles to personal study of the Scriptures. a file-transfer request from an appli- cation program. With MS-DOS, ap- Bible Research Systems plication programs treat files as if TOPICS THE WORD they were divided into logical rec- $49.95 9415 Burnet, Suite 208 processor Austin, TX 78758 ords. The size of the logical record is (512) 835-7981 $199.95 entirely dependent on the application and may range from 1 byte to 65,535 APPLE 1+, IBM.PC, TESSO4i1 o, CP/M R ` {Trademark mF APPLE, bytes. It is not a permanent feature of

242 June 1983 © BYTE Publications Inc Circle 43 on inquiry card. (6a) the sector within the allocation unit. byte position 1200 For this example with single-density tes = 9, remainder 48 8-inch disks (four sectors per alloca- 128 b-^- r sector tion unit), this would be the third unit from the start of the file and the sec- Therefore, first byte to transfer is sector 9, byte 48 ond sector within the unit (figure 6b). What you need to do now is skip 128 - 48 = 80 bytes to transfer in first sector through the FAT to the third alloca- 1200 - 80 = 1120 bytes left after first sector tion unit in the file. If your file is the same one shown in figure 5, then 1120 bytes = 128 bps 8, remainder 96 from the directory entry you learn sector that the first unit is number 5. Look- ing at entry 5 of the FAT, you see the second unit is number 6. And finally, Therefore, transfer 8 whole sectors, then 96 bytes of last sector from entry 6 of the FAT, you find the third unit of the file, number 3. Table (6b) 2 reminds you that allocation unit number 3 is made up of physical sec- 9 sectors = 2, remainder 1 tors 34, 35, 36, and 37; therefore, 4 sectors physical sector 35 is what you are allocation unit looking for. Now the disk reads begin. Physical Therefore, first sector to transfer is allocation unit 2, sector 1. sector 35, only part of which is need- ed, is read into the single buffer kept Figure 6 : Calculating physical, byte-level operations from logical definitions. The pro- in MS-DOS solely for this purpose. cess outlined in figure 6a shows how the amount of data is calculated in physical terms. Then that part of the sector that is The actual position of data on the disk is computed in figure 6b. needed is moved as a block into the place requested by the application a file but in fact may vary from one number of bytes to transfer (also program. file-transfer request to the next. The 1200). Next, the whole sectors are read. logical record size currently being Next, these numbers must be put in MS-DOS looks ahead in the FAT to used is passed to MS-DOS for each terms of physical disk sectors. This see if the allocation units to be trans- transfer made. It is, of course, com- requires some divisions and subtrac- ferred are consecutive. If so, they are pletely independent of the physical tions involving the physical sector combined into a single multiple- sector size the disk uses. size and results in the breakdown of sector I/O system transfer request, To read a file, an application pro- the transfer into three distinct pieces: which allows the I/O system to op- gram passes to MS-DOS the size of a (1) the position in the file of the first timize the transfer. This is the pri- logical record, the first logical record physical sector and the first byte mary reason why MS-DOS disks do to read, and the number of sequential within that sector to be transferred, not ordinarily use any form of sector logical records to read. Let's follow (2) the number of whole sectors to interleaving: a well-written I/O sys- an example of how MS-DOS uses this transfer after the first (partial) sector, tem will be able to transfer con- information. Assume the application and (3) the number of bytes of the last secutive disk sectors if told to do it in program is using 80-byte records and (partial) sector to be transferred. The a single request. The overhead of is set up to read a file 15 records at a calculations and their results are making the request, however, would time. Let's pick things up on its sec- shown in figure 6a. It is quite com- often be too great to transfer con- ond read, that is, after it has already mon for one or two of these pieces to secutive sectors if it were done on a taken the first 15 records and is about be of length 0, in which case some of sector-by-sector basis. to read the second 15. The request the following steps are not per- Back to the example. MS-DOS will will be for an 80-byte record, the first formed. request that the I/O system read sec- record is number 15, and you want to At this point, there is still no hint as tors 36 and 37 directly into the mem- read 15 records. Now pretend you're to where the data will actually be ory location called for by the applica- MS-DOS and analyze this request. found on the disk. You know that tion. Then, noting that allocation You immediately convert the re- you want the tenth sector of the file units 9 and 10 are consecutive, the quest into byte-level operations. First (sector 9 because you start counting corresponding sectors 58, 59, 60, and multiply the logical record size by the with 0), but you're not yet ready to 61 from unit 9 and sectors 62 and 63 record number, to get the byte posi- check with the FAT to see where it is. from unit 10 will be read by the I/O tion to start reading (80 X 15 = The sector position in the file must be system in a single request. This com- 1200). Then multiply the record size broken into two new numbers: the pletes the transfer of the eight whole by the number of records, to get the allocation unit position in the file and sectors.

244 June 1983 © BYTE Publications Inc A Short History of MS-DOS Known variously as Seattle Com- that Seattle Computer provided for last less than six months. (Unfortunate- puter 86-DOS, IBM Personal Com- Microsoft. Seattle Computer Products ly, it has lasted much longer than that puter DOS, and Zenith Z-DOS, MS- displayed the complete package (8086 as part MS-DOS.) DOS was developed by Seattle Com- running disk BASIC) in New York the In the last few days of 1980, a new puter Products for its 8086-based com- first week of June at the 1979 National version of the DOS was released, now puter system. The MS-DOS history is Computer Conference. (This was the known as 86-DOS version 0.3. Seattle intertwined with the general develop- first-ever public display of an 8086 Computer passed this new version on ment of software for 8086-based com- BASIC and of an 8086 processor card to Microsoft, which had bought non- puters. for the S-100 bus.) exclusive rights to market 86-DOS and In May 1979, Seattle Computer Seattle Computer shipped its first had one customer for it at the time. made the first prototype of its 8086 8086 cards in November 1979, with Also about this time, Digital Research microprocessor card for the S-100 bus. Stand-Alone Disk BASIC as the only released the first copies of CP/M-86. In There were brief discussions with software to run on it. The months April 1981, Seattle Computer Products Digital Research about using one of rolled by, and CP/M-86 was nowhere released 86-DOS version 1.00, which Seattle Computer's prototypes to aid in in sight. Finally, in April 1980, Seat- was very similar to the versions of MS- developing CP/M-86, which was to be tle decided to create its own DOS. This DOS that are widely distributed today. ready "soon." Although Seattle Com- decision resulted just as much from In July 1981, Microsoft bought all puter was considering using CP/M-86 concern about CP/M's shortcomings rights to the DOS from Seattle Com- when it became available (expected no as from the urgent need for a general- puter, and the name MS-DOS was later than the end of 1979), there were purpose operating system. adopted. Shortly afterward, IBM an- only two working prototypes of the The first versions of the operating nounced the Personal Computer, using 8086 processor card, and it was felt system , called QDOS 0.10, were as its operating system what was essen- that both were needed in house. There- shipped in August 1980. QDOS stood tially Seattle Computer's 86-DOS 1.14. fore, there wasn't one free for Digital for Quick and Dirty Operating System Microsoft has been continuously im- Research. because it was thrown together in such proving the DOS, providing version Microsoft had already started a a hurry (two man-months), but it 1.24 to IBM (as IBM's version 1.1) with strong 8086 software-development worked surprisingly well. It had all the MS-DOS version 1.25 as the general program. The firm was ready to try the basic utilities for assembly-language release to all MS-DOS customers in 8086 version of Stand-Alone Disk development except an editor. One March 1982. Now version 2.0, released BASIC, which is a version of its BASIC week later, Seattle Computer had in February 1983, has just been an- interpreter with a built-in operating created an operating system with an nounced with IBM's new XT com- system. During the last two weeks of editor, an absurdity known as puter. May 1979, this BASIC was made com- (editor of lines). A primitive line- pletely functional using the hardware oriented system, it was supposed to

To finish the job, sector number 64 pleted the first such read. This would 32 bytes of the sector will be moved is read into the internal MS-DOS sec- mean that sector 35 (the first one read into place without a disk read. tor buffer. Its first 96 bytes are moved in this example) would already be in For its own internal simplicity, MS- to the application program's area. the sector buffer because its first 48 DOS has only one sector buffer. Be- bytes were needed for the previous tween the 15-record reads, should the The Sector Buffer application request some other trans- This example shows the internal fer that requires use of the buffer, MS-DOS sector buffer being used in a The presence of only then the buffer contents will be very simple way. In reality, MS-DOS one sector buffer in MS- changed, and these optimizations are would normally perform the disk DOS is a design not possible. In this particular case, in read in the example more efficiently which most of the disk transfer does than described here due to its opti- inadequacy that is not need the buffer, there will be very mized buffer handling. By keeping difficult to defend. little difference in speed either way. track of the contents of the buffer, Let's look at a different case where disk accesses are minimized. The this optimization is practically essen- resulting speed improvement can be read. MS-DOS would not reread this tial. dramatic particularly when the re- sector but instead would simply copy Suppose the application wishes to quested transfer size is small (a frac- the remaining 80 bytes into the area write a file sequentially, one 16-byte tion of a sector). designated by the application. record at a time. When the first In the example, I assumed the ap- Likewise, when the application is record is written, MS-DOS simply plication program was sequentially ready to read the third chunk of the copies the 16 bytes into the first part reading 15-record chunks (at 80 bytes file, MS-DOS will find sector 64 of the sector buffer. As each of the per record) and had already com- already in the sector buffer. The last next seven records is written, it too

246 June 19$3 © BYTE Publications Inc Circle 405 on inquiry card.--♦ Circle 164 on inquiry card.

is just copied into the appropriate SOLID, OAK position in the sector buffer. Again with a 128-byte sector of an 8-inch SOFTWARE. single-density format, the sector buf- fer would be full at this point. Upon attempting to write the ninth record, MS-DOS would find it needs to put the record in a different sector from the one currently in the buffer. The current buffer contents are marked "dirty," meaning they must be writ- ten to disk rather than discarded. MS- DOS does this and then moves the ninth 16-byte record into the buffer. Note that MS-DOS did not write the sector buffer automatically after 128 bytes had been written to it. This is because the DOS has no notion of a DISTINCTIVE COMPUTER FURNITURE. sequential file: every disk transfer has FACTORY DIRECT. an explicitly specified record position UNCONDITIONALLY GUARANTEED. and record size . Thus, it does not All the peripherals you can buy won't help and the affordability of factory-direct think of the buffer as "full"-for all it the productivity of your computer system if delivery. knows, the application program you don t have an organized way to utilize Write us, or call our toll-free number to order them. System VII Furniture gives you an a full-color catalog. Send $1.00 plus $1.00 might back up and write the first 16 efficient , comfortable workspace . With the shipping and handling. $2.00 will be credit- bytes over again . So the data is simp- warmth and beauty of hand-rubbed Oak ed toward first purchase. ly kept in the buffer until the file is V/` CALL. 1-800-547-8888 Dept. F closed or until the buffer is needed for P.O. Box 427 e• Lafayette, Oregon 97127 something else. Another optimization was taking place here that may have gone un- noticed. MS-DOS is always aware of lntrodudng SPL If you have a computer the exact size of its files, and the the first multi-mode spooler Get A Second assumption in the previous example for CP/M computers was that this file was being newly written . Had it already existed, MS- If you believed that your computer Computer couldn't do better than a single task DOS would have been forced to pre- system think again. You can convert FOR $139 read each sector into the sector buffer your machine into a dual-task computer before copying any records into it. with SPL, the amazing Spooler program developed by Blat R+D. SPL enables you This is essential in case the program to use hidden capacity available on your does random writes, intending to CP/M computer to print documents and run your ordinary programs, all at once. change only selected portions of the While printing, your regular file. When the file is being extended programs won't stop (as in this case ), the preread is not processing, waiting for the performed. printer to finish. SPL will store the information to be printed in The possible outcome of this ap- internal or external (disk proach to buffer handling is that drives) memory until the printer is when the application program re- ready to receive the data. Result: your programs will run at full speed. quests a write and is told it was suc- As SPL can use up to the full cessfully completed, the data may, in capacity of your disks for temporary fact, not yet be written to the disk. storage, it's much more powerful You could get an equivalent increase The alternative approach is called than hardware spoolers, which are in computing power by spending $1000 limited to 64k memory or less. to $3000, but SPL is only $ 139, including buffer write-through, in which the SPL is an advanced product with disk and manual. data in the sector buffer would be several modes of operation. In addition To order your SPL program call us written to disk each time the applica- to intercepting the output to the printer, today specifying what disk format you SPL can print your existing text files, or require. You can charge it to your VISA tion requested a write. This would those that your programs will create from or Master Card if you prefer. mean, in the example, eight rewrites now on . SPL will even take care of tab Blat Research +Development Corp. of the same sector before moving on expansion . As an added bonus, SPL 8016 188th SW, Edmonds WA 98020 to the next, requiring a minimum of needs no installation on most CP/M 2.x Call toll -free 1 -800-LOBO-BAY computers. In WA call [206) 771-1408 1.2 seconds to write just 128 bytes! As

250 June 1983 © BYTE Publications Inc Circle 44 on inquiry card. Circle 440 on Inquiry card.

the logical record size gets smaller, justed to the user's needs: for exam- the time required to write becomes ple, to accommodate more buffers to P&T CP/M®2 is greater. prevent thrashing (this is the ideal GROWING The presence of only one buffer solution to the buffer thrashing prob- does bring about the definite possibil- lem previously discussed) and fewer ity of buffer "thrashing." Take the ex- buffers to make more system memory ample of an application such as a available. compiler that will alternately read a The new MS-DOS does not keep small amount from one file and write the file allocation tables in memory at a little bit to another. If both the all times . Instead, the tables share the reads and writes consist of a single use of the sector buffers along with 16-byte record, then the following se- partial-sector data transfers. This quence will be performed for each means that at any one time, all, part, pair of records: or none of a FAT may be in memory. The buffer-handling algorithms will •read input file, get record from buf- presumably keep often-used sectors fer in memory, and this applies to in- •read output file, put record into dividual sectors of the FAT as well. buffer This change in the DOS goes com- •write output file pletely against my original design principles. Memory is getting cheaper For each record pair, three disk trans- all the time, so dedicating a few thou- fers are required. The result would be sand bytes to the FATS should be unbearably slow. The presence of completely painless. Now we're back only one sector buffer in MS-DOS is to doing disk reads just to find out a design inadequacy that is difficult to where the data is. In the case of a ran- defend (but it does help keep the DOS dom access to a large fragmented file small). The practical solution is for (for example, when accessing a data- applications that must access more base that fills half of a small Winches- than one file at a time to provide their ter disk), it is possible that several own internal buffering. By requesting sectors of the FAT would need to be transfers that are at least half as big as visited, in random order, to find the the sector size, thrashing can be sub- needed allocation unit. stantially reduced. While MS-DOS retains the original fixed-size main directory, it now can MS-DOS 2.0 have files as subdirectories. This Microsoft has now made available hierarchical (tree-structured) direc- MS-DOS version 2.0 to all OEM (ori- tory system may be extended to any ginal equipment manufacturer) cus- depth. This approach is nearly essen- tomers of previous versions. The 10 tial for users to keep track of all the months put into version 2.0 by the files that might be on a hard disk. MS-DOS team probably exceeds the MS-DOS version 2.0 is, on the total effort behind the previous 1.25 whole, a substantial upgrade of the release, including the original devel- previous releases . The three preced- opment at Seattle Computer Prod- ing paragraphs are intended only to Start with a Model II floppy system and ucts. While the changes have been point out the way the 2.0 file struc- grow into a hard disk. Since all P&T ture differs from the file structure I've CP/M 2 systems are fully compatible, substantial, the basic structure is still you will have no conversion worries. recognizable. I have been discussing discussed, not to give you a complete Special note : P&T hard disk systems n allow you the user to configure logical the DOS at such a low level that most product description. drive assignments to your specifications. Write for more details. of what I've talked about applies Prepaid VISA, M/C, or COD orders accepted. directly to version 2.0 as well. Here All prices FOB Goleta and subject to change. are the three main differences, along About the Author CP/M is a registered trademark of Digital Tim Paterson worked for Seattle Computer Research . TRS-80 is a trademark of Tandy Corp. with my personal comment as Products on the design of its 8086 computer original author of the DOS. I was not system and the operating system now called PICKLES PICKLt involved in the MS-DOS 2.0 project. MS-DOS. He then worked for Microsoft for & TROUT MS-DOS 2.0 allows multiple-sec- about a year. Since returning to Seattle Com- tor buffers. The number is deter- puter Products as director of engineering, he P.O. BOX 1206 been prinarily involved with new hard- GOLETA, CA 93116 mined by a configuration file when has (805) 685-4641 ^ ware development. R001 the DOS is loaded. It can be easily ad-

252 June 1963 © BYTE Publications Inc