MACH2 - File Space Allocation Utility Copyright 1983 by Karl A. Hessinger - MicroConsultants, All rights reserved Published by MISOSYS, Alexandria, Virginia TABLE OF CONTENTS General Information 2 Distribution Diskette 2 Invoking MAPPER 3 Invoking ALLOC 5 Invoking CALC 7 Invoking HANDY 8 Space Optimization Procedures 10 Glossary 14 Note: LDOS is a trademark of Logical Systems Incorporated TRSDOS is a trademark of Tandy Corp. GENERAL INFORMATION The LDOS file system allocates space for your files in one of two ways. It either assigns space randomly [as used in LDOS 5.0.x, 5.1.0, 5.1.1, 5.1.2, 5.1.3, 6.0] or assigns space automatically starting from cylinder one [5.1.4, 6.1]. Since the access of disk files requires a disk drive to step from track to track [which is one of the slowest operations of a disk drive excluding turn-on delay], the most efficient placement of files is one that minimizes this stepping operation. Either method may prove inefficient in particular cases since the optimum arrangement is dependent on the specific function and access sequence of all files on the disk. Once and for all, MISOSYS now puts you in the driver seat when it comes to DOS allocation of disk space. Whether you are a commercial programmer wanting to construct "optimized" master diskettes for distribution purposes, whether you are a sophisticated hacker wanting to squeeze every bit of performance out of your system, or whether you just want to create the most contiguous files where you want them, MACH2 is for you. MACH2 is a collection of four utilities that were designed to work together with such ease, that you will be amazed at how easy direct control of space allocation can be. The MACH2 utilities are friendly. The MACH2 utilities are flexible. Finally, the MACH2 utilities are powerful. You are not limited to floppies, MACH2 works just as well with hard drive systems. We know that you have been asking for better control over space allocation for a long time. We know that you have needed MACH2 for a long time. We know that you do not want more stringent DOS control over file placement. Now you can take control! MISOSYS delivers with MACH2! DISTRIBUTION DISKETTE This documentation covers the operation of both the Model I/III LDOS 5.1 version (MACH2) and the LDOS or TRSDOS 6.x compatible version (PRO-MACH2). The MACH2 package is provided on a 35-track single density data diskette for LDOS Version 5.1. The PRO-MACH2 package is provided on a 40-track single density data diskette for LDOS/TRSDOS Version 6. MAPPER The operating system's directory command (DIR) will let you know what files you have on a disk, but MAPPER will show you where the files are positioned on that disk. It is invoked via the syntax: MAPPER :d (BLANK,PRINT) :d Specifies which drive to map. BLANK Used to generate an allocation worksheet. PRINT Sends output to the printer device. Abbreviations: B=BLANK, P=PRINT The MAPPER provides a diskette map by granule by file. You can use the MAPPER just to get a look at what files occupy each granule of disk space. This information is great for other uses [such as reconstruction of damaged cylinders]. Use the MAPPER with the BLANK parameter option on a freshly formatted disk [or other such disk with available free space] to obtain a worksheet for manually preparing your optimum arrangement of files. If you do not enter a drive number on the command line, MAPPER will prompt you to enter the drive number via the prompt: Drive ? . The BLANK parameter will cause the free granules on the disk to be displayed as a bracketed blank field,"[ ]" (without the quotes) instead of the normal field entry of "** Empty **". This can be used to generate a worksheet for use in creating an optimized disk by ALLOC. While the map is being displayed on the video screen, the following keys will allow you to scroll through the map: Key Code Key Function Display previous screen page Display next screen page or Exit to DOS The PRINT parameter option will cause the disk map to be sent to the printer instead of the video display. MAPPER produces a screen or printer listing similar to the following illustration [some lines have been deleted to abbreviate the listing]: Diskname : TESTDISK Free Space : 108K Sides : 1 Density : Double Cylinders : 40 ------------------------------------------------------- 0 BOOT/SYS M80/CMD M80/CMD 1 M80/CMD M80/CMD M80/CMD 2 M80/CMD M80/CMD TEST/CMD 3 TEST/CMD TEST/CMD TEST/CMD 19 ** Empty ** ** Empty ** ** Empty ** 20 DIR/SYS DIR/SYS DIR/SYS 24 ** Empty ** ** Empty ** ** Empty ** 25 ** Locked ** ** Locked ** ** Locked ** 26 ** Empty ** ** Empty ** ** Empty ** 27 M80PACK/CMD M80PACK/CMD M80PACK/CMD 28 M80PACK/CMD M80PACK/CMD M80PACK/CMD 37 ** Empty ** ** Empty ** ** Empty ** 38 M80/CMD M80/CMD M80/CMD The "file specification field" will contain the string "** error **" if the associated granule is allocated without a file referencing the granule. In addition, if two or more files are assigned to the same granule, that error will be indicated by appending the string "<---" to the file specification. If you use the BLANK parameter option on a freshly formatted disk with no additional files present, the worksheet generated will look like this [some lines have been deleted to abbreviate the listing]: Diskname : TESTDISK Free Space 174K Sides : 1 Density : Double Cylinders : 40 ------------------------------------------------------- 0 BOOT/SYS [ ] [ ] 1 [ ] [ ] [ ] 2 [ ] [ ] [ ] 3 [ ] [ ] [ ] 4 [ ] [ ] [ ] 5 [ ] [ ] [ ] - - - - - - - - - - - 20 DIR/SYS DIR/SYS DIR/SYS 21 [ ] [ ] [ ] 22 [ ] [ ] [ ] 23 [ ] [ ] [ ] - - - - - - - - - - - 37 [ ] [ ] [ ] 38 [ ] [ ] [ ] 39 [ ] [ ] [ ] ALLOC Pick your media and use your MAPPER-generated worksheet to develop your customized layout of files - or plunge right in to ALLOC since it gives you a dynamic free-space map on-line! ALLOC will allow you to place a file at any location on a disk that you choose. It is invoked simply by entering: ALLOC There are no parameters. The allocation tool, ALLOC, lets you tell the DOS where you want a file placed in up to four directory extents. ALLOC's screen display conveniently presents the controls. All you need do to start the process is specify the file specification. ALLOC even provides an option to specify the file as being "created", thus inhibiting the DOS from deallocating file space. You will be prompted for the name of the file you wish to allocate via the prompt: Filename ? .............. The file specification must include a drive number. Once you identify the file specification, ALLOC gives you a three-line scrolling free-space map so that you can see what granules have already been allocated on the disk in question. The free space map will be displayed to help you plan where the file or files can be located. Look at the useful ALLOC screen display as it prompts for the granule count during a file allocation procedure: ALLOC - LDOS File Space Allocator 6- 11 xx. ... ... ... xxx x.. 12- 17 ... ... ... ... ... ... 18- 23 ... ... xxx ... ... ... Allocating file : TEST/DAT:3 Starting Starting Granule Extent Cylinder Granule Count ====== ======== ======== ======= 1 12 0 .. The three-line free space map may be scrolled in-place by using the or keys as an entry to any "extent" prompt. For each of the four possible extents, you will be prompted for the starting cylinder, the starting granule, and the granule count. Each prompt is identified to you via the position of the cursor. Cylinders and granules are both numbered starting from zero. Thus for example, a three granule per cylinder diskette (5-1/4" double density) has granules numbered 0, 1, and 2. A 40-cylinder diskette has cylinders numbered from 0 through 39. Depressing or to the starting cylinder prompt will instruct ALLOC that you have entered all of the extents. Depressing from either of the two remaining prompts will cause ALLOC to restart the entry of that particular extent. When information for all of the extents has been entered, you will be provided an opportunity to commence the physical allocation or retreat via the prompt: OK to allocate/create this file (Y/N/C) ? The response to this query also establishes whether or not the file's CREATE bit will be set. If you depress , ALLOC will abort the physical allocation thereby providing you with an "escape" mechanism in case of an entry error. If the allocation is aborted, the filename will be removed from the target disk's directory. Depress , and ALLOC will physically allocate the file. If you specify , the file will be allocated and the "CREATE" bit will be set in the file's directory entry. The "create" bit is used by the DOS to ensure that the space will not be deallocated. Its primary utility is for the pre-allocation of space for random access files similar to the DOS CREATE library command; however, ALLOC obtains this space using the least number of extents based on your own analysis [if you want this selection performed automatically, use HANDY]. Thus, ALLOC's procedure generates a file that is optimum for access speed, ALLOC can allocate space for a file that already exists in the directory; however, ALLOC is incapable of allocating space to an existing file which has a non-zero file length [i.e. you can ALLOC space to an existing null length file but not one that already has an allocation of space]. CALC The CALC utility can process a disk's directory to let you know exactly how many granules each file would take up on most media formats supported by the DOS. This tool is great for taking a disk full of programs that are on one media type and ascertaining the granule requirements for a different media type. CALC is invoked via the syntax: CALC :d (PRINT) :d Specifies which drive to calculate. PRINT Sends output to the printer device. Abbreviations: P=PRINT If a drive number is not entered on the command line, you will be prompted to enter the drive number via the prompt: Drive ? . CALC will display a listing of all files on the disk along with the number of granules that would be required for that file on various media types. The listing will be normally directed to the video screen but can be redirected to the printer device via the parameter, PRINT. As easy as CALC :1 (P), you can obtain a listing similar to the following printout: 5" 5" 8" 8" ==== Hard Disk ==== Filename single double single double 4 SPG 16 SPG 32 SPG ============ ====== ====== ====== ====== ====== ====== ====== BOOT/SYS 1 1 1 1 2 1 1 DIR/SYS 4 3 3 2 5 2 1 M80/CMD 15 13 10 8 19 5 3 M80PACK/CMD 15 12 9 8 18 5 3 TEST/CIM 5 4 3 3 6 2 1 TEST/CMD 15 12 9 8 18 5 3 TEST/DAT 0 0 0 0 0 0 0 The first two columns relate to 5-1/4 inch single and double density media indicating five and six Sectors Per Granule (SPG) respectively. The third and fourth columns reference the granule requirements on eight-inch single and double density media indicating eight and ten SPG respectively. The final three columns are provided for use with hard disk allocation schemes using four, sixteen, or thirty-two SPG respectively. HANDY Want to just get a large block of contiguous space for that data base? HANDY is just handy for those non-critical allocation jobs. HANDY will easily allocate the most contiguous extent of space in up to four extents - the number of extents is controlled by you! HANDY determines where the file will fit on the disk according to your extent specification. It is easily invoked via the command specification: HANDY filespec (SIZE=dd,CREATE) filespec is the name of the file that you want to allocate space for. The entry is optional. If omitted, you will be prompted for the name of the file(s). SIZE=dd is the amount of space (in K) that you want to allocate for the file identified. CREATE is specified if you want the directory entry for "filespec" of "SIZE=dd" to have its "CREATE" bit set (see text). Abbreviations: S=SIZE,C=CREATE HANDY operates in two modes. To streamline the allocation of a single file with HANDY, you can enter the file specification and the SIZE parameter directly on the command line. The "CREATE" parameter is used to specify the nature of such a file. If the full command-line entry of information is performed, HANDY will automatically allocate the file space and exit without pausing for any prompts. Alternatively, if the file specification is omitted, HANDY will not accept any parameters from the command line. This method of usage results in going through the menu prompts that will be presented. After the program is loaded, if you have not entered the file specification on the command line, you will be prompted with: Filename ? .............. Be sure that the file specification has a drive number. File space is requested in units of "K" (1024 characters). After the filespec has been entered, you will be prompted to enter the total space to be allocated for the file. This query is: Size of file (in K) ? ... HANDY has the ability to restrict the automatic allocation from using specified cylinders. We will use the term "lock". This does not mean that HANDY will permanently restrict such allocation - it will invoke the restriction only for the allocation of the file identified by you. This feature can be useful if you wish HANDY not to use certain portions of the disk - such as the last 10 cylinders, or the first 5 cylinders. You specify the cylinder ranges to lock in response to the prompts: Lock cylinders : ... through : ... You may enter as many cylinder ranges as you wish. When you complete an entry, you will be reprompted for an additional range. When you have finished, simply depress at the "Lock cylinders :" prompt. HANDY calculates the fewest number of extents for the given file size and the target disk, and displays the results. The menu at this point would look something like the following illustration: HANDY - LDOS File Space Allocator Filename ? yourfile/dat:3 Size of file (in K) ? 12 Lock cylinders : through : Starting Starting Granule Extent Cylinder Granule Count ====== ======== ======== ======= 1 21 0 8 OK to allocate/create this file (Y/N/C) ? When information for all of the extents has been displayed, you will be provided an opportunity to commence the physical allocation or retreat via the prompt: OK to allocate/create this file (Y/N/C) ? The response to this query also establishes whether or not the "CREATE" bit will be set. If you depress , HANDY will abort the physical allocation thereby providing you with an "escape" mechanism. If the allocation is aborted, the filename will be removed from the target disk's directory. Depress , and HANDY will physically allocate the file. If you specify , the file will be allocated and the "CREATE" bit will be set in the file's directory entry. The "create" bit is used by the DOS to ensure that the space will not be deallocated. Its primary utility is for the pre-allocation of space for random access files; however, HANDY obtains this space using the least number of extents. HANDY cannot allocate space to an existing file which has a non-zero length or which would require more than four extents. Creating an Optimized Disk Before we discuss a step-by-step method that can be used to construct an optimized disk, it is necessary for you to understand some of the actions that the operating system performs when accessing any given file. First, file access consists generally of up to three parts: the opening of a file, passing data from/to the file (input/output), and closing the file. Depending on the size of the file, it takes up space on one or more cylinders. During the process of opening or closing a file, the DOS must read the disk's directory. The disk's directory is usually kept on a cylinder at the midpoint of the disk (i.e. a 40-cylinder disk has its directory at cylinder 20). A disk takes a specified period of time to step from track to track. This may vary on 5-1/4" drives, for example, from 6 milliseconds per track (fastest drive) to up to 40 milliseconds per track (slowest drive). Therefore, the distance in tracks of a file from the directory dictates the minimum amount of disk time required before the first file record can be accessed. If the file is 15 tracks away from the directory on a 20ms step rate drive, this adds up to 300 milliseconds. The space occupied by a file may not exist in a single connected chunk [we actually call this chunk of space an extent]. The size of an extent will vary according to what granules are available when the file is allocated [HANDY will always allocate the space to achieve a maximum number of granules per extent]. An extent cannot exceed 32 granules. Therefore, the number of extents taken up by a file depends on both the size of the file and the "spottedness" of the available free space. When a file is opened, the DOS maintains a file control block (FCB) which contains information on accessing the file's disk records. This FCB can hold the data on up to four extents. Therefore, once a file has more than four extents, the DOS will have to re-examine the file's directory to obtain the data on an extent not found in the FCB. Since the new extent data replaces one of the old, a randomly accessed file with a great number of extents incurs an excessive overhead of directory access which implies greater disk drive head thrashing. This discussion presents two observations. First, files that are frequently accessed should be placed close to the directory. Second, files that are randomly accessed should be contained in as few extents as possible. With these points in mind, let's illustrate a few steps to be taken in order to construct a diskette for optimum access. In this case, we are going to refer to a "frequently accessed" situation - such as a DOS system disk. The following steps may provide a simple way to create just such an optimized diskette. 1. Select the freshly formatted destination disk and invoke MAPPER with both the BLANK and the PRINT options. This will produce a worksheet that you can use to manually construct the disk layout. 2. Invoke CALC referencing the source disk to calculate the number of granules that each file will require. 3. Make your space selections by writing the names of the files onto the worksheet. Remember that placing the most frequently used files closest to the directory should yield the highest performance. This means you have to be aware of the frequency of usage of each file. 4. Using ALLOC, place the files on the disk according to the map you have just manually worked up. 5. Use BACKUP or COPY to transfer the actual files from the SOURCE disk to the allocated DESTINATION disk. Let's examine a specific example. You want to develop an optimized 5-1/4" 80-track double density system disk with two sides. Your source is a 40-track double density 5-1/4" single sided diskette. For this operation, you will not need CALC. Want you want to do is to obtain the existing map of the source (under the assumption that you have been supplied an optimum system disk). Using MAPPER on the source, you will obtain a printout similar to the following [some lines have been deleted to abbreviate the listing]: Diskname : LDOS-514 Free Space : 62K Sides : 1 Density : Double Cylinders : 40 ------------------------------------------------------------ 0 BOOT/SYS QFB/CMD QFB/CMD 1 QFB/CMD FED/CMD FED/CMD 2 FED/CMD FED/CMD FED/CMD 3 ** Empty ** ** Empty ** ** Empty ** 7 ** Empty ** ** Empty ** ** Empty ** 8 LOG/CMD JL/DVR CONV/CMD 9 MOD3/DCT REPAIR/CMD CMDFILE/CMD 10 CMDFILE/CMD KI/DVR FORMAT/CMD 11 FORMAT/CMD FORMAT/CMD FORMAT/CMD 12 BACKUP/CMD BACKUP/CMD BACKUP/CMD 13 BACKUP/CMD LBASIC/OV1 LBASIC/OV2 14 LBASIC/OV2 LBASIC/OV3 LBASIC/CMD 15 LBASIC/CMD LBASIC/CMD LBASIC/CMD 16 SYS0/SYS SYS0/SYS SYS0/SYS 17 SYS7/SYS SYS7/SYS SYS7/SYS 18 SYS7/SYS SYS7/SYS SYS7/SYS 19 SYS7/SYS SYS2/SYS SYS3/SYS 20 DIR/SYS DIR/SYS DIR/SYS 21 SYS8/SYS SYS1/SYS SYS10/SYS 22 SYS11/SYS SYS12/SYS SYS6/SYS 23 SYS6/SYS SYS6/SYS SYS6/SYS 24 SYS6/SYS SYS6/SYS SYS6/SYS 25 SYS6/SYS SYS6/SYS SYS4/SYS 26 SYS5/SYS SYS9/SYS BASIC/CMD 27 PATCH/CMD PATCH/CMD PR/FLT 28 MINIDOS/FLT KSM/FLT LCOMM/CMD 29 LCOMM/CMD RS232T/DVR HITAPE/CMD 30 EQUATE3/EQU EQUATE3/EQU EQUATE3/EQU 31 COPY23B/BAS ** Empty ** ** Empty ** 32 ** Empty ** ** Empty ** ** Empty ** 39 ** Empty ** ** Empty ** ** Empty ** The next step is to invoke MAPPER on the freshly formatted destination disk using the PRINT and BLANK parameters. This will generate a worksheet that looks something like the following [some lines have been deleted to abbreviate the listing while others have been filled in based on the next step that you will undertake]: Diskname : FLOP Free Space : 707K Sides : 2 Density : Double Cylinders : 80 ----------------------------------------------------------------- 0 BOOT/SYS BOOT/SYS BOOT/SYS BOOT/SYS [ -----> ] [ -----> ] 1 [ fed/cmd ] [ -----> ] [ -----> ] [ -----> ] [ -----> ] [ ] 2 [ ] [ ] [ ] [ ] [ ] [ ] 32 [ ] [ ] [ ] [ ] [ ] [ ] 33 [ ] [ ] [ ] [ ] [ ] [ ] 34 [ ] [ ] [ ] [ ] [ ] [ ] 35 [ ] [ ] [ ] [ ] [ ] [ ] 36 [ ] [ ] [ ] [ ] [ ] [ ] 37 [ ] [ ] [lbasic/cmd] [ -----> ] [ -----> ] [ -----> ] 38 [ -----> ] [ -----> ] [ -----> ] [ sys7/sys ] [ -----> ] [ -----> ] 39 [ -----> ] [ -----> ] [ -----> ] [ -----> ] [ sys2/sys ] [ sys3/sys ] 40 DIR/SYS DIR/SYS DIR/SYS DIR/SYS DIR/SYS DIR/SYS 41 [ sys8/sys ] [ sys1/sys ] [ sys10/sys] [ sys11/sys] [ sys12/sys] [ sys6/sys ] 42 [ -----> ] [ -----> ] [ -----> ] [ sys7/sys ] [ -----> ] [ -----> ] 43 [ -----> ] [ -----> ] [ sys4/sys ] [ sys5/sys ] [ sys9/sys ] [ basic/cmd] 44 [ patch/cmd] [ -----> ] [ pr/flt ] [ ] [ ] [ ] 45 [ ] [ ] [ ] [ ] [ ] [ ] 46 [ ] [ ] [ ] [ ] [ ] [ ] 47 [ ] [ ] [ ] [ ] [ ] [ ] 78 [ ] [ ] [ ] [ ] [ ] [ ] 79 [ ] [ ] [ ] [ ] [ ] [ ] The next step is to transfer the file names from the source map to the destination worksheet, working out from either side of the directory. The sample worksheet has already been filled with some of the file names. Since both the source and destination diskettes have the same number of sectors per granule, CALC was not needed to calculate the granule requirements. You would have needed CALC's information if the source and destination used a different number of sectors per granule - say one being a single density 5-1/4" diskette and the other being a double density 5-1/4" diskette. Once the worksheet is completed, the information is keyed into ALLOC so that the space for each file is allocated. The series of entries will be something like the following: user entry description of entry ---------- -------------------- alloc invoke ALLOC sys8/sys:2 enter the file specification 41 starting cylinder = 41 0 starting granule = 0 1 the file uses one granule response to second extent OK to allocate sys1/sys:2 the next file specification 41 starting cylinder = 41 1 starting granule is 1 1 also one granule used response to second extent OK to allocate sys6/sys:2 let's skip to this file 41 starting cylinder is 41 5 starting granule = 5 9 sys6/sys used 9 granules (continue with data for remaining files) Model I/III users may prepare a "key" file containing all required entries and use the redirection capabilities of ZSHELL to redirect the keyboard input to use the prepared key file. Up to this point, all of the files have been allocated space on the destination diskette. You now have to transfer the contents of the existing files from the source diskette to the destination diskette. Use BACKUP to accomplish this procedure. This completes the allocation and generation of the optimized diskette. GLOSSARY CREATE BIT This refers to a flag contained in the directory entry for a file. When this bit is set, the operating system will be kept from deallocating any unused space at the end of the file when the file is closed. Such a file will never shrink in size. The file will remain as large as its largest allocation. The flag is normally set by the DOS CREATE command. CYLINDER A cylinder is a term which represents all like-numbered tracks on all surfaces of a disk. For example, on a two surface media, track zero of surface zero and track zero of surface one are grouped together into cylinder zero. Where a disk uses only a single surface, the terms cylinder and track both represent the same space and are thus equivalent. EXTENT An extent contains data on the allocation of disk space. Each extent can contain the allocation information for a maximum of 32 contiguous granules. The contents of the extent tells you what cylinder stores the first granule of the extent, what is the number of that granule, and how many contiguous granules are in use in the extent. GRANULE A group of sectors is allocated whenever additional space is needed for a file. This group is called a GRANULE and is always a constant size for any given disk. The size of a granule generally increases with the increasing size of the disk storage device. K A "K" is a term applied to 1024 characters of storage. When applied to a disk, it would represent four sectors of space. SECTOR Each track of a disk is divided into subareas called sectors. Each sector has an identifying number within the track. In LDOS and TRSDOS systems, this sector usually holds 256 characters. The sectors are usually numbered starting from zero on each track. TRACK The magnetic layer of particles on a disk's surface are magnetized into concentric circles of storage during the formatting process. Each circle is called a track. A typical 40-track disk has a density of 48 tracks per inch. Thus the diskette region used has a lateral width of 0.833 inches.