Extents





To permit a file to be non-contiguous, each File Control Block allows a file to be in up to ten different sections of the disk, referred to as extents. An extent is defined by the following structure in STRUCTS.FTH.


struct file-extents  \ -- len
  int  ->extent-start      \ location of data (block number)
  int  ->extent-size       \ size of data, (number of blocks)
end-struct

If more than ten extents are needed, another block is used to contain additional extents. These are referred to as indirect extents which are controlled by the following structure in STRUCTS.FTH.


struct indir-extent
  int  ->ind-extent-start
  int  ->ind-logical-end
end-struct

: new-extent-needed     { l_blocks l_fid | -- blocks }
A returned positive number is the number of blocks required.

: need-extent?  \ blocks fid -- t/f
COMPILER: Return TRUE if more space is needed in the file, i.e. it needs to be extended.

: file-extent   { l_ext-no l_fld -- block size }
Return the start and length in blocks of the extent number for the file number.

: fcb-free-extent?      { l_buff | l_fcb l_ext -- t/f }
Buff is the address of a file-extension structure. Return true if the extent it points to is free.

: next-extent?  { l_buff | l_found -- t/f }
Buff is the address of a file-extension structure. Return true if there is a free extent in the FCB it points to.

: end-of-existing-extent        { l_buff | l_fcb l_ext -- end_block }
Buff is the address of a file-extension structure. Return the block number of the block immediately after the end of the previous extent. This is used to determine whether or not the last extent can be increased in size or a new extent is needed.

: add-to-existing-extent?       { l_buff | -- t/f }
Buff is the address of a file-extension structure. Return true if the previous extent can be extended.

: extend-extent { l_buff | l_fcb l_ext -- }
Buff is the address of a file-extension structure. Extend the existing previous extent.

: update-fcb    { l_fcb | -- t/f }
Copy the RAM FCB to the FLD on the disk.

: set-extent    { l_buff | l_ext l_fcb -- }
Buff is the address of a file-extension structure. Use it to set the selected extent in the FCB.




Indirect Extents

BLOCK_SIZE equ INDIR_SIZE       \ -- u
Size of indirect extension block.

INDIR_SIZE INDIR-EXTENT / equ #INDIR-EXTENT     \ -- n
Number of indirect extents per indirect extension block.

INDIR-EXTENT buffer: *ext-buff  \ -- addr
Buffer for handling indirect extents.

: need-indirect-extent  { l_*struct l_fid | l_*ind_block l_oc -- t/f }
Adds a new indirect extent to a file as required. Struct is the address of a file-extension structure.

: get-indirect-extent   { l_fid l_remaining | l_indi l_req l_hd_block -- phys  }
l_remaining is the number of blocks remaining - 1. Return the physical address of the logical block via indirection.

: delete-indir-extent   { l_indirect_blk l_start -- }
Deletes all associated indirect blocks.




Extending a file

: annex-file    { l_blocks l_fid | l_buff l_start l_last_extent -- t/f }
Extends a file by the given number of blocks, returning true for success.