qnx6.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. The QNX6 Filesystem
  2. ===================
  3. The qnx6fs is used by newer QNX operating system versions. (e.g. Neutrino)
  4. It got introduced in QNX 6.4.0 and is used default since 6.4.1.
  5. Option
  6. ======
  7. mmi_fs Mount filesystem as used for example by Audi MMI 3G system
  8. Specification
  9. =============
  10. qnx6fs shares many properties with traditional Unix filesystems. It has the
  11. concepts of blocks, inodes and directories.
  12. On QNX it is possible to create little endian and big endian qnx6 filesystems.
  13. This feature makes it possible to create and use a different endianness fs
  14. for the target (QNX is used on quite a range of embedded systems) plattform
  15. running on a different endianness.
  16. The Linux driver handles endianness transparently. (LE and BE)
  17. Blocks
  18. ------
  19. The space in the device or file is split up into blocks. These are a fixed
  20. size of 512, 1024, 2048 or 4096, which is decided when the filesystem is
  21. created.
  22. Blockpointers are 32bit, so the maximum space that can be addressed is
  23. 2^32 * 4096 bytes or 16TB
  24. The superblocks
  25. ---------------
  26. The superblock contains all global information about the filesystem.
  27. Each qnx6fs got two superblocks, each one having a 64bit serial number.
  28. That serial number is used to identify the "active" superblock.
  29. In write mode with reach new snapshot (after each synchronous write), the
  30. serial of the new master superblock is increased (old superblock serial + 1)
  31. So basically the snapshot functionality is realized by an atomic final
  32. update of the serial number. Before updating that serial, all modifications
  33. are done by copying all modified blocks during that specific write request
  34. (or period) and building up a new (stable) filesystem structure under the
  35. inactive superblock.
  36. Each superblock holds a set of root inodes for the different filesystem
  37. parts. (Inode, Bitmap and Longfilenames)
  38. Each of these root nodes holds information like total size of the stored
  39. data and the addressing levels in that specific tree.
  40. If the level value is 0, up to 16 direct blocks can be addressed by each
  41. node.
  42. Level 1 adds an additional indirect addressing level where each indirect
  43. addressing block holds up to blocksize / 4 bytes pointers to data blocks.
  44. Level 2 adds an additional indirect addressing block level (so, already up
  45. to 16 * 256 * 256 = 1048576 blocks that can be addressed by such a tree).
  46. Unused block pointers are always set to ~0 - regardless of root node,
  47. indirect addressing blocks or inodes.
  48. Data leaves are always on the lowest level. So no data is stored on upper
  49. tree levels.
  50. The first Superblock is located at 0x2000. (0x2000 is the bootblock size)
  51. The Audi MMI 3G first superblock directly starts at byte 0.
  52. Second superblock position can either be calculated from the superblock
  53. information (total number of filesystem blocks) or by taking the highest
  54. device address, zeroing the last 3 bytes and then subtracting 0x1000 from
  55. that address.
  56. 0x1000 is the size reserved for each superblock - regardless of the
  57. blocksize of the filesystem.
  58. Inodes
  59. ------
  60. Each object in the filesystem is represented by an inode. (index node)
  61. The inode structure contains pointers to the filesystem blocks which contain
  62. the data held in the object and all of the metadata about an object except
  63. its longname. (filenames longer than 27 characters)
  64. The metadata about an object includes the permissions, owner, group, flags,
  65. size, number of blocks used, access time, change time and modification time.
  66. Object mode field is POSIX format. (which makes things easier)
  67. There are also pointers to the first 16 blocks, if the object data can be
  68. addressed with 16 direct blocks.
  69. For more than 16 blocks an indirect addressing in form of another tree is
  70. used. (scheme is the same as the one used for the superblock root nodes)
  71. The filesize is stored 64bit. Inode counting starts with 1. (whilst long
  72. filename inodes start with 0)
  73. Directories
  74. -----------
  75. A directory is a filesystem object and has an inode just like a file.
  76. It is a specially formatted file containing records which associate each
  77. name with an inode number.
  78. '.' inode number points to the directory inode
  79. '..' inode number points to the parent directory inode
  80. Eeach filename record additionally got a filename length field.
  81. One special case are long filenames or subdirectory names.
  82. These got set a filename length field of 0xff in the corresponding directory
  83. record plus the longfile inode number also stored in that record.
  84. With that longfilename inode number, the longfilename tree can be walked
  85. starting with the superblock longfilename root node pointers.
  86. Special files
  87. -------------
  88. Symbolic links are also filesystem objects with inodes. They got a specific
  89. bit in the inode mode field identifying them as symbolic link.
  90. The directory entry file inode pointer points to the target file inode.
  91. Hard links got an inode, a directory entry, but a specific mode bit set,
  92. no block pointers and the directory file record pointing to the target file
  93. inode.
  94. Character and block special devices do not exist in QNX as those files
  95. are handled by the QNX kernel/drivers and created in /dev independent of the
  96. underlaying filesystem.
  97. Long filenames
  98. --------------
  99. Long filenames are stored in a separate addressing tree. The staring point
  100. is the longfilename root node in the active superblock.
  101. Each data block (tree leaves) holds one long filename. That filename is
  102. limited to 510 bytes. The first two starting bytes are used as length field
  103. for the actual filename.
  104. If that structure shall fit for all allowed blocksizes, it is clear why there
  105. is a limit of 510 bytes for the actual filename stored.
  106. Bitmap
  107. ------
  108. The qnx6fs filesystem allocation bitmap is stored in a tree under bitmap
  109. root node in the superblock and each bit in the bitmap represents one
  110. filesystem block.
  111. The first block is block 0, which starts 0x1000 after superblock start.
  112. So for a normal qnx6fs 0x3000 (bootblock + superblock) is the physical
  113. address at which block 0 is located.
  114. Bits at the end of the last bitmap block are set to 1, if the device is
  115. smaller than addressing space in the bitmap.
  116. Bitmap system area
  117. ------------------
  118. The bitmap itself is divided into three parts.
  119. First the system area, that is split into two halves.
  120. Then userspace.
  121. The requirement for a static, fixed preallocated system area comes from how
  122. qnx6fs deals with writes.
  123. Each superblock got it's own half of the system area. So superblock #1
  124. always uses blocks from the lower half whilst superblock #2 just writes to
  125. blocks represented by the upper half bitmap system area bits.
  126. Bitmap blocks, Inode blocks and indirect addressing blocks for those two
  127. tree structures are treated as system blocks.
  128. The rational behind that is that a write request can work on a new snapshot
  129. (system area of the inactive - resp. lower serial numbered superblock) while
  130. at the same time there is still a complete stable filesystem structer in the
  131. other half of the system area.
  132. When finished with writing (a sync write is completed, the maximum sync leap
  133. time or a filesystem sync is requested), serial of the previously inactive
  134. superblock atomically is increased and the fs switches over to that - then
  135. stable declared - superblock.
  136. For all data outside the system area, blocks are just copied while writing.