Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * QNX6 file system, Linux implementation.
4 *
5 * Version : 1.0.0
6 *
7 * History :
8 *
9 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
10 * 16-02-2012 pagemap extension by Al Viro
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/slab.h>
17#include <linux/highuid.h>
18#include <linux/pagemap.h>
19#include <linux/buffer_head.h>
20#include <linux/writeback.h>
21#include <linux/statfs.h>
22#include <linux/parser.h>
23#include <linux/seq_file.h>
24#include <linux/mount.h>
25#include <linux/crc32.h>
26#include <linux/mpage.h>
27#include "qnx6.h"
28
29static const struct super_operations qnx6_sops;
30
31static void qnx6_put_super(struct super_block *sb);
32static struct inode *qnx6_alloc_inode(struct super_block *sb);
33static void qnx6_free_inode(struct inode *inode);
34static int qnx6_remount(struct super_block *sb, int *flags, char *data);
35static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf);
36static int qnx6_show_options(struct seq_file *seq, struct dentry *root);
37
38static const struct super_operations qnx6_sops = {
39 .alloc_inode = qnx6_alloc_inode,
40 .free_inode = qnx6_free_inode,
41 .put_super = qnx6_put_super,
42 .statfs = qnx6_statfs,
43 .remount_fs = qnx6_remount,
44 .show_options = qnx6_show_options,
45};
46
47static int qnx6_show_options(struct seq_file *seq, struct dentry *root)
48{
49 struct super_block *sb = root->d_sb;
50 struct qnx6_sb_info *sbi = QNX6_SB(sb);
51
52 if (sbi->s_mount_opt & QNX6_MOUNT_MMI_FS)
53 seq_puts(seq, ",mmi_fs");
54 return 0;
55}
56
57static int qnx6_remount(struct super_block *sb, int *flags, char *data)
58{
59 sync_filesystem(sb);
60 *flags |= SB_RDONLY;
61 return 0;
62}
63
64static unsigned qnx6_get_devblock(struct super_block *sb, __fs32 block)
65{
66 struct qnx6_sb_info *sbi = QNX6_SB(sb);
67 return fs32_to_cpu(sbi, block) + sbi->s_blks_off;
68}
69
70static unsigned qnx6_block_map(struct inode *inode, unsigned iblock);
71
72static int qnx6_get_block(struct inode *inode, sector_t iblock,
73 struct buffer_head *bh, int create)
74{
75 unsigned phys;
76
77 pr_debug("qnx6_get_block inode=[%ld] iblock=[%ld]\n",
78 inode->i_ino, (unsigned long)iblock);
79
80 phys = qnx6_block_map(inode, iblock);
81 if (phys) {
82 /* logical block is before EOF */
83 map_bh(bh, inode->i_sb, phys);
84 }
85 return 0;
86}
87
88static int qnx6_check_blockptr(__fs32 ptr)
89{
90 if (ptr == ~(__fs32)0) {
91 pr_err("hit unused blockpointer.\n");
92 return 0;
93 }
94 return 1;
95}
96
97static int qnx6_read_folio(struct file *file, struct folio *folio)
98{
99 return mpage_read_folio(folio, qnx6_get_block);
100}
101
102static void qnx6_readahead(struct readahead_control *rac)
103{
104 mpage_readahead(rac, qnx6_get_block);
105}
106
107/*
108 * returns the block number for the no-th element in the tree
109 * inodebits requred as there are multiple inodes in one inode block
110 */
111static unsigned qnx6_block_map(struct inode *inode, unsigned no)
112{
113 struct super_block *s = inode->i_sb;
114 struct qnx6_sb_info *sbi = QNX6_SB(s);
115 struct qnx6_inode_info *ei = QNX6_I(inode);
116 unsigned block = 0;
117 struct buffer_head *bh;
118 __fs32 ptr;
119 int levelptr;
120 int ptrbits = sbi->s_ptrbits;
121 int bitdelta;
122 u32 mask = (1 << ptrbits) - 1;
123 int depth = ei->di_filelevels;
124 int i;
125
126 bitdelta = ptrbits * depth;
127 levelptr = no >> bitdelta;
128
129 if (levelptr > QNX6_NO_DIRECT_POINTERS - 1) {
130 pr_err("Requested file block number (%u) too big.", no);
131 return 0;
132 }
133
134 block = qnx6_get_devblock(s, ei->di_block_ptr[levelptr]);
135
136 for (i = 0; i < depth; i++) {
137 bh = sb_bread(s, block);
138 if (!bh) {
139 pr_err("Error reading block (%u)\n", block);
140 return 0;
141 }
142 bitdelta -= ptrbits;
143 levelptr = (no >> bitdelta) & mask;
144 ptr = ((__fs32 *)bh->b_data)[levelptr];
145
146 if (!qnx6_check_blockptr(ptr))
147 return 0;
148
149 block = qnx6_get_devblock(s, ptr);
150 brelse(bh);
151 }
152 return block;
153}
154
155static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf)
156{
157 struct super_block *sb = dentry->d_sb;
158 struct qnx6_sb_info *sbi = QNX6_SB(sb);
159 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
160
161 buf->f_type = sb->s_magic;
162 buf->f_bsize = sb->s_blocksize;
163 buf->f_blocks = fs32_to_cpu(sbi, sbi->sb->sb_num_blocks);
164 buf->f_bfree = fs32_to_cpu(sbi, sbi->sb->sb_free_blocks);
165 buf->f_files = fs32_to_cpu(sbi, sbi->sb->sb_num_inodes);
166 buf->f_ffree = fs32_to_cpu(sbi, sbi->sb->sb_free_inodes);
167 buf->f_bavail = buf->f_bfree;
168 buf->f_namelen = QNX6_LONG_NAME_MAX;
169 buf->f_fsid = u64_to_fsid(id);
170
171 return 0;
172}
173
174/*
175 * Check the root directory of the filesystem to make sure
176 * it really _is_ a qnx6 filesystem, and to check the size
177 * of the directory entry.
178 */
179static const char *qnx6_checkroot(struct super_block *s)
180{
181 static char match_root[2][3] = {".\0\0", "..\0"};
182 int i, error = 0;
183 struct qnx6_dir_entry *dir_entry;
184 struct inode *root = d_inode(s->s_root);
185 struct address_space *mapping = root->i_mapping;
186 struct page *page = read_mapping_page(mapping, 0, NULL);
187 if (IS_ERR(page))
188 return "error reading root directory";
189 kmap(page);
190 dir_entry = page_address(page);
191 for (i = 0; i < 2; i++) {
192 /* maximum 3 bytes - due to match_root limitation */
193 if (strncmp(dir_entry[i].de_fname, match_root[i], 3))
194 error = 1;
195 }
196 qnx6_put_page(page);
197 if (error)
198 return "error reading root directory.";
199 return NULL;
200}
201
202#ifdef CONFIG_QNX6FS_DEBUG
203void qnx6_superblock_debug(struct qnx6_super_block *sb, struct super_block *s)
204{
205 struct qnx6_sb_info *sbi = QNX6_SB(s);
206
207 pr_debug("magic: %08x\n", fs32_to_cpu(sbi, sb->sb_magic));
208 pr_debug("checksum: %08x\n", fs32_to_cpu(sbi, sb->sb_checksum));
209 pr_debug("serial: %llx\n", fs64_to_cpu(sbi, sb->sb_serial));
210 pr_debug("flags: %08x\n", fs32_to_cpu(sbi, sb->sb_flags));
211 pr_debug("blocksize: %08x\n", fs32_to_cpu(sbi, sb->sb_blocksize));
212 pr_debug("num_inodes: %08x\n", fs32_to_cpu(sbi, sb->sb_num_inodes));
213 pr_debug("free_inodes: %08x\n", fs32_to_cpu(sbi, sb->sb_free_inodes));
214 pr_debug("num_blocks: %08x\n", fs32_to_cpu(sbi, sb->sb_num_blocks));
215 pr_debug("free_blocks: %08x\n", fs32_to_cpu(sbi, sb->sb_free_blocks));
216 pr_debug("inode_levels: %02x\n", sb->Inode.levels);
217}
218#endif
219
220enum {
221 Opt_mmifs,
222 Opt_err
223};
224
225static const match_table_t tokens = {
226 {Opt_mmifs, "mmi_fs"},
227 {Opt_err, NULL}
228};
229
230static int qnx6_parse_options(char *options, struct super_block *sb)
231{
232 char *p;
233 struct qnx6_sb_info *sbi = QNX6_SB(sb);
234 substring_t args[MAX_OPT_ARGS];
235
236 if (!options)
237 return 1;
238
239 while ((p = strsep(&options, ",")) != NULL) {
240 int token;
241 if (!*p)
242 continue;
243
244 token = match_token(p, tokens, args);
245 switch (token) {
246 case Opt_mmifs:
247 set_opt(sbi->s_mount_opt, MMI_FS);
248 break;
249 default:
250 return 0;
251 }
252 }
253 return 1;
254}
255
256static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
257 int offset, int silent)
258{
259 struct qnx6_sb_info *sbi = QNX6_SB(s);
260 struct buffer_head *bh;
261 struct qnx6_super_block *sb;
262
263 /* Check the superblock signatures
264 start with the first superblock */
265 bh = sb_bread(s, offset);
266 if (!bh) {
267 pr_err("unable to read the first superblock\n");
268 return NULL;
269 }
270 sb = (struct qnx6_super_block *)bh->b_data;
271 if (fs32_to_cpu(sbi, sb->sb_magic) != QNX6_SUPER_MAGIC) {
272 sbi->s_bytesex = BYTESEX_BE;
273 if (fs32_to_cpu(sbi, sb->sb_magic) == QNX6_SUPER_MAGIC) {
274 /* we got a big endian fs */
275 pr_debug("fs got different endianness.\n");
276 return bh;
277 } else
278 sbi->s_bytesex = BYTESEX_LE;
279 if (!silent) {
280 if (offset == 0) {
281 pr_err("wrong signature (magic) in superblock #1.\n");
282 } else {
283 pr_info("wrong signature (magic) at position (0x%lx) - will try alternative position (0x0000).\n",
284 offset * s->s_blocksize);
285 }
286 }
287 brelse(bh);
288 return NULL;
289 }
290 return bh;
291}
292
293static struct inode *qnx6_private_inode(struct super_block *s,
294 struct qnx6_root_node *p);
295
296static int qnx6_fill_super(struct super_block *s, void *data, int silent)
297{
298 struct buffer_head *bh1 = NULL, *bh2 = NULL;
299 struct qnx6_super_block *sb1 = NULL, *sb2 = NULL;
300 struct qnx6_sb_info *sbi;
301 struct inode *root;
302 const char *errmsg;
303 struct qnx6_sb_info *qs;
304 int ret = -EINVAL;
305 u64 offset;
306 int bootblock_offset = QNX6_BOOTBLOCK_SIZE;
307
308 qs = kzalloc(sizeof(struct qnx6_sb_info), GFP_KERNEL);
309 if (!qs)
310 return -ENOMEM;
311 s->s_fs_info = qs;
312
313 /* Superblock always is 512 Byte long */
314 if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
315 pr_err("unable to set blocksize\n");
316 goto outnobh;
317 }
318
319 /* parse the mount-options */
320 if (!qnx6_parse_options((char *) data, s)) {
321 pr_err("invalid mount options.\n");
322 goto outnobh;
323 }
324 if (test_opt(s, MMI_FS)) {
325 sb1 = qnx6_mmi_fill_super(s, silent);
326 if (sb1)
327 goto mmi_success;
328 else
329 goto outnobh;
330 }
331 sbi = QNX6_SB(s);
332 sbi->s_bytesex = BYTESEX_LE;
333 /* Check the superblock signatures
334 start with the first superblock */
335 bh1 = qnx6_check_first_superblock(s,
336 bootblock_offset / QNX6_SUPERBLOCK_SIZE, silent);
337 if (!bh1) {
338 /* try again without bootblock offset */
339 bh1 = qnx6_check_first_superblock(s, 0, silent);
340 if (!bh1) {
341 pr_err("unable to read the first superblock\n");
342 goto outnobh;
343 }
344 /* seems that no bootblock at partition start */
345 bootblock_offset = 0;
346 }
347 sb1 = (struct qnx6_super_block *)bh1->b_data;
348
349#ifdef CONFIG_QNX6FS_DEBUG
350 qnx6_superblock_debug(sb1, s);
351#endif
352
353 /* checksum check - start at byte 8 and end at byte 512 */
354 if (fs32_to_cpu(sbi, sb1->sb_checksum) !=
355 crc32_be(0, (char *)(bh1->b_data + 8), 504)) {
356 pr_err("superblock #1 checksum error\n");
357 goto out;
358 }
359
360 /* set new blocksize */
361 if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
362 pr_err("unable to set blocksize\n");
363 goto out;
364 }
365 /* blocksize invalidates bh - pull it back in */
366 brelse(bh1);
367 bh1 = sb_bread(s, bootblock_offset >> s->s_blocksize_bits);
368 if (!bh1)
369 goto outnobh;
370 sb1 = (struct qnx6_super_block *)bh1->b_data;
371
372 /* calculate second superblock blocknumber */
373 offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) +
374 (bootblock_offset >> s->s_blocksize_bits) +
375 (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
376
377 /* set bootblock offset */
378 sbi->s_blks_off = (bootblock_offset >> s->s_blocksize_bits) +
379 (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
380
381 /* next the second superblock */
382 bh2 = sb_bread(s, offset);
383 if (!bh2) {
384 pr_err("unable to read the second superblock\n");
385 goto out;
386 }
387 sb2 = (struct qnx6_super_block *)bh2->b_data;
388 if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) {
389 if (!silent)
390 pr_err("wrong signature (magic) in superblock #2.\n");
391 goto out;
392 }
393
394 /* checksum check - start at byte 8 and end at byte 512 */
395 if (fs32_to_cpu(sbi, sb2->sb_checksum) !=
396 crc32_be(0, (char *)(bh2->b_data + 8), 504)) {
397 pr_err("superblock #2 checksum error\n");
398 goto out;
399 }
400
401 if (fs64_to_cpu(sbi, sb1->sb_serial) >=
402 fs64_to_cpu(sbi, sb2->sb_serial)) {
403 /* superblock #1 active */
404 sbi->sb_buf = bh1;
405 sbi->sb = (struct qnx6_super_block *)bh1->b_data;
406 brelse(bh2);
407 pr_info("superblock #1 active\n");
408 } else {
409 /* superblock #2 active */
410 sbi->sb_buf = bh2;
411 sbi->sb = (struct qnx6_super_block *)bh2->b_data;
412 brelse(bh1);
413 pr_info("superblock #2 active\n");
414 }
415mmi_success:
416 /* sanity check - limit maximum indirect pointer levels */
417 if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
418 pr_err("too many inode levels (max %i, sb %i)\n",
419 QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
420 goto out;
421 }
422 if (sb1->Longfile.levels > QNX6_PTR_MAX_LEVELS) {
423 pr_err("too many longfilename levels (max %i, sb %i)\n",
424 QNX6_PTR_MAX_LEVELS, sb1->Longfile.levels);
425 goto out;
426 }
427 s->s_op = &qnx6_sops;
428 s->s_magic = QNX6_SUPER_MAGIC;
429 s->s_flags |= SB_RDONLY; /* Yup, read-only yet */
430 s->s_time_min = 0;
431 s->s_time_max = U32_MAX;
432
433 /* ease the later tree level calculations */
434 sbi = QNX6_SB(s);
435 sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
436 sbi->inodes = qnx6_private_inode(s, &sb1->Inode);
437 if (!sbi->inodes)
438 goto out;
439 sbi->longfile = qnx6_private_inode(s, &sb1->Longfile);
440 if (!sbi->longfile)
441 goto out1;
442
443 /* prefetch root inode */
444 root = qnx6_iget(s, QNX6_ROOT_INO);
445 if (IS_ERR(root)) {
446 pr_err("get inode failed\n");
447 ret = PTR_ERR(root);
448 goto out2;
449 }
450
451 ret = -ENOMEM;
452 s->s_root = d_make_root(root);
453 if (!s->s_root)
454 goto out2;
455
456 ret = -EINVAL;
457 errmsg = qnx6_checkroot(s);
458 if (errmsg != NULL) {
459 if (!silent)
460 pr_err("%s\n", errmsg);
461 goto out3;
462 }
463 return 0;
464
465out3:
466 dput(s->s_root);
467 s->s_root = NULL;
468out2:
469 iput(sbi->longfile);
470out1:
471 iput(sbi->inodes);
472out:
473 brelse(bh1);
474 brelse(bh2);
475outnobh:
476 kfree(qs);
477 s->s_fs_info = NULL;
478 return ret;
479}
480
481static void qnx6_put_super(struct super_block *sb)
482{
483 struct qnx6_sb_info *qs = QNX6_SB(sb);
484 brelse(qs->sb_buf);
485 iput(qs->longfile);
486 iput(qs->inodes);
487 kfree(qs);
488 sb->s_fs_info = NULL;
489 return;
490}
491
492static sector_t qnx6_bmap(struct address_space *mapping, sector_t block)
493{
494 return generic_block_bmap(mapping, block, qnx6_get_block);
495}
496static const struct address_space_operations qnx6_aops = {
497 .read_folio = qnx6_read_folio,
498 .readahead = qnx6_readahead,
499 .bmap = qnx6_bmap
500};
501
502static struct inode *qnx6_private_inode(struct super_block *s,
503 struct qnx6_root_node *p)
504{
505 struct inode *inode = new_inode(s);
506 if (inode) {
507 struct qnx6_inode_info *ei = QNX6_I(inode);
508 struct qnx6_sb_info *sbi = QNX6_SB(s);
509 inode->i_size = fs64_to_cpu(sbi, p->size);
510 memcpy(ei->di_block_ptr, p->ptr, sizeof(p->ptr));
511 ei->di_filelevels = p->levels;
512 inode->i_mode = S_IFREG | S_IRUSR; /* probably wrong */
513 inode->i_mapping->a_ops = &qnx6_aops;
514 }
515 return inode;
516}
517
518struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
519{
520 struct qnx6_sb_info *sbi = QNX6_SB(sb);
521 struct qnx6_inode_entry *raw_inode;
522 struct inode *inode;
523 struct qnx6_inode_info *ei;
524 struct address_space *mapping;
525 struct page *page;
526 u32 n, offs;
527
528 inode = iget_locked(sb, ino);
529 if (!inode)
530 return ERR_PTR(-ENOMEM);
531 if (!(inode->i_state & I_NEW))
532 return inode;
533
534 ei = QNX6_I(inode);
535
536 inode->i_mode = 0;
537
538 if (ino == 0) {
539 pr_err("bad inode number on dev %s: %u is out of range\n",
540 sb->s_id, ino);
541 iget_failed(inode);
542 return ERR_PTR(-EIO);
543 }
544 n = (ino - 1) >> (PAGE_SHIFT - QNX6_INODE_SIZE_BITS);
545 offs = (ino - 1) & (~PAGE_MASK >> QNX6_INODE_SIZE_BITS);
546 mapping = sbi->inodes->i_mapping;
547 page = read_mapping_page(mapping, n, NULL);
548 if (IS_ERR(page)) {
549 pr_err("major problem: unable to read inode from dev %s\n",
550 sb->s_id);
551 iget_failed(inode);
552 return ERR_CAST(page);
553 }
554 kmap(page);
555 raw_inode = ((struct qnx6_inode_entry *)page_address(page)) + offs;
556
557 inode->i_mode = fs16_to_cpu(sbi, raw_inode->di_mode);
558 i_uid_write(inode, (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid));
559 i_gid_write(inode, (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid));
560 inode->i_size = fs64_to_cpu(sbi, raw_inode->di_size);
561 inode->i_mtime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_mtime);
562 inode->i_mtime.tv_nsec = 0;
563 inode->i_atime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_atime);
564 inode->i_atime.tv_nsec = 0;
565 inode->i_ctime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_ctime);
566 inode->i_ctime.tv_nsec = 0;
567
568 /* calc blocks based on 512 byte blocksize */
569 inode->i_blocks = (inode->i_size + 511) >> 9;
570
571 memcpy(&ei->di_block_ptr, &raw_inode->di_block_ptr,
572 sizeof(raw_inode->di_block_ptr));
573 ei->di_filelevels = raw_inode->di_filelevels;
574
575 if (S_ISREG(inode->i_mode)) {
576 inode->i_fop = &generic_ro_fops;
577 inode->i_mapping->a_ops = &qnx6_aops;
578 } else if (S_ISDIR(inode->i_mode)) {
579 inode->i_op = &qnx6_dir_inode_operations;
580 inode->i_fop = &qnx6_dir_operations;
581 inode->i_mapping->a_ops = &qnx6_aops;
582 } else if (S_ISLNK(inode->i_mode)) {
583 inode->i_op = &page_symlink_inode_operations;
584 inode_nohighmem(inode);
585 inode->i_mapping->a_ops = &qnx6_aops;
586 } else
587 init_special_inode(inode, inode->i_mode, 0);
588 qnx6_put_page(page);
589 unlock_new_inode(inode);
590 return inode;
591}
592
593static struct kmem_cache *qnx6_inode_cachep;
594
595static struct inode *qnx6_alloc_inode(struct super_block *sb)
596{
597 struct qnx6_inode_info *ei;
598 ei = alloc_inode_sb(sb, qnx6_inode_cachep, GFP_KERNEL);
599 if (!ei)
600 return NULL;
601 return &ei->vfs_inode;
602}
603
604static void qnx6_free_inode(struct inode *inode)
605{
606 kmem_cache_free(qnx6_inode_cachep, QNX6_I(inode));
607}
608
609static void init_once(void *foo)
610{
611 struct qnx6_inode_info *ei = (struct qnx6_inode_info *) foo;
612
613 inode_init_once(&ei->vfs_inode);
614}
615
616static int init_inodecache(void)
617{
618 qnx6_inode_cachep = kmem_cache_create("qnx6_inode_cache",
619 sizeof(struct qnx6_inode_info),
620 0, (SLAB_RECLAIM_ACCOUNT|
621 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
622 init_once);
623 if (!qnx6_inode_cachep)
624 return -ENOMEM;
625 return 0;
626}
627
628static void destroy_inodecache(void)
629{
630 /*
631 * Make sure all delayed rcu free inodes are flushed before we
632 * destroy cache.
633 */
634 rcu_barrier();
635 kmem_cache_destroy(qnx6_inode_cachep);
636}
637
638static struct dentry *qnx6_mount(struct file_system_type *fs_type,
639 int flags, const char *dev_name, void *data)
640{
641 return mount_bdev(fs_type, flags, dev_name, data, qnx6_fill_super);
642}
643
644static struct file_system_type qnx6_fs_type = {
645 .owner = THIS_MODULE,
646 .name = "qnx6",
647 .mount = qnx6_mount,
648 .kill_sb = kill_block_super,
649 .fs_flags = FS_REQUIRES_DEV,
650};
651MODULE_ALIAS_FS("qnx6");
652
653static int __init init_qnx6_fs(void)
654{
655 int err;
656
657 err = init_inodecache();
658 if (err)
659 return err;
660
661 err = register_filesystem(&qnx6_fs_type);
662 if (err) {
663 destroy_inodecache();
664 return err;
665 }
666
667 pr_info("QNX6 filesystem 1.0.0 registered.\n");
668 return 0;
669}
670
671static void __exit exit_qnx6_fs(void)
672{
673 unregister_filesystem(&qnx6_fs_type);
674 destroy_inodecache();
675}
676
677module_init(init_qnx6_fs)
678module_exit(exit_qnx6_fs)
679MODULE_LICENSE("GPL");
1/*
2 * QNX6 file system, Linux implementation.
3 *
4 * Version : 1.0.0
5 *
6 * History :
7 *
8 * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
9 * 16-02-2012 pagemap extension by Al Viro
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/highuid.h>
17#include <linux/pagemap.h>
18#include <linux/buffer_head.h>
19#include <linux/writeback.h>
20#include <linux/statfs.h>
21#include <linux/parser.h>
22#include <linux/seq_file.h>
23#include <linux/mount.h>
24#include <linux/crc32.h>
25#include <linux/mpage.h>
26#include "qnx6.h"
27
28static const struct super_operations qnx6_sops;
29
30static void qnx6_put_super(struct super_block *sb);
31static struct inode *qnx6_alloc_inode(struct super_block *sb);
32static void qnx6_destroy_inode(struct inode *inode);
33static int qnx6_remount(struct super_block *sb, int *flags, char *data);
34static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf);
35static int qnx6_show_options(struct seq_file *seq, struct dentry *root);
36
37static const struct super_operations qnx6_sops = {
38 .alloc_inode = qnx6_alloc_inode,
39 .destroy_inode = qnx6_destroy_inode,
40 .put_super = qnx6_put_super,
41 .statfs = qnx6_statfs,
42 .remount_fs = qnx6_remount,
43 .show_options = qnx6_show_options,
44};
45
46static int qnx6_show_options(struct seq_file *seq, struct dentry *root)
47{
48 struct super_block *sb = root->d_sb;
49 struct qnx6_sb_info *sbi = QNX6_SB(sb);
50
51 if (sbi->s_mount_opt & QNX6_MOUNT_MMI_FS)
52 seq_puts(seq, ",mmi_fs");
53 return 0;
54}
55
56static int qnx6_remount(struct super_block *sb, int *flags, char *data)
57{
58 *flags |= MS_RDONLY;
59 return 0;
60}
61
62static unsigned qnx6_get_devblock(struct super_block *sb, __fs32 block)
63{
64 struct qnx6_sb_info *sbi = QNX6_SB(sb);
65 return fs32_to_cpu(sbi, block) + sbi->s_blks_off;
66}
67
68static unsigned qnx6_block_map(struct inode *inode, unsigned iblock);
69
70static int qnx6_get_block(struct inode *inode, sector_t iblock,
71 struct buffer_head *bh, int create)
72{
73 unsigned phys;
74
75 QNX6DEBUG((KERN_INFO "qnx6: qnx6_get_block inode=[%ld] iblock=[%ld]\n",
76 inode->i_ino, (unsigned long)iblock));
77
78 phys = qnx6_block_map(inode, iblock);
79 if (phys) {
80 /* logical block is before EOF */
81 map_bh(bh, inode->i_sb, phys);
82 }
83 return 0;
84}
85
86static int qnx6_check_blockptr(__fs32 ptr)
87{
88 if (ptr == ~(__fs32)0) {
89 printk(KERN_ERR "qnx6: hit unused blockpointer.\n");
90 return 0;
91 }
92 return 1;
93}
94
95static int qnx6_readpage(struct file *file, struct page *page)
96{
97 return mpage_readpage(page, qnx6_get_block);
98}
99
100static int qnx6_readpages(struct file *file, struct address_space *mapping,
101 struct list_head *pages, unsigned nr_pages)
102{
103 return mpage_readpages(mapping, pages, nr_pages, qnx6_get_block);
104}
105
106/*
107 * returns the block number for the no-th element in the tree
108 * inodebits requred as there are multiple inodes in one inode block
109 */
110static unsigned qnx6_block_map(struct inode *inode, unsigned no)
111{
112 struct super_block *s = inode->i_sb;
113 struct qnx6_sb_info *sbi = QNX6_SB(s);
114 struct qnx6_inode_info *ei = QNX6_I(inode);
115 unsigned block = 0;
116 struct buffer_head *bh;
117 __fs32 ptr;
118 int levelptr;
119 int ptrbits = sbi->s_ptrbits;
120 int bitdelta;
121 u32 mask = (1 << ptrbits) - 1;
122 int depth = ei->di_filelevels;
123 int i;
124
125 bitdelta = ptrbits * depth;
126 levelptr = no >> bitdelta;
127
128 if (levelptr > QNX6_NO_DIRECT_POINTERS - 1) {
129 printk(KERN_ERR "qnx6:Requested file block number (%u) too big.",
130 no);
131 return 0;
132 }
133
134 block = qnx6_get_devblock(s, ei->di_block_ptr[levelptr]);
135
136 for (i = 0; i < depth; i++) {
137 bh = sb_bread(s, block);
138 if (!bh) {
139 printk(KERN_ERR "qnx6:Error reading block (%u)\n",
140 block);
141 return 0;
142 }
143 bitdelta -= ptrbits;
144 levelptr = (no >> bitdelta) & mask;
145 ptr = ((__fs32 *)bh->b_data)[levelptr];
146
147 if (!qnx6_check_blockptr(ptr))
148 return 0;
149
150 block = qnx6_get_devblock(s, ptr);
151 brelse(bh);
152 }
153 return block;
154}
155
156static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf)
157{
158 struct super_block *sb = dentry->d_sb;
159 struct qnx6_sb_info *sbi = QNX6_SB(sb);
160 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
161
162 buf->f_type = sb->s_magic;
163 buf->f_bsize = sb->s_blocksize;
164 buf->f_blocks = fs32_to_cpu(sbi, sbi->sb->sb_num_blocks);
165 buf->f_bfree = fs32_to_cpu(sbi, sbi->sb->sb_free_blocks);
166 buf->f_files = fs32_to_cpu(sbi, sbi->sb->sb_num_inodes);
167 buf->f_ffree = fs32_to_cpu(sbi, sbi->sb->sb_free_inodes);
168 buf->f_bavail = buf->f_bfree;
169 buf->f_namelen = QNX6_LONG_NAME_MAX;
170 buf->f_fsid.val[0] = (u32)id;
171 buf->f_fsid.val[1] = (u32)(id >> 32);
172
173 return 0;
174}
175
176/*
177 * Check the root directory of the filesystem to make sure
178 * it really _is_ a qnx6 filesystem, and to check the size
179 * of the directory entry.
180 */
181static const char *qnx6_checkroot(struct super_block *s)
182{
183 static char match_root[2][3] = {".\0\0", "..\0"};
184 int i, error = 0;
185 struct qnx6_dir_entry *dir_entry;
186 struct inode *root = s->s_root->d_inode;
187 struct address_space *mapping = root->i_mapping;
188 struct page *page = read_mapping_page(mapping, 0, NULL);
189 if (IS_ERR(page))
190 return "error reading root directory";
191 kmap(page);
192 dir_entry = page_address(page);
193 for (i = 0; i < 2; i++) {
194 /* maximum 3 bytes - due to match_root limitation */
195 if (strncmp(dir_entry[i].de_fname, match_root[i], 3))
196 error = 1;
197 }
198 qnx6_put_page(page);
199 if (error)
200 return "error reading root directory.";
201 return NULL;
202}
203
204#ifdef CONFIG_QNX6FS_DEBUG
205void qnx6_superblock_debug(struct qnx6_super_block *sb, struct super_block *s)
206{
207 struct qnx6_sb_info *sbi = QNX6_SB(s);
208
209 QNX6DEBUG((KERN_INFO "magic: %08x\n",
210 fs32_to_cpu(sbi, sb->sb_magic)));
211 QNX6DEBUG((KERN_INFO "checksum: %08x\n",
212 fs32_to_cpu(sbi, sb->sb_checksum)));
213 QNX6DEBUG((KERN_INFO "serial: %llx\n",
214 fs64_to_cpu(sbi, sb->sb_serial)));
215 QNX6DEBUG((KERN_INFO "flags: %08x\n",
216 fs32_to_cpu(sbi, sb->sb_flags)));
217 QNX6DEBUG((KERN_INFO "blocksize: %08x\n",
218 fs32_to_cpu(sbi, sb->sb_blocksize)));
219 QNX6DEBUG((KERN_INFO "num_inodes: %08x\n",
220 fs32_to_cpu(sbi, sb->sb_num_inodes)));
221 QNX6DEBUG((KERN_INFO "free_inodes: %08x\n",
222 fs32_to_cpu(sbi, sb->sb_free_inodes)));
223 QNX6DEBUG((KERN_INFO "num_blocks: %08x\n",
224 fs32_to_cpu(sbi, sb->sb_num_blocks)));
225 QNX6DEBUG((KERN_INFO "free_blocks: %08x\n",
226 fs32_to_cpu(sbi, sb->sb_free_blocks)));
227 QNX6DEBUG((KERN_INFO "inode_levels: %02x\n",
228 sb->Inode.levels));
229}
230#endif
231
232enum {
233 Opt_mmifs,
234 Opt_err
235};
236
237static const match_table_t tokens = {
238 {Opt_mmifs, "mmi_fs"},
239 {Opt_err, NULL}
240};
241
242static int qnx6_parse_options(char *options, struct super_block *sb)
243{
244 char *p;
245 struct qnx6_sb_info *sbi = QNX6_SB(sb);
246 substring_t args[MAX_OPT_ARGS];
247
248 if (!options)
249 return 1;
250
251 while ((p = strsep(&options, ",")) != NULL) {
252 int token;
253 if (!*p)
254 continue;
255
256 token = match_token(p, tokens, args);
257 switch (token) {
258 case Opt_mmifs:
259 set_opt(sbi->s_mount_opt, MMI_FS);
260 break;
261 default:
262 return 0;
263 }
264 }
265 return 1;
266}
267
268static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
269 int offset, int silent)
270{
271 struct qnx6_sb_info *sbi = QNX6_SB(s);
272 struct buffer_head *bh;
273 struct qnx6_super_block *sb;
274
275 /* Check the superblock signatures
276 start with the first superblock */
277 bh = sb_bread(s, offset);
278 if (!bh) {
279 printk(KERN_ERR "qnx6: unable to read the first superblock\n");
280 return NULL;
281 }
282 sb = (struct qnx6_super_block *)bh->b_data;
283 if (fs32_to_cpu(sbi, sb->sb_magic) != QNX6_SUPER_MAGIC) {
284 sbi->s_bytesex = BYTESEX_BE;
285 if (fs32_to_cpu(sbi, sb->sb_magic) == QNX6_SUPER_MAGIC) {
286 /* we got a big endian fs */
287 QNX6DEBUG((KERN_INFO "qnx6: fs got different"
288 " endianess.\n"));
289 return bh;
290 } else
291 sbi->s_bytesex = BYTESEX_LE;
292 if (!silent) {
293 if (offset == 0) {
294 printk(KERN_ERR "qnx6: wrong signature (magic)"
295 " in superblock #1.\n");
296 } else {
297 printk(KERN_INFO "qnx6: wrong signature (magic)"
298 " at position (0x%lx) - will try"
299 " alternative position (0x0000).\n",
300 offset * s->s_blocksize);
301 }
302 }
303 brelse(bh);
304 return NULL;
305 }
306 return bh;
307}
308
309static struct inode *qnx6_private_inode(struct super_block *s,
310 struct qnx6_root_node *p);
311
312static int qnx6_fill_super(struct super_block *s, void *data, int silent)
313{
314 struct buffer_head *bh1 = NULL, *bh2 = NULL;
315 struct qnx6_super_block *sb1 = NULL, *sb2 = NULL;
316 struct qnx6_sb_info *sbi;
317 struct inode *root;
318 const char *errmsg;
319 struct qnx6_sb_info *qs;
320 int ret = -EINVAL;
321 u64 offset;
322 int bootblock_offset = QNX6_BOOTBLOCK_SIZE;
323
324 qs = kzalloc(sizeof(struct qnx6_sb_info), GFP_KERNEL);
325 if (!qs)
326 return -ENOMEM;
327 s->s_fs_info = qs;
328
329 /* Superblock always is 512 Byte long */
330 if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
331 printk(KERN_ERR "qnx6: unable to set blocksize\n");
332 goto outnobh;
333 }
334
335 /* parse the mount-options */
336 if (!qnx6_parse_options((char *) data, s)) {
337 printk(KERN_ERR "qnx6: invalid mount options.\n");
338 goto outnobh;
339 }
340 if (test_opt(s, MMI_FS)) {
341 sb1 = qnx6_mmi_fill_super(s, silent);
342 if (sb1)
343 goto mmi_success;
344 else
345 goto outnobh;
346 }
347 sbi = QNX6_SB(s);
348 sbi->s_bytesex = BYTESEX_LE;
349 /* Check the superblock signatures
350 start with the first superblock */
351 bh1 = qnx6_check_first_superblock(s,
352 bootblock_offset / QNX6_SUPERBLOCK_SIZE, silent);
353 if (!bh1) {
354 /* try again without bootblock offset */
355 bh1 = qnx6_check_first_superblock(s, 0, silent);
356 if (!bh1) {
357 printk(KERN_ERR "qnx6: unable to read the first superblock\n");
358 goto outnobh;
359 }
360 /* seems that no bootblock at partition start */
361 bootblock_offset = 0;
362 }
363 sb1 = (struct qnx6_super_block *)bh1->b_data;
364
365#ifdef CONFIG_QNX6FS_DEBUG
366 qnx6_superblock_debug(sb1, s);
367#endif
368
369 /* checksum check - start at byte 8 and end at byte 512 */
370 if (fs32_to_cpu(sbi, sb1->sb_checksum) !=
371 crc32_be(0, (char *)(bh1->b_data + 8), 504)) {
372 printk(KERN_ERR "qnx6: superblock #1 checksum error\n");
373 goto out;
374 }
375
376 /* set new blocksize */
377 if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
378 printk(KERN_ERR "qnx6: unable to set blocksize\n");
379 goto out;
380 }
381 /* blocksize invalidates bh - pull it back in */
382 brelse(bh1);
383 bh1 = sb_bread(s, bootblock_offset >> s->s_blocksize_bits);
384 if (!bh1)
385 goto outnobh;
386 sb1 = (struct qnx6_super_block *)bh1->b_data;
387
388 /* calculate second superblock blocknumber */
389 offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) +
390 (bootblock_offset >> s->s_blocksize_bits) +
391 (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
392
393 /* set bootblock offset */
394 sbi->s_blks_off = (bootblock_offset >> s->s_blocksize_bits) +
395 (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
396
397 /* next the second superblock */
398 bh2 = sb_bread(s, offset);
399 if (!bh2) {
400 printk(KERN_ERR "qnx6: unable to read the second superblock\n");
401 goto out;
402 }
403 sb2 = (struct qnx6_super_block *)bh2->b_data;
404 if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) {
405 if (!silent)
406 printk(KERN_ERR "qnx6: wrong signature (magic)"
407 " in superblock #2.\n");
408 goto out;
409 }
410
411 /* checksum check - start at byte 8 and end at byte 512 */
412 if (fs32_to_cpu(sbi, sb2->sb_checksum) !=
413 crc32_be(0, (char *)(bh2->b_data + 8), 504)) {
414 printk(KERN_ERR "qnx6: superblock #2 checksum error\n");
415 goto out;
416 }
417
418 if (fs64_to_cpu(sbi, sb1->sb_serial) >=
419 fs64_to_cpu(sbi, sb2->sb_serial)) {
420 /* superblock #1 active */
421 sbi->sb_buf = bh1;
422 sbi->sb = (struct qnx6_super_block *)bh1->b_data;
423 brelse(bh2);
424 printk(KERN_INFO "qnx6: superblock #1 active\n");
425 } else {
426 /* superblock #2 active */
427 sbi->sb_buf = bh2;
428 sbi->sb = (struct qnx6_super_block *)bh2->b_data;
429 brelse(bh1);
430 printk(KERN_INFO "qnx6: superblock #2 active\n");
431 }
432mmi_success:
433 /* sanity check - limit maximum indirect pointer levels */
434 if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
435 printk(KERN_ERR "qnx6: too many inode levels (max %i, sb %i)\n",
436 QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
437 goto out;
438 }
439 if (sb1->Longfile.levels > QNX6_PTR_MAX_LEVELS) {
440 printk(KERN_ERR "qnx6: too many longfilename levels"
441 " (max %i, sb %i)\n",
442 QNX6_PTR_MAX_LEVELS, sb1->Longfile.levels);
443 goto out;
444 }
445 s->s_op = &qnx6_sops;
446 s->s_magic = QNX6_SUPER_MAGIC;
447 s->s_flags |= MS_RDONLY; /* Yup, read-only yet */
448
449 /* ease the later tree level calculations */
450 sbi = QNX6_SB(s);
451 sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
452 sbi->inodes = qnx6_private_inode(s, &sb1->Inode);
453 if (!sbi->inodes)
454 goto out;
455 sbi->longfile = qnx6_private_inode(s, &sb1->Longfile);
456 if (!sbi->longfile)
457 goto out1;
458
459 /* prefetch root inode */
460 root = qnx6_iget(s, QNX6_ROOT_INO);
461 if (IS_ERR(root)) {
462 printk(KERN_ERR "qnx6: get inode failed\n");
463 ret = PTR_ERR(root);
464 goto out2;
465 }
466
467 ret = -ENOMEM;
468 s->s_root = d_make_root(root);
469 if (!s->s_root)
470 goto out2;
471
472 ret = -EINVAL;
473 errmsg = qnx6_checkroot(s);
474 if (errmsg != NULL) {
475 if (!silent)
476 printk(KERN_ERR "qnx6: %s\n", errmsg);
477 goto out3;
478 }
479 return 0;
480
481out3:
482 dput(s->s_root);
483 s->s_root = NULL;
484out2:
485 iput(sbi->longfile);
486out1:
487 iput(sbi->inodes);
488out:
489 if (bh1)
490 brelse(bh1);
491 if (bh2)
492 brelse(bh2);
493outnobh:
494 kfree(qs);
495 s->s_fs_info = NULL;
496 return ret;
497}
498
499static void qnx6_put_super(struct super_block *sb)
500{
501 struct qnx6_sb_info *qs = QNX6_SB(sb);
502 brelse(qs->sb_buf);
503 iput(qs->longfile);
504 iput(qs->inodes);
505 kfree(qs);
506 sb->s_fs_info = NULL;
507 return;
508}
509
510static sector_t qnx6_bmap(struct address_space *mapping, sector_t block)
511{
512 return generic_block_bmap(mapping, block, qnx6_get_block);
513}
514static const struct address_space_operations qnx6_aops = {
515 .readpage = qnx6_readpage,
516 .readpages = qnx6_readpages,
517 .bmap = qnx6_bmap
518};
519
520static struct inode *qnx6_private_inode(struct super_block *s,
521 struct qnx6_root_node *p)
522{
523 struct inode *inode = new_inode(s);
524 if (inode) {
525 struct qnx6_inode_info *ei = QNX6_I(inode);
526 struct qnx6_sb_info *sbi = QNX6_SB(s);
527 inode->i_size = fs64_to_cpu(sbi, p->size);
528 memcpy(ei->di_block_ptr, p->ptr, sizeof(p->ptr));
529 ei->di_filelevels = p->levels;
530 inode->i_mode = S_IFREG | S_IRUSR; /* probably wrong */
531 inode->i_mapping->a_ops = &qnx6_aops;
532 }
533 return inode;
534}
535
536struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
537{
538 struct qnx6_sb_info *sbi = QNX6_SB(sb);
539 struct qnx6_inode_entry *raw_inode;
540 struct inode *inode;
541 struct qnx6_inode_info *ei;
542 struct address_space *mapping;
543 struct page *page;
544 u32 n, offs;
545
546 inode = iget_locked(sb, ino);
547 if (!inode)
548 return ERR_PTR(-ENOMEM);
549 if (!(inode->i_state & I_NEW))
550 return inode;
551
552 ei = QNX6_I(inode);
553
554 inode->i_mode = 0;
555
556 if (ino == 0) {
557 printk(KERN_ERR "qnx6: bad inode number on dev %s: %u is "
558 "out of range\n",
559 sb->s_id, ino);
560 iget_failed(inode);
561 return ERR_PTR(-EIO);
562 }
563 n = (ino - 1) >> (PAGE_CACHE_SHIFT - QNX6_INODE_SIZE_BITS);
564 offs = (ino - 1) & (~PAGE_CACHE_MASK >> QNX6_INODE_SIZE_BITS);
565 mapping = sbi->inodes->i_mapping;
566 page = read_mapping_page(mapping, n, NULL);
567 if (IS_ERR(page)) {
568 printk(KERN_ERR "qnx6: major problem: unable to read inode from "
569 "dev %s\n", sb->s_id);
570 iget_failed(inode);
571 return ERR_CAST(page);
572 }
573 kmap(page);
574 raw_inode = ((struct qnx6_inode_entry *)page_address(page)) + offs;
575
576 inode->i_mode = fs16_to_cpu(sbi, raw_inode->di_mode);
577 inode->i_uid = (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid);
578 inode->i_gid = (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid);
579 inode->i_size = fs64_to_cpu(sbi, raw_inode->di_size);
580 inode->i_mtime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_mtime);
581 inode->i_mtime.tv_nsec = 0;
582 inode->i_atime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_atime);
583 inode->i_atime.tv_nsec = 0;
584 inode->i_ctime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_ctime);
585 inode->i_ctime.tv_nsec = 0;
586
587 /* calc blocks based on 512 byte blocksize */
588 inode->i_blocks = (inode->i_size + 511) >> 9;
589
590 memcpy(&ei->di_block_ptr, &raw_inode->di_block_ptr,
591 sizeof(raw_inode->di_block_ptr));
592 ei->di_filelevels = raw_inode->di_filelevels;
593
594 if (S_ISREG(inode->i_mode)) {
595 inode->i_fop = &generic_ro_fops;
596 inode->i_mapping->a_ops = &qnx6_aops;
597 } else if (S_ISDIR(inode->i_mode)) {
598 inode->i_op = &qnx6_dir_inode_operations;
599 inode->i_fop = &qnx6_dir_operations;
600 inode->i_mapping->a_ops = &qnx6_aops;
601 } else if (S_ISLNK(inode->i_mode)) {
602 inode->i_op = &page_symlink_inode_operations;
603 inode->i_mapping->a_ops = &qnx6_aops;
604 } else
605 init_special_inode(inode, inode->i_mode, 0);
606 qnx6_put_page(page);
607 unlock_new_inode(inode);
608 return inode;
609}
610
611static struct kmem_cache *qnx6_inode_cachep;
612
613static struct inode *qnx6_alloc_inode(struct super_block *sb)
614{
615 struct qnx6_inode_info *ei;
616 ei = kmem_cache_alloc(qnx6_inode_cachep, GFP_KERNEL);
617 if (!ei)
618 return NULL;
619 return &ei->vfs_inode;
620}
621
622static void qnx6_i_callback(struct rcu_head *head)
623{
624 struct inode *inode = container_of(head, struct inode, i_rcu);
625 INIT_LIST_HEAD(&inode->i_dentry);
626 kmem_cache_free(qnx6_inode_cachep, QNX6_I(inode));
627}
628
629static void qnx6_destroy_inode(struct inode *inode)
630{
631 call_rcu(&inode->i_rcu, qnx6_i_callback);
632}
633
634static void init_once(void *foo)
635{
636 struct qnx6_inode_info *ei = (struct qnx6_inode_info *) foo;
637
638 inode_init_once(&ei->vfs_inode);
639}
640
641static int init_inodecache(void)
642{
643 qnx6_inode_cachep = kmem_cache_create("qnx6_inode_cache",
644 sizeof(struct qnx6_inode_info),
645 0, (SLAB_RECLAIM_ACCOUNT|
646 SLAB_MEM_SPREAD),
647 init_once);
648 if (!qnx6_inode_cachep)
649 return -ENOMEM;
650 return 0;
651}
652
653static void destroy_inodecache(void)
654{
655 kmem_cache_destroy(qnx6_inode_cachep);
656}
657
658static struct dentry *qnx6_mount(struct file_system_type *fs_type,
659 int flags, const char *dev_name, void *data)
660{
661 return mount_bdev(fs_type, flags, dev_name, data, qnx6_fill_super);
662}
663
664static struct file_system_type qnx6_fs_type = {
665 .owner = THIS_MODULE,
666 .name = "qnx6",
667 .mount = qnx6_mount,
668 .kill_sb = kill_block_super,
669 .fs_flags = FS_REQUIRES_DEV,
670};
671
672static int __init init_qnx6_fs(void)
673{
674 int err;
675
676 err = init_inodecache();
677 if (err)
678 return err;
679
680 err = register_filesystem(&qnx6_fs_type);
681 if (err) {
682 destroy_inodecache();
683 return err;
684 }
685
686 printk(KERN_INFO "QNX6 filesystem 1.0.0 registered.\n");
687 return 0;
688}
689
690static void __exit exit_qnx6_fs(void)
691{
692 unregister_filesystem(&qnx6_fs_type);
693 destroy_inodecache();
694}
695
696module_init(init_qnx6_fs)
697module_exit(exit_qnx6_fs)
698MODULE_LICENSE("GPL");