home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / UTILITYS / FIRE12.ARC / RESTORE.DOC < prev    next >
Text File  |  1991-08-11  |  18KB  |  337 lines

  1.  
  2. RESTORE.DOC - Documentation for RESTORE.COM
  3.                 31 January 19871
  4.                 Steve Dirickson
  5.  
  6.  
  7. Description:
  8. -----------
  9. RESTORE is a utility program that improves disk performance by regrouping
  10. the allocation groups assigned to each file on the disk so that each file
  11. is allocated to sequential sectors on the disk i.e., 'restoring' the disk
  12. to the condition it was in when it was new.
  13.  
  14. Discussion:
  15. ----------
  16. CP/M-compatible operating systems store files on disk in what are called
  17. "allocation groups."  The size of an allocation group is determined by
  18. the system's BIOS, and is typically 1k or 2k bytes for floppy disks, and
  19. 2k, 4k, or 8k for hard disks.  The allocation group is the smallest unit
  20. of storage on the disk; if you write a one-byte file to the disk, it will
  21. take up just as much space (in the sense of making that space unavailable
  22. for storing other files) as would a file the size of one entire alloca-
  23. tion group.
  24.  
  25. When a disk is formatted, all allocation groups are free, and the first
  26. file written to the disk occupies the allocation groups immediately after
  27. the directory, in sequence.  The next file written to the disk occupies
  28. the groups after the first and so on.  When a file is deleted, its allo-
  29. cation groups are freed up, and may be reused by the system.
  30.  
  31. As files are written and erased, later files start to become 'fragmented'
  32. i.e., they are written with some allocation groups in one location and
  33. other groups in other locations.  Thus, when these 'fragmented' files are
  34. read or written, the system must position the read/write head over one
  35. track for part of the file, then move the head to another track for more
  36. of the file.  This starts to degrade disk performance, because more and
  37. more time is spent moving the head around to find the various parts of
  38. the file, causing access times for the files to get longer and longer.
  39. This problem affects both floppy and hard disks.  The effect this has on
  40. the system response is dependent on how the system buffers the disk data
  41. in memory.  A system that uses a 'track buffer' system, where an entire
  42. track is saved in memory each time the disk is read, will be VERY much
  43. slower when accessing severely fragmented files than when the files are
  44. stored in sequential allocation groups and thus several related groups
  45. are kept in memory together.  Similarly, a system that uses multiple-
  46. record disk I/O will be seriously degraded by disk fragmentation.  Con-
  47. versely, an unbuffered BIOS, and especially an unblocked BIOS, will be
  48. less affected, because latency (the time the controller has to wait for
  49. the desired record to rotate under the head) is more significant in com-
  50. parison to track stepping times.
  51.  
  52. The only way to recover from this situation has been to copy all files
  53. on the disk to backup disks, reformat the disk (or simply erase all the
  54. files), and then recopy the files from the backup disk(s) to the working
  55. disk.  This takes a significant amount of time to do, and it is even more
  56. inconvenient if files are assigned to several user areas on the disk,
  57. since each user area on the backup disk must be individually entered and
  58. the files in that area copied to the corresponding area on the work disk.
  59.  
  60. RESTORE is designed to make this process easier by eliminating the copy
  61. to and from the backup disks.  RESTORE works only on the disk being re-
  62. stored, and thus may be used even in a single-disk system.
  63.  
  64.  
  65.                 ***WARNING***
  66.  
  67. Since RESTORE does in-place restoration of the disk, it has INCREDIBLE
  68. potential for wrecking havoc with your disk if something goes wrong while
  69. it is working, like a loss of power or a controller fault.  Therefore,
  70. you should ALWAYS back up the disk to be RESTOREd shortly before running
  71. the program.  This shouldn't be much of a problem, since you do a full
  72. back up of your hard disk at least every weekend, right?  RIGHT?  NO?!!
  73. Well, if you don't, you should.  It only takes one occurrence of having
  74. to rebuild a disk's directory one group at a time to make you a believer.
  75. Just after a full backup is the optimum time to run RESTORE.
  76.  
  77.  
  78. Use:
  79. ---
  80. NOTE:  You MUST sort the directory of the disk to be RESTOREd before
  81. running RESTORE, by running SAP, SAPP, CLEANDIR or some similar program.
  82. If RESTORE finds that the directory is not sorted, it will tell you so
  83. and quit. (SAP.COM, version 5.0 is included in this .LBR).  Also note
  84. that some older versions of CLEANDIR, SAP, SAPP, etc., did not properly
  85. sort the directory because they did not include the last directory entry
  86. on the disk in the sort.  RESTORE WILL find this entry, and will tell
  87. you that your directory is not sorted.    You can use DUU, DU3, PATCH or
  88. your own favorite disk utility to examine the directory of the disk to
  89. see what is wrong.
  90.  
  91. Once you have the disk's directory sorted, simply start the program by
  92. typing 'RESTORE'.  The program will sign on, and ask you to change disks
  93. if you desire.    This allows single-disk users to place the disk contain-
  94. ing the program in the drive, start the program, and then swap in the
  95. disk to be restored.  This means you don't have to copy the program to
  96. each disk you want to restore.
  97.  
  98. Note that RESTORE  --ALWAYS--  works on the user's default disk i.e.,
  99. the one you were on when you invoked the program.  So, if you want to
  100. restore the disk in drive B but RESTORE is on the disk in drive A, you
  101. MUST log onto disk B and then call the program from drive A:
  102.  
  103.         A>B:<ret>
  104.         B>A:RESTORE <ret>
  105.  
  106. RESTORE reads in the directory of the default disk, analyzes the direc-
  107. tory, and prints some information; how many directory entries are on the
  108. disk, how many groups are allocated, how many groups have to be swapped,
  109. and how many times the directory will be rewritten.  This last is sig-
  110. nificant since 1) directory writes usually take much longer than other
  111. writes, because most BIOSs immediately write their buffer to the disk
  112. after a change in the directory, rather than waiting until the user wants
  113. to write somewhere else, and 2) the directory takes up several allocation
  114. groups, and the entire directory is rewritten after each directory entry
  115. has been fixed.  Note that the number of directory entries reported by
  116. RESTORE will probably not match the number of files on the disk, since
  117. each extent of a file takes up its own directory entry.
  118.  
  119. After RESTORE tells you what it is going to have to do to the disk, it
  120. asks you to type 'Y' to restore the disk, or anything else to abort.  You
  121. may enter an upper or lower case Y, or even type CTL-Y.  Anything else
  122. will cause RESTORE to abort without doing anything to the disk.
  123.  
  124. After you type 'y', RESTORE will start to fix your disk.  It prints the
  125. name of the directory entry is is working on, so you can keep track of
  126. how it is doing.  You may type a CTL-C at any time, and RESTORE will a-
  127. bort after it finishes the current directory entry, and tell you how many
  128. directory entries are left over.  Left to itself, RESTORE will finish the
  129. disk, then tell you it is finished and terminate.
  130.  
  131. If you are using a system that does not reload the directories from disk
  132. on each warm boot, like ZRDOS version 1.6 and later, you will need to do
  133. whatever your system needs (run DISKRST in the case of ZRDOS) to restore
  134. the system's directory to match the one on disk.  Remember, RESTORE works
  135. thorough the BIOS, so the DOS has no idea what is going on.
  136.  
  137.  
  138. System Requirements:
  139. -------------------
  140. Operating System - A CP/M-compatible operating system that supports con-
  141. sole input and output and the following direct BIOS function calls:
  142.  
  143.       Select Disk
  144.       Set Track
  145.       Set Sector
  146.       Set DMA Address
  147.       Disk Read
  148.       Disk Write
  149.       Sector Translation
  150.  
  151. These are the only direct BIOS calls used by RESTORE.  Console I/O is
  152. done via the BDOS, so you may use the CTL-P to echo the output to your
  153. printer.  If you do so, you may need to install the patch discussed be-
  154. low.
  155.  
  156. Processor - Versions are provided for both 8080/8085-compatible proces-
  157. sors (RESTOREI.COM) and for Z80-compatible processors (RESTOREZ.COM).
  158. The Z80 version is about 5% smaller and runs about 1% faster than the
  159. 8080 version.
  160.  
  161. Memory - Depends on your disk system.  The largest disk directory RESTORE
  162. can handle is 1024 entries (DRM = 1023 for you operating system hacker
  163. types).  This size disk typically uses 4k byte allocation groups.  With
  164. this type of disk, RESTORE requires a 44k TPA.    This is the largest TPA
  165. requirement.  Other disk sizes can be restored in less TPA.  A SSSD
  166. floppy limited to 64 directory entries using 1k allocation groups can be
  167. RESTOREd in 8k of TPA.
  168.  
  169. Note that RESTORE is NOT a ZCPR3 utility.  I have tried to make it as
  170. nearly universal as possible.  It does not use cursor-positioning se-
  171. quences for the terminal, or require any installation.    The only thing
  172. your terminal has to be able to do is receive and display standard ASCII
  173. characters, including being able to do a carriage return without a line-
  174. feed.  This is used in the display of the files being processed.  The
  175. same line is rewritten as each new file is started.  If your terminal
  176. can't do a carriage return without a line feed (or makes a mess doing
  177. so, like a TTY), or if you want to echo the output of the program to
  178. your printer without wearing a hole in the paper, install the following
  179. patch:
  180.  
  181.     Patches:
  182.     -------
  183.     To make the file display do a line feed as well as a
  184.     carriage return, use your debugger or disk utility to
  185.     look at the word at address 103h (just after the jump
  186.     at the start of the program).  This word is the address
  187.     of the location in the file display string where you
  188.     can insert a line feed character (0ah).  Put a LF there
  189.     and write the modified file back to disk.
  190.  
  191.     The other patch option is the flag that controls the
  192.     disk-change wait.  As released, the program will print
  193.     a message telling you to change disks if necessary, and
  194.     press any key when ready.  Then it waits for you to
  195.     press any key.    Later, after the statistics for the disk
  196.     are printed, it asks you to press 'Y' to continue, or
  197.     any other key to abort.  If you don't want these waits,
  198.     or you want to do unattended 'batch processing' of mul-
  199.     tiple drives, you will need to patch this byte to zero.
  200.     It is located just after the word described above, at
  201.     address 105h.  It is non-zero to have the program wait
  202.     for input in these two situations, or zero to start
  203.     processing immediately.  The input for these two user
  204.     waits is done using the BDOS 'Read Console Buffer'
  205.     function, so ZEX or XSUB may be used to provide the
  206.     input; note, however, that doing so will cost you about
  207.     3k of TPA, and may cause a memory shortage problem.
  208.     Try it on your largest disk.  If it works, you can have
  209.     it both ways.
  210.  
  211.  
  212. Limitations:
  213. -----------
  214. As discussed above, the maximum size disk RESTORE can handle is one with
  215. a limit of 1024 directory entries using 4K byte allocation groups (ac-
  216. tually, it will also handle this size disk with 8K allocation groups but
  217. only if you have a 51.5k TPA i.e., your BDOS starts at some address after
  218. CE00h.    Since I am a believer in the 48k TPA convention, this is not the
  219. advertised maximum disk size).    This is the typical configuration for
  220. most popular CP/M hard disks (10-30 Mb).  If you have a drive with a DRM
  221. of 2047, RESTORE will not run.    I'm not really sure why people make disks
  222. like this, since, with CP/M's limit of 8 Mb per logical disk, this means
  223. that there is room for one directory entry for each allocation group on
  224. the disk!.  That's a lot of lost directory space.  Since it would take
  225. 64k simply to read in the directory of such a disk, RESTORE will tell you
  226. that there is not enough memory and quit.  I have chosen not to use the
  227. incremental-directory-read technique that was added to CLEANDIR and SAP
  228. for such disks, since, to remain within the 48k TPA boundary, this would
  229. only increase the maximum number of directory entries from 1024 to 1152.
  230.  
  231. One of the problems associated with a program of this type is the hand-
  232. ling of bad sectors on the disk.  Since there is no standard way of
  233. marking bad sectors, I have completely ignored the issue in writing the
  234. program.  I recommend the following system for those with bad sectors
  235. on their hard disk:
  236.  
  237.      1) You have probably used BDxx, FBAD, or whatever you use to
  238.     mark the bad sectors on the disk.  Use DUU, DU3, PATCH, or
  239.     your own disk utility to examine the disk's directory.
  240.     Note the allocation groups that are assigned to the '.BAD'
  241.     (or however your utility marks them) files.  Make a list
  242.     of the allocation groups containing the bad sectors.
  243.  
  244.      2) After you finish backing up your disk (that IS when you use
  245.     RESTORE, isn't it?  See the WARNING above if not), run RE-
  246.     STORE, then use your disk utility to look at the disk's di-
  247.     rectory and see what files are now assigned to the allocation
  248.     groups on your list of bad groups.  Make a list of these
  249.     files.
  250.  
  251.      3) Erase the files on the list.
  252.  
  253.      4) Rerun FBAD, etc., to re-mark the bad wgroups.
  254.  
  255.      5) Copy over the files on the list from your backup disk.
  256.  
  257. I realize that this is somewhat cumbersome, and I apologize for that.
  258. But, since there is no sandardized method for handling bad sectors, this
  259. this is the best I have been able to come up with.
  260.  
  261. Note:  When the discussion above talks about 'using your disk utility'
  262. to examine the disk's directory, you may use the DMAP program included
  263. with RESTORE instead.  See the DMAP.DOC file for information on this u-
  264. tility.  Simply type 'DMAP' and look for the filenames or allocation
  265. groups you want to scroll by.
  266.  
  267.  
  268. Operation:
  269. ---------
  270. RESTORE uses a brute-force method to relocate allocation groups.  It
  271. reads in the directory (which MUST be sorted), and decides from the di-
  272. directory allocation data in the Disk Parameter Block for the disk how
  273. many groups are allocated to the directory.  The next sequential alloca-
  274. tion group should be assigned to the first file in the directory.  RE-
  275. STORE looks to see if that is the case.  If not, it scans the directory
  276. to find what file has that group allocated to it.  If the desired group
  277. is not allocated, RESTORE copies the group referenced in the directory
  278. into the desired group, then changes the directory entry to show the new
  279. group.    If the group is allocated to another file, RESTORE reads both
  280. groups into memory, then writes them to the alternate locations, effect-
  281. ively swapping the groups in place.  Both directory entries are modified,
  282. the next sequential allocation group is selected, and the process re-
  283. peats.    The updated directory is written to the disk after each directory
  284. entry is completed, not after each allocation group swap.  Thus, the
  285. number of directory rewrites will typically be about one-half to one-
  286. fourth (on a hard disk; one-fourth to one-eighth on a floppy disk) of
  287. the number of group swaps required.
  288.  
  289. When I say that the method is 'brute force', I mean that no intelligence
  290. is used in the sort process.  Under worst-case conditions, the first al-
  291. location group on a disk might be free, with all other groups assigned
  292. in the desired sequence to the files in the directory.    In this case the
  293. disk is really not fragmented and nothing needs to be done.  If you run
  294. RESTORE on a disk in this situation, it will tell you that EVERY GROUP
  295. on the disk must be moved, and will do so if you let it.  No analysis of
  296. the fragmentation of the disk is done, and no optimization is used to
  297. figure out how to restore the disk using the least number of group swaps.
  298. While possible, the code to do this would make the program long enough
  299. that it might not be able to process a 1024-entry directory.  On a more
  300. basic level, it would take me longer to write the optimization than I
  301. feel is reasonable.  RESTORE works, and works well.  The machine does
  302. not in the least mind moving the same allocation group three or four
  303. times.
  304.  
  305. On the subject of speed:  RESTORE is, in addition to being more conven-
  306. ient than copying all the files back from a backup disk, considerably
  307. faster than that method.  While times vary depending on the degree of
  308. fragmentation and the hardware, I have found RESTORE to be about 20%
  309. faster than a NON-VERIFYING copy of files from backup floppies back to
  310. my hard disk.  RESTORE does read-after-write CRC verification of all
  311. disk writes.  Plus, you don't have to sit around and feed your machine
  312. floppies for hours.  RESTORE will process a filled 20 Meg hard disk in
  313. about 5 hours on my hardware; doing the same thing, with verification,
  314. from floppies takes over 9 hours and about 28 disk swaps!  With RESTORE,
  315. simply use a multiple-command line or SUBMIT file (DON'T use ZEX or XSUB
  316. if you have a big hard disk) and let RESTORE crunch away over night, or
  317. while you are out shopping for a computer for your wife (or husband).
  318. Note that if you want to use this 'batch processing' of multiple drives,
  319. you must patch the disk-change flag to zero as described above to disable
  320. the disk-change wait.
  321.  
  322.  
  323. DISCLAIMER:
  324. ----------
  325. This is a very useful utility, and I have tested it extensively.  How-
  326. ever, as noted above, it is also very capable of lunching your disks
  327. completely if the system has a problem.  Use it in good health and hap-
  328. piness, but MAKE BACKUPS BEFORE YOU USE IT!!.  Papa Wallenda ran his
  329. system without a backup.  He's not around any more.  'Nuff said.
  330.  
  331.                 Steve Dirickson
  332.                 21145 Raintree Place NW
  333.                 Poulsbo  WA  98370-9726
  334.                 Voice: 206-697-1270/9311
  335.                 BBS: Seattle's 'downspout': 206-325-1325
  336.                      ZNode Central: 415-489-9005
  337.