home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / cpm / utils / s / sortdisk.ark / PACK.DOC < prev    next >
Encoding:
Text File  |  1988-03-01  |  7.6 KB  |  141 lines

  1. .cw 10
  2. PACK is a program for reorganising CP/M disks.  It is most useful for
  3. hard disk users who want to improve system performance by speeding
  4. access to frequently used files.  It ensures that all data belonging
  5. to each file is contiguous on the disk.  It also allows the user to
  6. specify that certain files or groups of files should not be moved, and
  7. that other files or groups of files should be moved to the beginning
  8. of the disk, where access to them is assumed to be faster (involving
  9. less head movement to and from the directory).
  10.  
  11. As with all programs which reorganise a disk or its directory, you
  12. should be extremely careful when using PACK. Only run it after you
  13. have backed-up all data to a safe place.  You should do that regularly
  14. anyway, as disasters can always occur, but if your system crashes
  15. while PACK is running you will definitely have to restore the disk
  16. from backup.  As far as I know PACK itself is bug-free (though I offer
  17. no guarantee whatsoever), but power failures, hardware glitches or
  18. itchy fingers on the RESET button will trash your disk.
  19.  
  20. PACK takes the fast and loose approach to the disk packing task.  It
  21. first of all plans exactly what it is going to do, recording the plan
  22. in an allocation group permutation schedule.  It then asks the user
  23. for confirmation, and if given it permutes the groups and then updates
  24. the directory to reflect the new situation.  Until the directory
  25. update is complete the disk is in an undefined state and the system
  26. had better not crash.  The time required obviously depends on how
  27. disorganised the disk was and what its data transfer rate is.  On my
  28. NEC D3126 it takes about 10 minutes to pack a badly fragmented 7MByte
  29. partition.
  30.  
  31. The alternative approach to disk packing (taken by Steve Dirickson in
  32. his RESTORE utility), is to keep the directory up to date while moving
  33. data groups around the disk.  This means that the disk will probably
  34. be intact if the program is interrupted, but it involves an inordinate
  35. number of writes to the directory during the packing process.  This
  36. slows the whole process down by a large factor, and increases the
  37. probability that, if there is a power failure or unscheduled reset,
  38. the system will be in the middle of writing a directory sector at the
  39. time.  My philosophy is that packing is a potentially risky business,
  40. and the quicker it is over with the better.
  41.  
  42. Writes to the disk are not checked by re-reading.  RESTORE does this
  43. (and checks the CRC of the read-back data). If you have flakey disk
  44. hardware you should concentrate on fixing it rather than using PACK.
  45. If your BIOS caches disk blocks or tracks, read-after-write at the
  46. user program level is pointless anyway.  Alternatively, put read-
  47. after-write logic in your BIOS, so that all programs which write to
  48. the disk benefit (and run like treacle). PACK does a lot of writing,
  49. but is not fundamentally different from any program which writes to
  50. disk; it has to trust that what it has written is successfully
  51. recorded.
  52.  
  53. PACK reads and writes the disk (necessarily) via direct BIOS calls.
  54. Sector read or write errors reported by the BIOS are treated as
  55. follows.  During the initial directory scan any read error causes the
  56. program to report the error and quit.  Read or write errors during the
  57. èpermutation phase cause the program to stop moving groups and try to
  58. extricate itself as gracefully as possible.  The directory is fixed up
  59. to reflect the moves that were accomplished.  The group that caused
  60. the problem will generally end up allocated twice, so up to two files
  61. may be lost.  A degree of DU3 wizardry is necessary to recover the
  62. disk.  PACK reports which group could not be read/written.  Use the
  63. DU3 M command to find which file the group is allocated to, erase that
  64. file, then check with DU3 again to see if the group is still allocated
  65. to another file and erase that one too if so.  Finally allocate the
  66. group by hand or with a suitable utility to a BADSECT file to stop it
  67. being used again.  The one or two erased files can be restored from
  68. backup (you have got a backup, haven't you). Read or write errors
  69. during the final directory update are ignored.  There is no way to
  70. recover if the directory is flakey.
  71.  
  72. The write type is passed to the BIOS in register C using the following
  73. strategy: 1st sector of group, C=2 (write unallocated data); remaining
  74. sectors, C=0 (write normal); last sector of a directory group, C=1
  75. (write to directory). Note that the first and intermediate writes to
  76. directory groups are not declared as directory writes.  This
  77. eliminates unecessary reading and writing of the directory groups by
  78. the BIOS blocking/unblocking logic, and should be quite legitimate.  It
  79. could be a problem if your BIOS has strange ideas about
  80. blocking/deblocking though.  In that case you should set the byte at
  81. location 010BH in PACK.COM to a non-zero value, which will force PACK
  82. to pass C=1 on all directory writes.
  83.  
  84. The memory requirements of PACK in addition to the program itself are
  85. 4 bytes per allocation group on the disk (4*DSM) plus space for 2
  86. allocation groups, so 40K of TPA is sufficient to pack a worst case
  87. disk (5K program + 4*512 tables + 2*16K group buffers). The memory is
  88. allocated before any changes are made to the disk, and if there is not
  89. enough PACK says so and quits.  The directory is scanned a few times
  90. during the planning phase, and as much as will fit is cached in the
  91. TPA at that time.  Any excess is re-read from the disk on each scan.
  92.  
  93. PACK resets the disk via BDOS function 37 after packing it, so there
  94. is no need to run DISKRST after PACK. BDOS will rebuild the allocation
  95. vectors the next time the disk is logged-in.
  96.  
  97. PACK refuses to process a disk which the BDOS considers is read-only.
  98.  
  99. PACK is written to run under ZCPR3 with either CP/M 2.2 or ZRDOS 1.7
  100. as the BDOS. It was developed using Echelon's ZAS/ZLINK assembler and
  101. linker, and uses library routines from SYSLIB and Z3LIB.
  102.  
  103.  
  104.  
  105. Disk and directory sizes under CP/M 2.2 (and ZRDOS 1.7):
  106.  
  107. The contraints on disk and directory size in CP/M 2.2 are as follows.
  108. There can be at most 2**16 (65536) logical sectors (@128 bytes) on the
  109. disk.  The BDOS assumes it can use 16 bit arithmetic when calculating
  110. sector numbers, and values in the random record field of the fcb are
  111. limited to 16 bits.  This gives us the CP/M 2.2 file and disk size
  112. èlimit of 8MBytes.  CP/M 3 extends this to 32MBytes by using 2 more
  113. bits in sector numbers.  There are two separate limits on directory
  114. size.  The allocation groups reserved for the directory must be
  115. representable in the 16 bits available in the disk parameter block
  116. (AL0 and AL1 in DRI parlance). This gives a limit of 16 * Group size /
  117. 32 entries.  But the number of directory entries that can ever be
  118. needed is also limited to one per allocation group when the disk is
  119. full of minimal size files.  The number of files is then given by the
  120. total allocation groups less those assigned for the directory.
  121.  
  122. Allocation      Max Disk    Max Groups   Max Number of Directory Entries
  123. Group size      size        per Disk      16 Groups   1 entry per Group
  124.  
  125.     1K          256K          256           (512)          248
  126.     2K            8M         4096           1024         (4032)
  127.     4K            8M         2048          (2048)         2032
  128.     8K            8M         1024          (4096)         1020
  129.    16K            8M          512          (8192)          511
  130.  
  131. Therefore the worst case directory size is 65024 Bytes, on a disk with
  132. a group size of 4K containing 2032 small files.  Worst case number of
  133. groups is 4096
  134.  
  135. Author:
  136.  
  137. Frank Cringle
  138. 22 Ellens Glen Road
  139. Edinburgh EH17 7QP
  140. Scotland
  141.  
  142. (031) 664 4616
  143.