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

Tim Paterlon 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 (110) han-" application programs, so that those these developers felt that CPIM-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 110, such as designed an 8086 microprocessor card design of MS-DOS were speed and ef­ sequential or random access of named ' for the S-l00 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, Seatile 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 110 ) 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 CPIM-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 CP1M were and efficiency. disk by the hidden file 10.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 CP1M-50 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 soltware-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 CP1M and a monitorIde­ physical disk sectors into m'emory, ':: their CPIM-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' the standard interface between the -TOP OF MEMORY eludes 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. f------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 $79: First, it sets up all basic error trapping MS-DOS with the extensions .COM, .EXE, or d Ma~ for either hard-disk errors or the Con­ .BAT can be executed by COM­ I,. Whe trol-C abort command. MSDOS.SYS 110 SYSTEM MAND simply by typing the first .Murray provides no default error handling 00400 part of the file name (without exten­ Plotter' but simply traps through a vector INTERRUPT VECTORS sion). You can normally enter 00000 form e\ that must have been previously set. parameters for these programs on the fession Setting the trap vector and providing command line, as with any of the flsure 1: Map of memory areas as as- And, a suitable error response is up to signed by MS-DOS. built-in commands. Overall, the ef­ beeasl COMMAND (or whatever program fect is to give you a command set that patible might be used to replace it). can be extended almost without limit IBNr, ( The second special feature is that sient sections. The resident, which just by adding the command as a pro­ most a COMMAND splits itself into two sits just above MS-DOS in low gram file on the disk. .sonal c pieces, called the resident and tran- memory, is the essential code and in- The three different extensions He a/s( to carr MODEMS; CRTS; PRINTERS; SWITCHES; MICRO COMPUTERS I CABLES with sc PRODUCT DESCRIPTION Lin YOUR COST neatly UDS l03LP,300 bpl,Modem 145 130 UDS 202LP,l200 bPI, HII' Duplex Modem 195 160 Well UDS 212LP,.1200 bPI, Full Duplex (2J2A) Modem 445 CAll U.S. Robotill$Auto Dial 212A, 300/1200 full Duplex Modem" 599 475 a Whi2 lneomm Auto 0181 212A, 300/1200 Full Duplu Modlm "19 460 c..mltel: Auto Dial 21ZA, 30011200 Full DuplaK Moda'" 595 495 MurraJ Microt.nd A"", Dial 21ZA, 30011200 Full Dupin Moda'" 595 495 · RiKon Inull"'n1 Mod"". 300/1200 110 N"",t.rl 495 CALL · all of II · RiKon PC 21ZA (IBM PC Moda'" Ca,d) 300/1200 495 CALL · lno;:omm M"lti Dial300f1200 no NumbolrJ 795 550 things U.S. RobotiCi P..word JOOf12DO lAu1<;l DiIIU Mode'" 495 CALL U.S;. RobotiCi Cou,la., Dlt>orna. 3OOf1200 Moclam 516 CALL a nifty U.S. Robo'\iCl S·1OO. 300f1210 A,,1<;I Dill MocM'" 495 CALL

Viro-I 50 CRT 695 550 F'altdom 100 CRT, .../20 F, kayl &. Editin1l 595 550 Incomm Ramotl SUilon I, wflnt.gratlld 300/1200 Moda", 1295 ,.. EpsDn MX80/Gnfl'IX" 650 Eplon MX80 FT!G,lI1lrn + 700 4"'" Epson MX100/G.atvall" 900 700 EI»011 FX.aO 750 956 Saor Mietonia Gaminl 10 399 360 Sao, Micron;CI Gamin; 15 ,.9 548 AJ Lana' Quality Prinlllf, 30 CPS (!liSR) 1450 1250 Incomm AB SWilch,8 Pin 120 94 lncornm AB SWiICh, 25 Pill 159 lncornm ABC Switch, 25 l';n 198 13'" .- IDS Bra.kout BDK (BI"e Boll) 159 140 .- · lnco",,,, B,.ekout Box IBobl 150 120 ·.- l;pson, HX-4!G-AA 795 CALL Epson QX·10/256K 2995 CALL Zenith Z·1OO 4000 CALL

