home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / documentation / documents / a252efmt < prev    next >
Internet Message Format  |  1999-04-27  |  15KB

  1. From: pcolmer@acorn.co.uk (Philip Colmer)
  2. Date: 26 Oct 90 12:55:54 GMT
  3.  
  4. Time to put this one to rest, methinks ...
  5.  
  6. When you format a hard drive, be it an ADFS drive or a SCSI drive, you can
  7. choose between "Old map" and "New map" formats. To see which format your
  8. hard drive is in, type
  9.  
  10.   *ADFS:Map :4
  11.  
  12.   (or :5, 6 or 7)
  13.  
  14. If the output says "new map", you've got a new map format.
  15.  
  16. Some facts about the new map format:
  17.  
  18. * this format has the ability to store smallish files within the space taken
  19.   on the disc by the directory. The maximum size of these files is the value
  20.   given to the LARGE FILE ALLOCATION UNIT, or LFAU.
  21.  
  22. * the LFAU is specified when you format the hard drive. Apart from
  23.   specifying the maximum size of a file which can be fitted within a
  24.   directory space (NB *NOT* the maximum size of a file which can be stored
  25.   on the disc), it is also related to the CAPACITY of the drive.
  26.  
  27.   The larger the drive, the higher the LFAU needs to be in order for the
  28.   drive to be able to be formatted. The following is a table of disc sizes
  29.   versus possible LFAUs:
  30.  
  31.   Capacity               LFAU        "Size" of a directory (approx)
  32.   ========               ====        ==============================
  33.   Up to 124Mbytes        256         4K
  34.   Up to 249Mbytes        512         8K
  35.   Up to 499Mbytes        1024        16K
  36.   Up to 999Mbytes        2048        32K
  37.  
  38.   The "up to" values are inclusive. You can, of course, specify a large
  39.   LFAU, but the side effect is that the larger the LFAU, the more disc space
  40.   a directory takes, hence the "wasted disc space".
  41.  
  42.   This arrangement, therefore, allows files up to the LFAU to be stored on
  43.   the disc without taking up any more disc space, and without fragmenting
  44.   the disc too much.
  45.  
  46. * when saving files to a new format disc, FileCore will automatically try
  47.   and coalesce blocks to avoid fragmentation.
  48.  
  49. * to determine what value LFAU your drive has:
  50.  
  51.   DIM block% 64
  52.   SYS"ADFS_DescribeDisc",":4",block%
  53.   P."LFAU is ";2^(block%?5)
  54.  
  55. Some facts about the old map format:
  56.  
  57. * each directory always takes 4Kbytes
  58.  
  59. * the disc is not automatically compacted.
  60.  
  61. Note that ALL of the above applies to any FileCore based filing system. This
  62. includes ADFS and SCSIFS.
  63.  
  64. Hope this clears everything up.
  65.  
  66. --Fil.
  67.  
  68.  
  69.  
  70. From: nick@abccam.abcl.co.uk (Nick Reeves)
  71. Summary: E FORMAT DESIGN DOCUMENT
  72. Date: 26 Oct 90 16:53:50 GMT
  73. Organization: Active Book Company Limited, Cambridge, UK
  74.  
  75.  
  76. Briefly:
  77. The large directory size is the price you pay for a disc structure
  78. which almost always keeps files contiguously, but can use fragments if
  79. it has to.  The rest of the space is not always wasted as small files
  80. in the directory can use it, and only have their length rounded up to
  81. the sector size rather than the cluster size. They are also quick to
  82. access as they are close to the directory and don't need to update the
  83. free space map.
  84.  
  85.  
  86.                 NEW DISC FILE STRUCTURE FOR RISC OS
  87.                 ===================================
  88.  
  89. MOTIVATION
  90. ----------
  91. The aim of the new file structure is firstly to remove the following
  92. restrictions of the original file structure.
  93.  1. files must be stored contiguously on disc giving "compaction required"
  94.     and "can't extend" errors
  95.  2. there was a maximum number of entries in the free space map giving
  96.     "map full" error
  97.  3. defective sectors could not be mapped out of floppy discs
  98.  
  99. However most file structures which overcome these (eg MS-DOS and UNIX) pay a
  100. heavy penalty in performance for the following reasons. As files may be split
  101. up into several pieces the information on disc allocation is greatly
  102. increased. The structure(s) to keep track of free space and disc allocation
  103. are typically too large to be kept in RAM for hard discs. Therefore the disc
  104. allocation algorithms tend to be be designed to minimise scanning of these
  105. structures, rather than minimising fragmentation. This greatly speeds up the
  106. fragmentation of free space and files, as blocks are claimed and released.
  107. Even if utilities exist to rationalise disc structure an unintelligent
  108. allocation scheme quickly fragments things again. Fragmentation degrades
  109. performance since the parameters of standard disc drives are such that the
  110. time spent seeking between the fragments of a file will dominate the time
  111. spent transferring data unless the fragments are greater than a track length
  112. on average. Therefore if the unit of disc allocation is small fragmentation
  113. soon reduces most fragments to a few units in length giving slow performance,
  114. but if the allocation unit is big enough to give anything close to possible
  115. performance the allocation units are so big that a large part of the disc
  116. space is wasted in rounding up files to allocation units. These points led to
  117. the following additional aims.
  118.  
  119.  4. The disc allocation and free space structure(s) should be small enough to
  120.     be kept in RAM even for large hard discs.
  121.  
  122.  5. The allocation strategies should be intelligent to slow the rate of
  123.     fragmentation and should not produce small fragments.
  124.  
  125.  6. Long term fragmentation will still occur so the allocation strategy should
  126.     have the option of rationalising disc allocation, which should not produce
  127.     a noticeable delay to the user.
  128.  
  129.  
  130. STRUCTURE OVERVIEW
  131. ------------------
  132. The disc structure is made up of the following parts
  133.  
  134. 1. (hard discs only) A boot block containing the defect list and other
  135.    information
  136. 2. A double copied map which allows you to deduce for any cluster (unit of disc
  137. allocation) whether it is allocated and if so to what position in which file
  138. 3. A hierarchical tree of directories
  139. 4. The remaining space is used for (fragments of) files or is unallocated
  140.  
  141. 1 and 3 are the same as for the old file structure (see OldMap document)
  142. except that disc addresses of files and directories are replaced by system
  143. internal numbers (SIN). The SIN includes a file number which can be looked up
  144. in the map to find the allocated disc space.
  145.  
  146.  
  147. NEW MAP STRUCTURE
  148. -----------------
  149. Most of the map is bitstream, with each bit in the map being associated with
  150. the allocation of a fixed number of bytes of disc space. This size (called
  151. the bit size) is always a power of two. The cluster size is the maximum of
  152. the bit size and the sector size. The map is divided into zones by the natural
  153. sector boundaries. Floppies are limited to one zone in the present
  154. implementation. The structure of a zone is as follows
  155.  
  156. start   byte
  157. byte    length  use
  158.  
  159.   0       1     this is a checksum on this zone calculated as below
  160.   1       2     offset in bits to first free space in zone, or 0 if none, with
  161.                 top bit always set
  162.   3       1     this byte when EORed with values for other zones should give FF
  163.   4      60     (only zone 0) the first 32 bytes are a disc record describing
  164.                 the disc, the other 28 bytes are 0, being reserved.
  165.  
  166. The rest of the zone is the bitstream. All entries in the bitstream have the
  167. same format. The start of an entry is an id field (of width given in the disc
  168. record), the end is marked by a 1, and any other bits are set to 0. The
  169. bitstream contains the following three types of object with their respective
  170. interpretation of the id field.
  171.  
  172.      OBJECT TYPE                ID VALUE
  173.  
  174.  a) (fragments of) files        file number (minimum value 2)
  175.  b) unallocated fragments       bit offset of next free fragment in zone or 0
  176.  c) disc defects                always 1
  177.  
  178. When searching for the fragments of a file zone containing the first fragment
  179. can be calculated from
  180.  
  181. zone = file number DIV ids per zone
  182.  
  183. Where ids per zone =  map bits in zone DIV (width of id field + 1)
  184.  
  185. An exception is the file number 2. This is reserved for the structure which is
  186. placed on an empty disc (boot block, map and root directory). Searching for
  187. file number 2 should start at zone = total zones DIV 2. This is to allow the
  188. root directory and map of hard disc to be placed near the middle.
  189.  
  190. The rest of the file's fragments (if any) can be found by searching through
  191. the zones in ascending order, wrapping back to zone 0 if necessary, looking
  192. for fragments with the correct file number. However because of the allocation
  193. strategies given below it is rare for a file to be in more than one piece
  194. unless it has been extended or is very large.
  195.  
  196. The need for an id field places a minimum size on a fragment. For
  197. example possible fragment sizes are 2K, 3K, 4K, 5K ... for an 800K
  198. floppy, or 12K, 13K, 14K, 15K ... for a 20 Mb hard disc with a ten
  199. zone 2.5K map. Thus a compact map representation (down to 1 bit per
  200. cluster if necessary) has been achieved by making it impossible to
  201. represent inefficient allocations, (ie those with small fragments).
  202.  
  203. In order to avoid wasting disc space for small files, when a file or directory
  204. does not use the whole of its allocated fragment and the fragment is too small
  205. too split sharing is allowed. Directories can share fragments with their
  206. sub files and files in the same directory can share a fragment. Sharing is at
  207. sector rather than cluster resolution, saving disc space. This also improves
  208. performance, firstly because head movement is reduced since small files are
  209. closer to each other and their parent directory on average, and secondly the
  210. map does not always need to be modified for small files. 
  211.  
  212. The SIN of a file is a 24 bit value. Bits 0-7 are the sector offset+1 in the
  213. fragment if the file may share a fragment or 0 if not. Bits 8-23 are the file
  214. number.
  215.  
  216.  
  217. ALLOCATION STRATEGIES
  218. ---------------------
  219. Directories are allocated from the middle zone outwards and files
  220. produced by whole file operations are allocated from the zone
  221. containing their parent outwards. For hard discs as well as keeping
  222. files in the same directory close to each other and their parent
  223. directory, it also tends to keep small files near the middle of the
  224. disc and large files further out. Both these reduce head movement.
  225. When choosing disc space on openout it is put at the start of a zone
  226. which balances distance from parent directory with amount of free
  227. space in the zone.
  228.  
  229. As all allocation is indirected through the map it is possible to
  230. re-allocate to reduce fragmentation without having to read or write
  231. directories and a zone compaction routine is available for use by the
  232. allocation routines. This is highly optimised both in the choice of moves (eg
  233. it can spot fragments of the same file that can be joined) and in the
  234. execution of the moves. It builds up lists of moves which it cancels,
  235. combines, joins, splits, collects together in groups to be done together, and
  236. sorts into an order that reduces head movement for the scatter read/write
  237. primitives of the device drivers. Small compactions happen in response to
  238. particular allocation needs and opportunities rather than compacting a whole
  239. zone or disc at once so it not usually apparent to the user.
  240.  
  241. Files produced by whole file operations (eg SAVE) tend to be longer lived
  242. than those produced by partial file operations (eg OPENOUT, GBPB). So if
  243. they cannot be allocated a single extent compaction continues until a free
  244. space of the correct size or data totalling twice the length of the file has
  245. been moved. If compaction fails the file is allocated either a pair of
  246. extents which totals the correct size or a set of adjacent free spaces
  247. (possibly with an extent removed or added to give a better fit). The only
  248. partial file operations that do compaction are open and close, and then only
  249. if a very good opportunity is found. As files produced by whole file ops are
  250. almost always allocated a single extent, and long lived files produced by
  251. partial file ops tend to re-assemble their fragments as compactions happen,
  252. seeking between extents of a file is greatly reduced.
  253.  
  254.  
  255. MINOR DETAILS -------------
  256.  
  257. The checksum on a zone is calculated/checked as below
  258.  
  259. ;entry
  260. ; R0 -> start
  261. ; R1 zone length
  262.  
  263. ;exit
  264. ; LR check byte, Z=0 <=> good
  265.  
  266. NewCheck ROUT
  267.  Push   "R1,R2,LR"
  268.  MOV    LR, #0
  269.  ADDS   R1, R1, R0              ;C=0
  270. loop
  271.  LDR    R2, [R1, #-4] !
  272.  ADCS   LR, LR, R2
  273.  TEQS   R1, R0          ;preserves C
  274.  BNE    loop
  275.  AND    R2, R2, #&FF    ;ignore old sum
  276.  SUB    LR, LR, R2
  277.  EOR    LR, LR, LR, LSR #16
  278.  EOR    LR, LR, LR, LSR #8
  279.  AND    LR, LR, #&FF
  280.  CMPS   R2, LR
  281.  Pull   "R1,R2,PC"
  282.  
  283.  
  284.  
  285.  
  286. The checksum on directories remains the same. But the validation string for a
  287. directory has changed from 'Hugo' to 'Nick'
  288.  
  289.  
  290. ; Directory Start
  291.                 ^ 0
  292. StartMasSeq     # 1
  293. StartName       # 4
  294. DirFirstEntry   # 0
  295.  
  296. ; Old Directory End
  297.                 ^ 0
  298.                 # -1
  299. DirCheckByte    # 0     ;RETRO DEFINITION was reserved
  300.  
  301.                 # -4
  302. EndName         # 0
  303.  
  304.                 # -1
  305. EndMasSeq       # 0
  306.  
  307.                 # -14   ;reserved
  308.  
  309. DirTitleSz      * 19
  310.                 # -DirTitleSz
  311. OldDirTitle     # 0
  312.  
  313.                 # -3
  314. OldDirParent    # 0
  315.  
  316.                 # -NameLen
  317. OldDirName      # 0
  318.  
  319.                 # -1
  320. OldDirLastMark  # 0     ;dummy last entry marker
  321.  
  322. ; New Directory End
  323.                 ^ 0
  324.                 # -1
  325.         ASSERT  DirCheckByte=@
  326.  
  327.                 # -4
  328.         ASSERT  EndName=@
  329.  
  330.                 # -1
  331.         ASSERT  EndMasSeq=@
  332.  
  333.                 # -NameLen
  334. NewDirName      # 0
  335.  
  336.                 # -DirTitleSz
  337. NewDirTitle     # 0
  338.  
  339.                 # -3
  340. NewDirParent    # 0
  341.  
  342.                 # -1    ;reserved
  343.                 # -1    ;reserved
  344.  
  345.                 # -1
  346. NewDirLastMark  # 0     ;dummy last entry marker
  347.  
  348.  
  349.  
  350. ; ================
  351. ; TestDirCheckByte
  352. ; ================
  353.  
  354. ; entry
  355. ;  R3 ind disc add of dir
  356. ;  R5 -> dir start
  357. ;  R6 -> dir end
  358.  
  359. ; exit
  360. ;  LR check byte
  361. ;  Z  clear if matches existing byte
  362.  
  363. TestDirCheckByte
  364.  Push   "R0-R2,R5,R7,LR"
  365.  BL     EndDirEntries                   ;(R3,R5,R6->R0)
  366.  BL     TestDir                         ;(R3->LR,Z)
  367.  ADDEQ  R7, R6, #NewDirLastMark+1       ;dir tail
  368.  ADDNE  R7, R6, #OldDirLastMark+1
  369. 05
  370.  BIC    R1, R0, #3
  371.  MOV    R2, #0
  372. 10                              ;whole words before end of entries
  373.  LDR    LR, [R5],#4
  374.  EOR    R2, LR, R2,ROR #13
  375.  TEQS   R5, R1
  376.  BNE    %BT10
  377. 20                              ;odd bytes before end of entries
  378.  LDRNEB LR, [R5], #1            ;not first pass through loop
  379.  EORNE  R2, LR, R2,ROR #13
  380.  TEQS   R5, R0
  381.  BNE    %BT20
  382.  
  383.  MOV    R5, R7
  384. 30                              ;odd bytes before at start of tail
  385.  TSTS   R5, #3
  386.  LDRNEB LR, [R5],#1
  387.  EORNE  R2, LR, R2, ROR #13
  388.  BNE    %BT30
  389.  
  390.  ASSERT DirCheckByte=-1         ;dont include last word as it contains
  391.  SUB    R1, R6, #4              ;the check byte
  392. 40                              ;whole words in tail
  393.  LDR    LR, [R5],#4
  394.  EOR    R2, LR, R2,ROR #13
  395.  TEQS   R5, R1
  396.  BNE    %BT40
  397.  
  398.  EOR    R2, R2, R2, LSR #16     ;reduce to 8 bits
  399.  EOR    R2, R2, R2, LSR #8
  400.  AND    R2, R2, #&FF
  401.  
  402.  LDRB   LR, [R6,#DirCheckByte]  ;compare with old check byte
  403.  TEQS   R2, LR
  404.  MOV    LR, R2
  405.  
  406.  Pull   "R0-R2,R5,R7,PC"
  407.  
  408.  
  409. ; =============
  410. ; EndDirEntries
  411. ; =============
  412.  
  413. ; Find the end of the list of entries in a dir
  414.  
  415. ; entry
  416. ;  R3 ind disc add of dir
  417. ;  R5 -> dir start
  418. ;  R6 -> dir end
  419.  
  420. ; exit
  421. ;  R0 -> first empty entry
  422.  
  423. EndDirEntries ROUT
  424.  Push   "R2,LR"
  425.  BL     TestDir                 ;(R3->LR,Z)
  426.  ADDEQ  R2, R6, #NewDirLastMark
  427.  ADDNE  R2, R6, #OldDirLastMark
  428.  ADD    R0, R5, #DirFirstEntry
  429.  SUB    R0, R0, #DirEntrySz
  430. 10                              ;loop examining entries
  431.  LDRB   LR, [R0,#DirEntrySz] !
  432.  CMPS   LR, #0                  ;until null entry
  433.  CMPNES R0, R2                  ;or exhausted
  434.  BLO    %BT10
  435.  MOVHI  R0, R2
  436.  Pull   "R2,PC",,^
  437.  
  438.  
  439.