qnx6.rst 7.2 KB

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