T .7MM, 7 Pin, 4 Wire, Talaphona Cable (Modular l'ill(ll) 10 7 S.g75, Modul... Double Adapter 7 , EIA 9/5, RS 232, 9 Pin Cable, 5 FT MM/FFIMF 16 12 ElA 2515, RS 232, 25 l';n Cable, 25 FT MM/FFIMF 22 14 .- ElA 6015, Cent.onics PI.allel Cable, 5 FT (36 Pinl 30 21 MC 0060/10, Cantronici 10 Ft. MM Cable, 36 Pin (10 Fl) 36 7010/5, IBM PC Printer Cable w/36 Pin 40 "22 8010/5 Appl. II Printer Cabl. w/36 Pin 22 9010/5, Atari P,in1er C.bla w/36 Pin 30 21" U.S. Robotil;:l Talpac 79 CALL Rixon PC Co", 1 (IBM PC Software) 69 CALL ORDER TOLL FREE· 1-800-323-2666 1585 Kenmore Ave., Buffalo, N.Y. 14217 TOUMATAN & ASBOCIATES W.Welcome' eVa, M••rcherge • eChacki Cheques or money orders. No C.O.D.s. Add shipping 115 N. Wolf Rd. eCompeny P.O. Whealil'Jll, IL 60090 312-459-8866 eC,O,D,IAdd.S'.60/Shipmant) In C8rwda; 1736 Avenue Rd., Toronto, Ont M5M 3Y7 Canada: Prien may vary

Circle 452 on Inquiry. card. allowed on program files represent SECTOR 1 different internal file formats. SECTOR 8 __--r-~-~------TRACK 0 •.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 SECTOR 7 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. g • .BAT (batch) files are text files with commands to be executed in sequence by COMMAND.

FOe Structure Disks are always divided up into SECTOR 6 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. SECTOR 5 SECTOR 4 A somewhat more abstract view of disks .was talcen in developing MS­ DOS. MS-DOS views the disk, not in figure Z: 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. o is the first sector of the outermost ing a standard mapping, however, is The FAT (file allocation tablel. 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.

Logical BYTE o I I 2 I , I •I 5 i , I 7 Sector LOCATION 1 I Numbers Uae o NAME a Reserved for bootstrap loader ATTRI- EXTENSION BUTES ZEROS 1-6 FAT 1} file allocation • 7-12 FAT 2 t.bles (FATs) 13-29 Directory " ZEROS TIME 30-2001 D.t. POINTER 24 DATE SIZE IN BYTES TO FAT Table 1: Map of disk areas on an 8-inch singk-sided, singk-density flop­ py disk. figure 3: Arrangement of bytes in disk directory entry. 64, or 128 logical sectors, but the Iy. It is, however, present in more number is fixed for a given disk for­ primitive systems, such as the UCSD Logical Allocation Unit Sector Number mat. Allocation units are numbered p-System. Pc Numbers sequentially. The numbering starts It would certainly seem desirable to For Api with 2; the first two numbers, 0 and minimize internal fragmentation by 30-33 2 (flrsl allocation unil) 1, are reserved. Table 2 shows thi~ 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. ample. However, for any given disk 42-45 5 • • 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 Table 2: Allocation unit numbering for is only 1 byte long, an entire unit will would be quite large if there were too \II the 8-inch single-density format . To be dedicated to it. many small allocation units. For When weint compute the logical sector number of For example, the standard format every unit, 1.5 bytes are required in innovations. the first sector in an allocation unit, for 8-inch single-density disks uses the FAT; there are normally two o Extremel~ you use the following equation: sector statements i four 128-byte sectors per allocation FATs on the disk, each of which is o It's based number - 4 X allocation unit number unit. When a new file is first created, rounded up to a whole number of sec­ ascompoun + 22. o You candi no space is allocated, but an entry is tors. DYougeta. made in the directory. Then when the Now take a standard 8-inch single­ completeCC first byte is written to the file, one density floppy disk that has 2002 sec­ allocation unit (four sectors) is as­ tors of 128 bytes. To minimize inter­ Alsoavallat signed to the file from the available nal fragmentation, choose the small­ 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 ALLOCATION UNIT 4 dated to the exact byte, but no more will require 3000 bytes (24 sectors) space is allocated until those first four per FAT, or 48 sectors for two FATs. sectors are completely full. Then to If the average file size is 16K bytes FILE DATA write 1 byte more than those four sec­ (128 sectors), the disk will be full Fe ALLOCATION tors worth, another four-5ector allo­ when there are 16 files on it. Waste w UNIT 5 cation unit is taken from free space due to internal fragmentation would o Basedonl o IF .. THE~ and assigned to the file. be o Avery niCE PARTIALLY When writing stops, the last alloca­ 0150 Englisl UNUSED OYougetac tion unit will be filled by some ran­ 16 files x 64 bytes per file = SECTOR-----.:: 47 ALLOCATION programs. At f----i.. UNIT 6 dom amount of data (figure 4). The 1024 bytes (8 sectors) COMPLETELY UNUSED unused space in the last allocation ... --_. SECTORS { 49 unit is wasted and can never be used Far more space is occupied by the I Tomakeours I What's more, as long as the file remains unchanged FATs on the disk than is wasted by completely sa­ on the disk. This wasted space is internal fragmentation I I disklJttli unop. I This is a limite Fiswe 4: Assignment of logical sectors to called internal fragmentation, To provide maximum usable data Sh.lpplng/hal allocation units. Note that, -in the file because it is part of the space space on the disk, both internal frag­ packll'illl. QVE shown, more than two sectors are wasted allocated to the file but is an unusable mentation and FAT size must be con- . age. Checks n because they are in an unused part of the fragment. On the average, the last sidered because both consume data Trademarks: ( SY'!Items, Inc.: last allocation unit. allocation unit (regardless of size) will area. The standard MS-DOS format Xeroll820, Xli be half filled and, .therefore, half for 8-inch single-density disks strikes International E wasted. Because each file wastes an a balance by using four sectors per MAIL TO[ 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 I entry also has a pointer to a place in one-half the allocation unit size. favors smaller FATs and larger allo­ I the FAT that tells where to find the The phenomenon called external cation units: the entire FAT is kept in I data in the file. Figure 3 shows the fragmentation occurs when a piece of main memory at all times. I layout of a directory entry. data space is unallocated yet remains The file allocation table contains all I The rest of the disk is the data area. unused because it is too small. This information regarding which alloca­ I Il is divided into many small, equal­ cannot happen in the MS-DOS file tion units are part of which file. Thus : EL sized areas called aIlocation units. system because MS-DOS does not re­ by keeping it in main memory, any I Each unit may have 1, 2, 4, 8, 16, 32, quire files to be allocated contiguous- file can be accessed either sequentially L_ (Sa) FILE or randomly without going to disk ALLOCATION are also allocation unit numbers. TABLE except for the data access itself. Think of the FAT as a map, or trans­ DIRECTORY RESERVED (' 1 Schemes used in other operating ­ lation table, that takes an allocation ;:.ENc.Tc.Rc.V____ EN TR IES 1 -1 tems (including CP1M and Unix) may unit number as input and returns a, 7 ; , require one or more disk reads simply different allocation unit number as , q I -1 to find out where the data is, par­ output. The input can be any unit ====---~ 5 , L-L-'----t:_ ticularly with a random access. In an that is part of a file; the number , 3 • f-'-' 7 8 application such as a database in­ returned is the next sequential unit of 8 -1 quiry, where frequent random access that file. , 10 • is the rule, this can easily make a 2 to Let's look at the example in figure' 10 -1 Ij 11 22 1 difference in performance. Sa. 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­ (sb) the number of the first unit in the file. tion unit of the file, look at entry 5 in,'

F FFF f F 07 90 00 FF 6 F If, as in the previous example, an the file allocation table. The 6 there; 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

6 F 01 ing at the directory you know where allocation unit number 6; and second, 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 dR-ta via the directory the FAT. This process is repeated as you and the file allocation table. Figure 5. 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 opemting system to the sequential parts of After number 6 comes number 3. then a file. The data stored in the sample file­ with any array, a given element is number 9, then number 10. In each allocation table is disp/Qyed in hexadeci­ found with a numeric index. The case, the allocation unit number mal in figure 5b. numbers used as indexes into the FAT returned by the FAT tells you both"

Save valuable time! 5 to 50 times faster performance than floppy disks and Winchester drives PION'S INTERSTELLAR DRIVE is designed for use with a family ofinterfaces and software packages. Currently avail~ able are interfaces for IBM. SIOO. TRS80. Apple, SS50, and most 280 uP, and software for most popularoperatingsystems. Additional interfaces are continually being developed for the • most popular computers. SAVE MONEYI Basic Price for 256KS unit [Includes Interface and software) Increase your $ 1095 plus tax (where applicable) and shipping l~ ~ computer's productivity • Visa and Master Card accepted. ~ ~ The INTERSTELLAR DRIVE is a high performance data storage subsystem with independent power PION,INC. Tel.1617)923-8oo9 supply, battery backup, and error detection. It has J0 1RWalnut St.,Watertown, MA 02172 256KB to 1Megabyte ofsolid state memoryintegrated TRS80 trademark of Tandy Corp, Apple trademark of Apple Computers to perform with your operating system. Interstellar Drive trademark of PION. Inc.

238 June 1913 @ BYTE Publkationl Inc Circle 304 on Inquiry card., where the data is (Le., in which unit) CARTRIDGE RI••ONS FOA and where to look in the FAT for the next allocation unit number. EPSON If you followed the example all the MX-80 MX-10 way through, you should have no­ ticed that entry 10 in the FAT con­ s11.".. tains a -1. This, as you might have "129."002 guessed, is the end-of-file mark. Allo­ cation unit number 10 is last in the INNOVATIVE Supe LABEL CONCEPTS file, so its entry contains this special the growi flag. (Another special value in the SPECIAL FLlP'N'FILE compiler DISC STORAGE BOX FAT is 0, which marks a free alloca­ PC DOS. HOLDS UP TO 60 DISKETTES tion unit.) 99 FORTRA $2. ,. 51/." 8" Now you know that this file oc­ (SKMINI example, cupies five allocation units, numbers 'ACROSS l',. 15116 CO"TINUOUS l"'HLS used to tI 5, 6, 3, 9, and 10 in order. The file p. 44, Oc could be extended by finding Any free COMPLETE LINE OF OTHER RIBBONS AVAILABLE, PLEASE CALL listed will unit, say 27, putting its number in en­ programs try 10 (where the -1 is now), and quality of marking it with the -1for end of file. That is, entry 10 in the FAT will con­ IBM CheCk:Mate" tain 27, and entry 27will contain -1. SUIlE ~. Iii] . 51 DIAUTO DR P.O BOX 103 ... This demonstrates how you can ex­ In its RANDOLPH, MA 02368 - tend any file at will and. that you can offers thE TOLL FREE 800-343-7706 IN MASS 617-963-7694 use any free space on the disk when 1. Full.A WE ACCEPT MASTER CARD & VISA needed, without regard to its physical MASS RESIDENTS ADD 5% SALES TAX impor location. PHONES OPEN 9AM-7PM EASTERN TIME 2. Slane If you ever want to look at a real varyir FAT, there's one more thing you1l =---==-=------==------4 need to know. Each FAT entry is 12 3. Free I bits (1.5 bytes) long. These entries are outpu packed together, so two of them fit in "4. Com~ 3 bytes. From a programming view­ 5. Speci point, you would look up an entry in dynar the FAT this way: Multiply the entry acce~ number by 1'(" truncating it to an in­ teger if necessary. Fetch the 16-bit 6. Debu word at that location in the FAT. If runlir the original entry number was odd 7. Full II (so that truncation was necessary in the first step), shift the word right 4 8. Full 8 bits; the lowest 12 bits of the word is {$50.l the contents of the FAT entry. Read­ rogr, ing a FAT from a hexadecimal dump upel isn't nearly as simpleI Figure 5b E;!ansyol shows the hexadecimal version of the 'eywill r sample FAT I've been using. $OOS. ~~ File System In Action To put all this in perspective, you need to look at howMS-DOS handles " a file-transfer request from an appli- .' cation program. With MS-DOS, ap­ plication programs treat files as if they were divided into logical rec­ ords. The size of the logical record is entirely dependent on the application' and may range from 1 byte to 65.535 bytes. It is not a pennanent feature of

Circle 43 on Inquiry care1. (6a) the sector within the allocation unit, byte position 1200 For this example with sing1e. read the second 15. The request the following steps are not per­ Back to the example. MS-DOS will " thane will be for an SO-byte record, the first formed. request that the lIO system read sec- 'I i IS a pI 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- 1,1 asfou read 15 records. Now pretend· you're to where the data will actually be ory location called for by the applica- ~1 1 MS·OOS and analyze this request. found on the disk. You know that tion. Then, noting that allocation !l.er. A You immediately convert the re­ you want the tenth sector of the file units 9 and 10 are consecutive, the TP-I( quest into byte-level operations. First (sector 9 because you start counting corresponding sectors 56,59,60, and paper 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 torfff record number, to get the byte posi­ check with the FAT to see where it is. from unit 10 will be read by the lIO 1 tion to start reading (60 X 15 = The sector position in the file must be system in a single request. This com­ patibI 1200). Then multiply the record size broken into two new numbers: the pletes the transfer of the eight whole and a' by the number of records, to get the allocation unit position in the file and sectors. leI da1 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 3S (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 1S-record reads, should the The Sector Buffer application request some other trans­ "'n The Beglnnl"! CorpolCltlon 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 VX584 .\ '512 COLOR very simple way. In reality, MS-DOS one sector buffer In MS­ changed, and these optimizations are ,• COLOR LOOI would normally perform the disk DOS Is a design not possible. In this particular case, in palette read in the example more efficiently which most of the disk transfer does • ON-BOARD : than described here due to its opti­ Inadequacy that Is not need the buffer, there will be very '3D GRAPHIC ling rotation,s mized buffer handling. By keeping difficult to defend. little difference in speed either way. . clipping, vlewr track of the contents of the buffer, Let's look at a different case where • HARDWARE disk accesses are minimized. The this optimization is practically essen­ • ON-BOARD I resulting speed improvement can be read. MS-DOS would not reread this tial. AGERSET 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 1S-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

Circle 405 on Inquiry card,-+ is just copied into the appropria position in the sector buffer. Ago' with a 128-byte sector of an 8-in single-density format, the sector buf fer would be full at this point. Upo 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-l DOS does this and then moves the 7 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 sequential file: every disk transfer has an explicitly specified record position: I. and record size. Thus, it does not' " think of the buffer as "full"-for all it" knows, the application program;' ',~' might back up and write the first 16' bytes over again. So the data is simp-' Iy kept in the buffer until the file is closed or until the buffer is needed for ," '1 6' something else. ( Another optimization was taking " place here that may have gone un- ,1. I noticed. MS-DOS is always aware of :.! Introdudng SPL If you have a computer the exact size of its files, and the" r the fbst multi-mode spooler Get A Second assumption in the previous example • I 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 documer'lts and change only selected portions of the run your ordinary programs, all at once. 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 untit 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­ cessfully completed, the data may, in As SPL can use up to the full f:.;;==;;::====:==~~;:;;;~ 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 r limited to 64k memory or less. to $3000, but SPL is only $ 139, including buffer write-through, in which the i DI 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 ot tab Bllt Relelrch+Developmen1 Corp. of the same sector before moving on expansion, As an added bonus, SPL 8018188th SW, Edmond. WA 98020 to the next, requiring a minimum of .i needs no installation on most CP/M 2.)( Cell toll·'r•• 1-800-LOBO-BAY computers. In WA call [208) n1-1408 1.2 seconds to write just 128 bytesl As

elrel 2SO tune 1983 e BYTE PubIkaUom lilt: Circle 44 on inquiry card. the logical record size gets smaller, justed to the user's needs: for ex the time required to write becomes pIe, to accommodate more buffers t greater. prevent thrashing (this is the ide The presence of only one buffer solution to the buffer thrashing pro' ·., does bring about the definite possibil­ lem previously discussed) and fewe .pt" ity of buffer "thrashing." Take the ex­ buffers to make more system memo ·, ample of an application such as a available. VI compiler that will alternately read a The new MS-DOS does not k ." small amount from one file and write the file allocation tables in memory at .H •• a little bit to another. If both the all times. Instead, the tables share the • l 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 anyone time, all, part, pair of records: or none of a FAT may be in memory. I' The buffer-handling algorithms will eread input file, get record from buf­ presumably keep often-used sectors e fer in memory, and this applies to in­ eread output file, put record into dividual sectors of the FAT as well. buffer This change in the DOS goes com­ ewrite 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 M) 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 FX small). The practical solution is for (for example, when accessing a data­ M) applications that must access more base that fills half of a small Winches­ NE 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 ,I. 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 'lO • MIl 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 ME 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 c 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 co total effort behind the previous 1.25 whole, a substantial upgrade of the VIC release, including the original devel­ previous releases. The three preced­ VIC opment at Seattle Computer Prod­ ing paragraphs are intended only to VIC VIC Start with a'Modelli 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 VIC CP/M 2 systems are fully compatfble, substantial, the basic structure is still ture differs from the file structure I've A~ you will have no conversion worries. recognizable. I have been discussing discussed, not to give you a complete Specie. note: P5T hard disk systems allow you the user to configure logical the DOS at such a low level that most product description.• drive assignments toyour specifications. Write for more details. of what I've talked about applies Prepaid VISA, I'd/C, orCOD orders accepted directly to version 2.0 as well. Here All prices FOB Goleta and subject lochange, CP/M is a registered trademark of Digital are the three main differences, along About the Author Research. TR&t!O Is atrademark otTandyCorp. with my personal comment as Tim Paterson worked for SeaHle Computer Products on the design of its 8086 computer original author of the DOS. I was not system and the operating sJlstem now called • involved in the MS-DOS 2.0 project. MS-DOS. He then worked for Microsoft for •51 MS-DOS 2.0 allows multiple-sec­ about ~ year. Since returning to Seattle Com­ U tor buffers. The number is deter­ puter Products as director of engineering, he • E mined by a configuration file when has been prinari!y involved with new hard· ,i , ware development.. ~ the DOS is loaded. It can be easily ad------'------" •(

Clrclt 251 June 1913 Cl BYTE Puhlkatknu Inc