Advertisement
KipIngram

Forth File System Specification

Oct 20th, 2023 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. o The final 16 bytes of each block are reserved for disk management/file system
  2. administration. This space is used as follows:
  3.  
  4. - bytes 4092-4095: next block in file
  5. - bytes 4088-4091: previous block in file
  6. - bytes 4084-4087: parent block
  7. - bytes 4082-4083: content byte count, this block
  8. - bytes 4080-4081: file system status bits
  9.  
  10. o With the exception of the anchor block (described below), bytes 0000-4079 of all
  11. blocks are available for arbitrary user or file system content.
  12.  
  13. o File directories will just be files, with particular content. So, the final 16
  14. bytes of directory blocks will be as described above. The file system status bits
  15. noted above will identify each block as user data, directory data, internal b+tree
  16. node, etc. etc.
  17.  
  18. o New items will be added to directory blocks beginning at the highest free address
  19. and working down. Each directory entry will be laid out as follows:
  20.  
  21. - Four bytes specifying a block number, which will be
  22. - The first content block of the file, or
  23. - The root of a b+tree mapping the file
  24. The block's file system status bits will specify which of these options is
  25. in play.
  26. - Five bytes specifying the file's total size in bytes
  27. - Three bytes of flags/status.
  28. - Four bytes reserved for future use.
  29. - A Forth counted string specifying the file's name
  30. - Pad bytes to 32-bit align the following entry.
  31.  
  32. Assuming the average counted name string requires eight bytes, a single block's
  33. usable space will hold 170 directory entries - most directories will need no more
  34. than a single block.
  35.  
  36. o The unspecified flags/status bits can specify permissions, etc.
  37.  
  38. o Directory entries will be packed, with each new item being added just before the
  39. previously added item. The content count word will allow us to determine where
  40. these items begin in the block, and we can then search them linearly to find a
  41. name match. If more entries than one block can hold are needed, blocks can be
  42. added to the directory "file" using the administrative fields at the end of the
  43. block.
  44.  
  45. o The root of the file system (path /) will begin at the "anchor block" - the only
  46. block in the system that must be at a pre-established block number. The anchor
  47. block will have the usual administrative fields at the end. Beginning with byte
  48. offset 0000, further content will be arranged as follows:
  49.  
  50. - Bytes 0000-0007: "Magic number" so we can identify this drive as a valid
  51. drive.
  52. - Bytes 0008-0011: First block in the block allocation pool
  53. - Bytes 0012-0015: First block after the block allocation pool
  54. - Bytes 0016-0019: First block on the "free block list"
  55. - Bytes 0020-0023: First block of the "frontier" (remaining virgin pool)
  56. - Bytes 0024-0027: Reserved for future use
  57. - Bytes 0028-0031: A number N specifying a bootable image count
  58. - N 8-byte fields, each as follows:
  59. - 4 bytes specifying a "first block in image"
  60. - 4 bytes specifying a "last block in image"
  61. - First directory entries of the / directory (filling down from the top)
  62.  
  63. The fields above are sufficient to allow the operation of a simple fixed size block
  64. allocator, and will also allow us to carve off the high end of the disk for custom
  65. management, outside of the file system. Note that the "content byte count" used
  66. in the anchor block will *not* include the special data in bytes 0000-0023, or the
  67. bytes used by bootable image ranges.
  68.  
  69. Note that directories other than / will have an entry with name ".." identifying
  70. the parent directory.
  71.  
  72. o The structures defined above will allow us to create arbitrary file hierarchies,
  73. find files given a path spec, and seek through files to any content offset.
  74.  
  75. o Each file can (later) have a b+tree associated with it, which will let us do
  76. in-file seeks at an accelerated pace. Each file block's "parent" field will be
  77. used as an access point to this b+tree, and blocks within the b+tree will be
  78. linked to siblings with the prev and next fields and to their parents with the
  79. parent field. The b+tree features are optional and not required for initial use.
  80.  
  81. o The "reserved" field in directory entries has no immediate purpose, but ultimately
  82. could be used to supply per-file "auxiliary information." For example, this might
  83. include a schema for database tables, an index for rapidly searching directories
  84. for specific file names, etc. The four bytes would designate a block where this
  85. additional information would be found.
  86.  
  87. o Internal b+tree node records will be eight bytes long and will consist of
  88. - The block number of a child block, and
  89. - The number of 256-byte "pages" of content "to the left"
  90. It will be possible to do a binary search on such an internal node to find
  91. the right child to descend to when seeking a particular offset within the
  92. file. 510 such records will fit in the usable portion of a block.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement