1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=================== 4*4882a593SmuzhiyunThe QNX6 Filesystem 5*4882a593Smuzhiyun=================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThe qnx6fs is used by newer QNX operating system versions. (e.g. Neutrino) 8*4882a593SmuzhiyunIt got introduced in QNX 6.4.0 and is used default since 6.4.1. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunOption 11*4882a593Smuzhiyun====== 12*4882a593Smuzhiyun 13*4882a593Smuzhiyunmmi_fs Mount filesystem as used for example by Audi MMI 3G system 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunSpecification 16*4882a593Smuzhiyun============= 17*4882a593Smuzhiyun 18*4882a593Smuzhiyunqnx6fs shares many properties with traditional Unix filesystems. It has the 19*4882a593Smuzhiyunconcepts of blocks, inodes and directories. 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunOn QNX it is possible to create little endian and big endian qnx6 filesystems. 22*4882a593SmuzhiyunThis feature makes it possible to create and use a different endianness fs 23*4882a593Smuzhiyunfor the target (QNX is used on quite a range of embedded systems) platform 24*4882a593Smuzhiyunrunning on a different endianness. 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunThe Linux driver handles endianness transparently. (LE and BE) 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunBlocks 29*4882a593Smuzhiyun------ 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunThe space in the device or file is split up into blocks. These are a fixed 32*4882a593Smuzhiyunsize of 512, 1024, 2048 or 4096, which is decided when the filesystem is 33*4882a593Smuzhiyuncreated. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunBlockpointers are 32bit, so the maximum space that can be addressed is 36*4882a593Smuzhiyun2^32 * 4096 bytes or 16TB 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunThe superblocks 39*4882a593Smuzhiyun--------------- 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunThe superblock contains all global information about the filesystem. 42*4882a593SmuzhiyunEach qnx6fs got two superblocks, each one having a 64bit serial number. 43*4882a593SmuzhiyunThat serial number is used to identify the "active" superblock. 44*4882a593SmuzhiyunIn write mode with reach new snapshot (after each synchronous write), the 45*4882a593Smuzhiyunserial of the new master superblock is increased (old superblock serial + 1) 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunSo basically the snapshot functionality is realized by an atomic final 48*4882a593Smuzhiyunupdate of the serial number. Before updating that serial, all modifications 49*4882a593Smuzhiyunare done by copying all modified blocks during that specific write request 50*4882a593Smuzhiyun(or period) and building up a new (stable) filesystem structure under the 51*4882a593Smuzhiyuninactive superblock. 52*4882a593Smuzhiyun 53*4882a593SmuzhiyunEach superblock holds a set of root inodes for the different filesystem 54*4882a593Smuzhiyunparts. (Inode, Bitmap and Longfilenames) 55*4882a593SmuzhiyunEach of these root nodes holds information like total size of the stored 56*4882a593Smuzhiyundata and the addressing levels in that specific tree. 57*4882a593SmuzhiyunIf the level value is 0, up to 16 direct blocks can be addressed by each 58*4882a593Smuzhiyunnode. 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunLevel 1 adds an additional indirect addressing level where each indirect 61*4882a593Smuzhiyunaddressing block holds up to blocksize / 4 bytes pointers to data blocks. 62*4882a593SmuzhiyunLevel 2 adds an additional indirect addressing block level (so, already up 63*4882a593Smuzhiyunto 16 * 256 * 256 = 1048576 blocks that can be addressed by such a tree). 64*4882a593Smuzhiyun 65*4882a593SmuzhiyunUnused block pointers are always set to ~0 - regardless of root node, 66*4882a593Smuzhiyunindirect addressing blocks or inodes. 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunData leaves are always on the lowest level. So no data is stored on upper 69*4882a593Smuzhiyuntree levels. 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunThe first Superblock is located at 0x2000. (0x2000 is the bootblock size) 72*4882a593SmuzhiyunThe Audi MMI 3G first superblock directly starts at byte 0. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunSecond superblock position can either be calculated from the superblock 75*4882a593Smuzhiyuninformation (total number of filesystem blocks) or by taking the highest 76*4882a593Smuzhiyundevice address, zeroing the last 3 bytes and then subtracting 0x1000 from 77*4882a593Smuzhiyunthat address. 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun0x1000 is the size reserved for each superblock - regardless of the 80*4882a593Smuzhiyunblocksize of the filesystem. 81*4882a593Smuzhiyun 82*4882a593SmuzhiyunInodes 83*4882a593Smuzhiyun------ 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunEach object in the filesystem is represented by an inode. (index node) 86*4882a593SmuzhiyunThe inode structure contains pointers to the filesystem blocks which contain 87*4882a593Smuzhiyunthe data held in the object and all of the metadata about an object except 88*4882a593Smuzhiyunits longname. (filenames longer than 27 characters) 89*4882a593SmuzhiyunThe metadata about an object includes the permissions, owner, group, flags, 90*4882a593Smuzhiyunsize, number of blocks used, access time, change time and modification time. 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunObject mode field is POSIX format. (which makes things easier) 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunThere are also pointers to the first 16 blocks, if the object data can be 95*4882a593Smuzhiyunaddressed with 16 direct blocks. 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunFor more than 16 blocks an indirect addressing in form of another tree is 98*4882a593Smuzhiyunused. (scheme is the same as the one used for the superblock root nodes) 99*4882a593Smuzhiyun 100*4882a593SmuzhiyunThe filesize is stored 64bit. Inode counting starts with 1. (while long 101*4882a593Smuzhiyunfilename inodes start with 0) 102*4882a593Smuzhiyun 103*4882a593SmuzhiyunDirectories 104*4882a593Smuzhiyun----------- 105*4882a593Smuzhiyun 106*4882a593SmuzhiyunA directory is a filesystem object and has an inode just like a file. 107*4882a593SmuzhiyunIt is a specially formatted file containing records which associate each 108*4882a593Smuzhiyunname with an inode number. 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun'.' inode number points to the directory inode 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun'..' inode number points to the parent directory inode 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunEeach filename record additionally got a filename length field. 115*4882a593Smuzhiyun 116*4882a593SmuzhiyunOne special case are long filenames or subdirectory names. 117*4882a593Smuzhiyun 118*4882a593SmuzhiyunThese got set a filename length field of 0xff in the corresponding directory 119*4882a593Smuzhiyunrecord plus the longfile inode number also stored in that record. 120*4882a593Smuzhiyun 121*4882a593SmuzhiyunWith that longfilename inode number, the longfilename tree can be walked 122*4882a593Smuzhiyunstarting with the superblock longfilename root node pointers. 123*4882a593Smuzhiyun 124*4882a593SmuzhiyunSpecial files 125*4882a593Smuzhiyun------------- 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunSymbolic links are also filesystem objects with inodes. They got a specific 128*4882a593Smuzhiyunbit in the inode mode field identifying them as symbolic link. 129*4882a593Smuzhiyun 130*4882a593SmuzhiyunThe directory entry file inode pointer points to the target file inode. 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunHard links got an inode, a directory entry, but a specific mode bit set, 133*4882a593Smuzhiyunno block pointers and the directory file record pointing to the target file 134*4882a593Smuzhiyuninode. 135*4882a593Smuzhiyun 136*4882a593SmuzhiyunCharacter and block special devices do not exist in QNX as those files 137*4882a593Smuzhiyunare handled by the QNX kernel/drivers and created in /dev independent of the 138*4882a593Smuzhiyununderlaying filesystem. 139*4882a593Smuzhiyun 140*4882a593SmuzhiyunLong filenames 141*4882a593Smuzhiyun-------------- 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunLong filenames are stored in a separate addressing tree. The staring point 144*4882a593Smuzhiyunis the longfilename root node in the active superblock. 145*4882a593Smuzhiyun 146*4882a593SmuzhiyunEach data block (tree leaves) holds one long filename. That filename is 147*4882a593Smuzhiyunlimited to 510 bytes. The first two starting bytes are used as length field 148*4882a593Smuzhiyunfor the actual filename. 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunIf that structure shall fit for all allowed blocksizes, it is clear why there 151*4882a593Smuzhiyunis a limit of 510 bytes for the actual filename stored. 152*4882a593Smuzhiyun 153*4882a593SmuzhiyunBitmap 154*4882a593Smuzhiyun------ 155*4882a593Smuzhiyun 156*4882a593SmuzhiyunThe qnx6fs filesystem allocation bitmap is stored in a tree under bitmap 157*4882a593Smuzhiyunroot node in the superblock and each bit in the bitmap represents one 158*4882a593Smuzhiyunfilesystem block. 159*4882a593Smuzhiyun 160*4882a593SmuzhiyunThe first block is block 0, which starts 0x1000 after superblock start. 161*4882a593SmuzhiyunSo for a normal qnx6fs 0x3000 (bootblock + superblock) is the physical 162*4882a593Smuzhiyunaddress at which block 0 is located. 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunBits at the end of the last bitmap block are set to 1, if the device is 165*4882a593Smuzhiyunsmaller than addressing space in the bitmap. 166*4882a593Smuzhiyun 167*4882a593SmuzhiyunBitmap system area 168*4882a593Smuzhiyun------------------ 169*4882a593Smuzhiyun 170*4882a593SmuzhiyunThe bitmap itself is divided into three parts. 171*4882a593Smuzhiyun 172*4882a593SmuzhiyunFirst the system area, that is split into two halves. 173*4882a593Smuzhiyun 174*4882a593SmuzhiyunThen userspace. 175*4882a593Smuzhiyun 176*4882a593SmuzhiyunThe requirement for a static, fixed preallocated system area comes from how 177*4882a593Smuzhiyunqnx6fs deals with writes. 178*4882a593Smuzhiyun 179*4882a593SmuzhiyunEach superblock got it's own half of the system area. So superblock #1 180*4882a593Smuzhiyunalways uses blocks from the lower half while superblock #2 just writes to 181*4882a593Smuzhiyunblocks represented by the upper half bitmap system area bits. 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunBitmap blocks, Inode blocks and indirect addressing blocks for those two 184*4882a593Smuzhiyuntree structures are treated as system blocks. 185*4882a593Smuzhiyun 186*4882a593SmuzhiyunThe rational behind that is that a write request can work on a new snapshot 187*4882a593Smuzhiyun(system area of the inactive - resp. lower serial numbered superblock) while 188*4882a593Smuzhiyunat the same time there is still a complete stable filesystem structure in the 189*4882a593Smuzhiyunother half of the system area. 190*4882a593Smuzhiyun 191*4882a593SmuzhiyunWhen finished with writing (a sync write is completed, the maximum sync leap 192*4882a593Smuzhiyuntime or a filesystem sync is requested), serial of the previously inactive 193*4882a593Smuzhiyunsuperblock atomically is increased and the fs switches over to that - then 194*4882a593Smuzhiyunstable declared - superblock. 195*4882a593Smuzhiyun 196*4882a593SmuzhiyunFor all data outside the system area, blocks are just copied while writing. 197