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 / ENTERPRS / CPM / UTILS / S / SORTDISK.ARK / PACK.DOC < prev    next >
Text File  |  1988-02-29  |  8KB  |  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èpermutation phase cause the program to stop moving groups and try to
  57. extricate itself as gracefully as possible.  The directory is fixed up
  58. to reflect the moves that were accomplished.  The group that caused
  59. the problem will generally end up allocated twice, so up to two files
  60. may be lost.  A degree of DU3 wizardry is necessary to recover the
  61. disk.  PACK reports which group could not be read/written.  Use the
  62. DU3 M command to find which file the group is allocated to, erase that
  63. file, then check with DU3 again to see if the group is still allocated
  64. to another file and erase that one too if so.  Finally allocate the
  65. group by hand or with a suitable utility to a BADSECT file to stop it
  66. being used again.  The one or two erased files can be restored from
  67. backup (you have got a backup, haven't you). Read or write errors
  68. during the final directory update are ignored.  There is no way to
  69. recover if the directory is flakey.
  70.  
  71. The write type is passed to the BIOS in register C using the following
  72. strategy: 1st sector of group, C=2 (write unallocated data); remaining
  73. sectors, C=0 (write normal); last sector of a directory group, C=1
  74. (write to directory). Note that the first and intermediate writes to
  75. directory groups are not declared as directory writes.  This
  76. eliminates unecessary reading and writing of the directory groups by
  77. the BIOS blocking/unblocking logic, and should be quite legitimate.  It
  78. could be a problem if your BIOS has strange ideas about
  79. blocking/deblocking though.  In that case you should set the byte at
  80. location 010BH in PACK.COM to a non-zero value, which will force PACK
  81. to pass C=1 on all directory writes.
  82.  
  83. The memory requirements of PACK in addition to the program itself are
  84. 4 bytes per allocation group on the disk (4*DSM) plus space for 2
  85. allocation groups, so 40K of TPA is sufficient to pack a worst case
  86. disk (5K program + 4*512 tables + 2*16K group buffers). The memory is
  87. allocated before any changes are made to the disk, and if there is not
  88. enough PACK says so and quits.  The directory is scanned a few times
  89. during the planning phase, and as much as will fit is cached in the
  90. TPA at that time.  Any excess is re-read from the disk on each scan.
  91.  
  92. PACK resets the disk via BDOS function 37 after packing it, so there
  93. is no need to run DISKRST after PACK. BDOS will rebuild the allocation
  94. vectors the next time the disk is logged-in.
  95.  
  96. PACK refuses to process a disk which the BDOS considers is read-only.
  97.  
  98. PACK is written to run under ZCPR3 with either CP/M 2.2 or ZRDOS 1.7
  99. as the BDOS. It was developed using Echelon's ZAS/ZLINK assembler and
  100. linker, and uses library routines from SYSLIB and Z3LIB.
  101.  
  102.  
  103.  
  104. Disk and directory sizes under CP/M 2.2 (and ZRDOS 1.7):
  105.  
  106. The contraints on disk and directory size in CP/M 2.2 are as follows.
  107. There can be at most 2**16 (65536) logical sectors (@128 bytes) on the
  108. disk.  The BDOS assumes it can use 16 bit arithmetic when calculating
  109. sector numbers, and values in the random record field of the fcb are
  110. limited to 16 bits.  This gives us the CP/M 2.2 file and disk sizeèlimit of 8MBytes.  CP/M 3 extends this to 32MBytes by using 2 more
  111. bits in sector numbers.  There are two separate limits on directory
  112. size.  The allocation groups reserved for the directory must be
  113. representable in the 16 bits available in the disk parameter block
  114. (AL0 and AL1 in DRI parlance). This gives a limit of 16 * Group size /
  115. 32 entries.  But the number of directory entries that can ever be
  116. needed is also limited to one per allocation group when the disk is
  117. full of minimal size files.  The number of files is then given by the
  118. total allocation groups less those assigned for the directory.
  119.  
  120. Allocation      Max Disk    Max Groups   Max Number of Directory Entries
  121. Group size      size        per Disk      16 Groups   1 entry per Group
  122.  
  123.     1K          256K          256           (512)          248
  124.     2K            8M         4096           1024         (4032)
  125.     4K            8M         2048          (2048)         2032
  126.     8K            8M         1024          (4096)         1020
  127.    16K            8M          512          (8192)          511
  128.  
  129. Therefore the worst case directory size is 65024 Bytes, on a disk with
  130. a group size of 4K containing 2032 small files.  Worst case number of
  131. groups is 4096
  132.  
  133. Author:
  134.  
  135. Frank Cringle
  136. 22 Ellens Glen Road
  137. Edinburgh EH17 7QP
  138. Scotland
  139.  
  140. (031) 664 4616
  141.