4. The disc allocation and free space structure(s) should be small enough to be kept in RAM even for large hard discs.
5. The allocation strategies should be intelligent to slow the rate of fragmentation and should not produce small fragments.
6. Long term fragmentation will still occur so the allocation strategy should have the option of rationalising disc allocation, which should not produce a noticeable delay to the user.
start byte
byte length use
0 1 this is a checksum on this zone calculated as below 1 2 offset in bits to first free space in zone, or 0 if none, with top bit always set 3 1 this byte when EORed with values for other zones should give FF 4 60 (only zone 0) the first 32 bytes are a disc record describing the disc, the other 28 bytes are 0, being reserved.
The rest of the zone is the bitstream. All entries in the bitstream have the same format. The start of an entry is an id field (of width given in the disc record), the end is marked by a 1, and any other bits are set to 0. The bitstream contains the following three types of object with their respective interpretation of the id field.
OBJECT TYPE ID VALUE
a) (fragments of) files file number (minimum value 2) b) unallocated fragments bit offset of next free fragment in zone or 0 c) disc defects always 1
When searching for the fragments of a file zone containing the first fragment can be calculated from
zone = file number DIV ids per zone
Where ids per zone = map bits in zone DIV (width of id field + 1)
An exception is the file number 2. This is reserved for the structure which is placed on an empty disc (boot block, map and root directory). Searching for file number 2 should start at zone = total zones DIV 2. This is to allow the root directory and map of hard disc to be placed near the middle.
The rest of the file's fragments (if any) can be found by searching through the zones in ascending order, wrapping back to zone 0 if necessary, looking for fragments with the correct file number. However because of the allocation strategies given below it is rare for a file to be in more than one piece unless it has been extended or is very large.
The need for an id field places a minimum size on a fragment. For example possible fragment sizes are 2K, 3K, 4K, 5K ... for an 800K floppy, or 12K, 13K 14K, 15K ... for a 20 Mb hard disc with a ten zone 2.5K map. Thus a compact map representation (down to 1 bit per cluster if necessary) has been achieved by making it impossible to represent inefficient allocations, (ie those with small fragments).
In order to avoid wasting disc space for small files, when a file or directory does not use the whole of its allocated fragment and the fragment is too small to split sharing is allowed. Directories can share fragments with their sub files and files in the same directory can share a fragment. Sharing is at sector rather than cluster resolution, saving disc space. This also improves performance, firstly because head movement is reduced since small files are closer to each other and their parent directory on average, and secondly the map does not always need to be modified for small files.
The SIN of a file is a 24 bit value. Bits 0-7 are the sector offset+1 in the fragment if the file may share a fragment or 0 if not. Bits 8-23 are the file number.
As all allocation is indirected through the map it is possible to re-allocate to reduce fragmentation without having to read or write directories and a zone compaction routine is available for use by the allocation routines. This is highly optimised both in the choice of moves (eg it can spot fragments of the same file that can be joined) and in the execution of the moves. It builds up lists of moves which it cancels, combines, joins, splits, collects together in groups to be done together, and sorts into an order that reduces head movement for the scatter read/write primitives of the device drivers. Small compactions happen in response to particular allocation needs and opportunities rather than compacting a whole zone or disc at once so it not usually apparent to the user.
Files produced by whole file operations (eg SAVE) tend to be longer lived than those produced by partial file operations (eg OPENOUT, GBPB). So if they cannot be allocated a single extent compaction continues until a free space of the correct size or data totalling twice the length of the file has been moved. If compaction fails the file is allocated either a pair of extents which totals the correct size or a set of adjacent free spaces (possibly with an extent removed or added to give a better fit). The only partial file operations that do compaction are open and close, and then only if a very good opportunity is found. As files produced by whole file ops are almost always allocated a single extent, and long lived files produced by partial file ops tend to re-assemble their fragments as compactions happen, seeking between extents of a file is greatly reduced.
;entry
; R0 -> start
; R1 zone length
;exit
; LR check byte, Z=0 <=> good
NewCheck ROUT
Push "R1,R2,LR"
MOV LR, #0
ADDS R1, R1, R0 ;C=0loop
TEQS R1, R0 ;preserves CBNE loop
The checksum on directories remains the same. But the validation string for a directory has changed from 'Hugo' to 'Nick'
; Directory Start
^ 0 StartMasSeq # 1 StartName # 4DirFirstEntry # 0
; Old Directory End
^ 0 # -1 DirCheckByte # 0 ;RETRO DEFINITION was reserved
# -4 EndName # 0
# -1 EndMasSeq # 0
# -14 ;reserved
DirTitleSz * 19 # -DirTitleSz OldDirTitle # 0
# -3OldDirParent # 0
# -NameLen OldDirName # 0
# -1 OldDirLastMark # 0 ;dummy last entry marker
; New Directory End
^ 0 # -1 ASSERT DirCheckByte=@
# -4 ASSERT EndName=@
# -1 ASSERT EndMasSeq=@
# -NameLen NewDirName # 0
# -DirTitleSz NewDirTitle # 0
# -3NewDirParent # 0
# -1 ;reserved # -1 ;reserved
# -1 NewDirLastMark # 0 ;dummy last entry marker
; ================
; TestDirCheckByte
; ================
; entry
; R3 ind disc add of dir
; R5 -> dir start
; R6 -> dir end
; exit
; LR check byte
; Z clear if matches existing byte
TestDirCheckByte
Push "R0-R2,R5,R7,LR"
BL EndDirEntries ;(R3,R5,R6->R0) BL TestDir ;(R3->LR,Z) ADDEQ R7, R6, #NewDirLastMark+1 ;dir tailADDNE R7, R6, #OldDirLastMark+1
10 ;whole words before end of entriesLDR LR, [R5],#4
20 ;odd bytes before end of entries LDRNEB LR, [R5], #1 ;not first pass through loopEORNE R2, LR, R2,ROR #13
MOV R5, R7
30 ;odd bytes before at start of tailTSTS R5, #3
ASSERT DirCheckByte=-1 ;dont include last word as it contains SUB R1, R6, #4 ;the check byte 40 ;whole words in tailLDR LR, [R5],#4
EOR R2, R2, R2, LSR #16 ;reduce to 8 bitsEOR R2, R2, R2, LSR #8
LDRB LR, [R6,#DirCheckByte] ;compare with old check byte
TEQS R2, LR
MOV LR, R2
Pull "R0-R2,R5,R7,PC"
; =============
; EndDirEntries
; =============
; Find the end of the list of entries in a dir
; entry
; R3 ind disc add of dir
; R5 -> dir start
; R6 -> dir end
; exit
; R0 -> first empty entry
EndDirEntries ROUT
Push "R2,LR"
BL TestDir ;(R3->LR,Z)ADDEQ R2, R6, #NewDirLastMark
10 ;loop examining entriesLDRB LR, [R0,#DirEntrySz] !
CMPS LR, #0 ;until null entry CMPNES R0, R2 ;or exhaustedBLO %BT10