2 * QNX6 file system, Linux implementation.
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
12 #include <linux/buffer_head.h>
13 #include <linux/slab.h>
14 #include <linux/crc32.h>
17 static void qnx6_mmi_copy_sb(struct qnx6_super_block
*qsb
,
18 struct qnx6_mmi_super_block
*sb
)
20 qsb
->sb_magic
= sb
->sb_magic
;
21 qsb
->sb_checksum
= sb
->sb_checksum
;
22 qsb
->sb_serial
= sb
->sb_serial
;
23 qsb
->sb_blocksize
= sb
->sb_blocksize
;
24 qsb
->sb_num_inodes
= sb
->sb_num_inodes
;
25 qsb
->sb_free_inodes
= sb
->sb_free_inodes
;
26 qsb
->sb_num_blocks
= sb
->sb_num_blocks
;
27 qsb
->sb_free_blocks
= sb
->sb_free_blocks
;
29 /* the rest of the superblock is the same */
30 memcpy(&qsb
->Inode
, &sb
->Inode
, sizeof(sb
->Inode
));
31 memcpy(&qsb
->Bitmap
, &sb
->Bitmap
, sizeof(sb
->Bitmap
));
32 memcpy(&qsb
->Longfile
, &sb
->Longfile
, sizeof(sb
->Longfile
));
35 struct qnx6_super_block
*qnx6_mmi_fill_super(struct super_block
*s
, int silent
)
37 struct buffer_head
*bh1
, *bh2
= NULL
;
38 struct qnx6_mmi_super_block
*sb1
, *sb2
;
39 struct qnx6_super_block
*qsb
= NULL
;
40 struct qnx6_sb_info
*sbi
;
43 /* Check the superblock signatures
44 start with the first superblock */
47 pr_err("Unable to read first mmi superblock\n");
50 sb1
= (struct qnx6_mmi_super_block
*)bh1
->b_data
;
52 if (fs32_to_cpu(sbi
, sb1
->sb_magic
) != QNX6_SUPER_MAGIC
) {
54 pr_err("wrong signature (magic) in superblock #1.\n");
59 /* checksum check - start at byte 8 and end at byte 512 */
60 if (fs32_to_cpu(sbi
, sb1
->sb_checksum
) !=
61 crc32_be(0, (char *)(bh1
->b_data
+ 8), 504)) {
62 pr_err("superblock #1 checksum error\n");
66 /* calculate second superblock blocknumber */
67 offset
= fs32_to_cpu(sbi
, sb1
->sb_num_blocks
) + QNX6_SUPERBLOCK_AREA
/
68 fs32_to_cpu(sbi
, sb1
->sb_blocksize
);
70 /* set new blocksize */
71 if (!sb_set_blocksize(s
, fs32_to_cpu(sbi
, sb1
->sb_blocksize
))) {
72 pr_err("unable to set blocksize\n");
75 /* blocksize invalidates bh - pull it back in */
80 sb1
= (struct qnx6_mmi_super_block
*)bh1
->b_data
;
82 /* read second superblock */
83 bh2
= sb_bread(s
, offset
);
85 pr_err("unable to read the second superblock\n");
88 sb2
= (struct qnx6_mmi_super_block
*)bh2
->b_data
;
89 if (fs32_to_cpu(sbi
, sb2
->sb_magic
) != QNX6_SUPER_MAGIC
) {
91 pr_err("wrong signature (magic) in superblock #2.\n");
95 /* checksum check - start at byte 8 and end at byte 512 */
96 if (fs32_to_cpu(sbi
, sb2
->sb_checksum
)
97 != crc32_be(0, (char *)(bh2
->b_data
+ 8), 504)) {
98 pr_err("superblock #1 checksum error\n");
102 qsb
= kmalloc(sizeof(*qsb
), GFP_KERNEL
);
104 pr_err("unable to allocate memory.\n");
108 if (fs64_to_cpu(sbi
, sb1
->sb_serial
) >
109 fs64_to_cpu(sbi
, sb2
->sb_serial
)) {
110 /* superblock #1 active */
111 qnx6_mmi_copy_sb(qsb
, sb1
);
112 #ifdef CONFIG_QNX6FS_DEBUG
113 qnx6_superblock_debug(qsb
, s
);
115 memcpy(bh1
->b_data
, qsb
, sizeof(struct qnx6_super_block
));
118 sbi
->sb
= (struct qnx6_super_block
*)bh1
->b_data
;
120 pr_info("superblock #1 active\n");
122 /* superblock #2 active */
123 qnx6_mmi_copy_sb(qsb
, sb2
);
124 #ifdef CONFIG_QNX6FS_DEBUG
125 qnx6_superblock_debug(qsb
, s
);
127 memcpy(bh2
->b_data
, qsb
, sizeof(struct qnx6_super_block
));
130 sbi
->sb
= (struct qnx6_super_block
*)bh2
->b_data
;
132 pr_info("superblock #2 active\n");
136 /* offset for mmi_fs is just SUPERBLOCK_AREA bytes */
137 sbi
->s_blks_off
= QNX6_SUPERBLOCK_AREA
/ s
->s_blocksize
;