Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * QNX6 file system, Linux implementation.
0004  *
0005  * Version : 1.0.0
0006  *
0007  * History :
0008  *
0009  * 01-02-2012 by Kai Bankett (chaosman@ontika.net) : first release.
0010  * 16-02-2012 pagemap extension by Al Viro
0011  *
0012  */
0013 
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/slab.h>
0017 #include <linux/highuid.h>
0018 #include <linux/pagemap.h>
0019 #include <linux/buffer_head.h>
0020 #include <linux/writeback.h>
0021 #include <linux/statfs.h>
0022 #include <linux/parser.h>
0023 #include <linux/seq_file.h>
0024 #include <linux/mount.h>
0025 #include <linux/crc32.h>
0026 #include <linux/mpage.h>
0027 #include "qnx6.h"
0028 
0029 static const struct super_operations qnx6_sops;
0030 
0031 static void qnx6_put_super(struct super_block *sb);
0032 static struct inode *qnx6_alloc_inode(struct super_block *sb);
0033 static void qnx6_free_inode(struct inode *inode);
0034 static int qnx6_remount(struct super_block *sb, int *flags, char *data);
0035 static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf);
0036 static int qnx6_show_options(struct seq_file *seq, struct dentry *root);
0037 
0038 static const struct super_operations qnx6_sops = {
0039     .alloc_inode    = qnx6_alloc_inode,
0040     .free_inode = qnx6_free_inode,
0041     .put_super  = qnx6_put_super,
0042     .statfs     = qnx6_statfs,
0043     .remount_fs = qnx6_remount,
0044     .show_options   = qnx6_show_options,
0045 };
0046 
0047 static int qnx6_show_options(struct seq_file *seq, struct dentry *root)
0048 {
0049     struct super_block *sb = root->d_sb;
0050     struct qnx6_sb_info *sbi = QNX6_SB(sb);
0051 
0052     if (sbi->s_mount_opt & QNX6_MOUNT_MMI_FS)
0053         seq_puts(seq, ",mmi_fs");
0054     return 0;
0055 }
0056 
0057 static int qnx6_remount(struct super_block *sb, int *flags, char *data)
0058 {
0059     sync_filesystem(sb);
0060     *flags |= SB_RDONLY;
0061     return 0;
0062 }
0063 
0064 static unsigned qnx6_get_devblock(struct super_block *sb, __fs32 block)
0065 {
0066     struct qnx6_sb_info *sbi = QNX6_SB(sb);
0067     return fs32_to_cpu(sbi, block) + sbi->s_blks_off;
0068 }
0069 
0070 static unsigned qnx6_block_map(struct inode *inode, unsigned iblock);
0071 
0072 static int qnx6_get_block(struct inode *inode, sector_t iblock,
0073             struct buffer_head *bh, int create)
0074 {
0075     unsigned phys;
0076 
0077     pr_debug("qnx6_get_block inode=[%ld] iblock=[%ld]\n",
0078          inode->i_ino, (unsigned long)iblock);
0079 
0080     phys = qnx6_block_map(inode, iblock);
0081     if (phys) {
0082         /* logical block is before EOF */
0083         map_bh(bh, inode->i_sb, phys);
0084     }
0085     return 0;
0086 }
0087 
0088 static int qnx6_check_blockptr(__fs32 ptr)
0089 {
0090     if (ptr == ~(__fs32)0) {
0091         pr_err("hit unused blockpointer.\n");
0092         return 0;
0093     }
0094     return 1;
0095 }
0096 
0097 static int qnx6_read_folio(struct file *file, struct folio *folio)
0098 {
0099     return mpage_read_folio(folio, qnx6_get_block);
0100 }
0101 
0102 static void qnx6_readahead(struct readahead_control *rac)
0103 {
0104     mpage_readahead(rac, qnx6_get_block);
0105 }
0106 
0107 /*
0108  * returns the block number for the no-th element in the tree
0109  * inodebits requred as there are multiple inodes in one inode block
0110  */
0111 static unsigned qnx6_block_map(struct inode *inode, unsigned no)
0112 {
0113     struct super_block *s = inode->i_sb;
0114     struct qnx6_sb_info *sbi = QNX6_SB(s);
0115     struct qnx6_inode_info *ei = QNX6_I(inode);
0116     unsigned block = 0;
0117     struct buffer_head *bh;
0118     __fs32 ptr;
0119     int levelptr;
0120     int ptrbits = sbi->s_ptrbits;
0121     int bitdelta;
0122     u32 mask = (1 << ptrbits) - 1;
0123     int depth = ei->di_filelevels;
0124     int i;
0125 
0126     bitdelta = ptrbits * depth;
0127     levelptr = no >> bitdelta;
0128 
0129     if (levelptr > QNX6_NO_DIRECT_POINTERS - 1) {
0130         pr_err("Requested file block number (%u) too big.", no);
0131         return 0;
0132     }
0133 
0134     block = qnx6_get_devblock(s, ei->di_block_ptr[levelptr]);
0135 
0136     for (i = 0; i < depth; i++) {
0137         bh = sb_bread(s, block);
0138         if (!bh) {
0139             pr_err("Error reading block (%u)\n", block);
0140             return 0;
0141         }
0142         bitdelta -= ptrbits;
0143         levelptr = (no >> bitdelta) & mask;
0144         ptr = ((__fs32 *)bh->b_data)[levelptr];
0145 
0146         if (!qnx6_check_blockptr(ptr))
0147             return 0;
0148 
0149         block = qnx6_get_devblock(s, ptr);
0150         brelse(bh);
0151     }
0152     return block;
0153 }
0154 
0155 static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf)
0156 {
0157     struct super_block *sb = dentry->d_sb;
0158     struct qnx6_sb_info *sbi = QNX6_SB(sb);
0159     u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
0160 
0161     buf->f_type    = sb->s_magic;
0162     buf->f_bsize   = sb->s_blocksize;
0163     buf->f_blocks  = fs32_to_cpu(sbi, sbi->sb->sb_num_blocks);
0164     buf->f_bfree   = fs32_to_cpu(sbi, sbi->sb->sb_free_blocks);
0165     buf->f_files   = fs32_to_cpu(sbi, sbi->sb->sb_num_inodes);
0166     buf->f_ffree   = fs32_to_cpu(sbi, sbi->sb->sb_free_inodes);
0167     buf->f_bavail  = buf->f_bfree;
0168     buf->f_namelen = QNX6_LONG_NAME_MAX;
0169     buf->f_fsid    = u64_to_fsid(id);
0170 
0171     return 0;
0172 }
0173 
0174 /*
0175  * Check the root directory of the filesystem to make sure
0176  * it really _is_ a qnx6 filesystem, and to check the size
0177  * of the directory entry.
0178  */
0179 static const char *qnx6_checkroot(struct super_block *s)
0180 {
0181     static char match_root[2][3] = {".\0\0", "..\0"};
0182     int i, error = 0;
0183     struct qnx6_dir_entry *dir_entry;
0184     struct inode *root = d_inode(s->s_root);
0185     struct address_space *mapping = root->i_mapping;
0186     struct page *page = read_mapping_page(mapping, 0, NULL);
0187     if (IS_ERR(page))
0188         return "error reading root directory";
0189     kmap(page);
0190     dir_entry = page_address(page);
0191     for (i = 0; i < 2; i++) {
0192         /* maximum 3 bytes - due to match_root limitation */
0193         if (strncmp(dir_entry[i].de_fname, match_root[i], 3))
0194             error = 1;
0195     }
0196     qnx6_put_page(page);
0197     if (error)
0198         return "error reading root directory.";
0199     return NULL;
0200 }
0201 
0202 #ifdef CONFIG_QNX6FS_DEBUG
0203 void qnx6_superblock_debug(struct qnx6_super_block *sb, struct super_block *s)
0204 {
0205     struct qnx6_sb_info *sbi = QNX6_SB(s);
0206 
0207     pr_debug("magic: %08x\n", fs32_to_cpu(sbi, sb->sb_magic));
0208     pr_debug("checksum: %08x\n", fs32_to_cpu(sbi, sb->sb_checksum));
0209     pr_debug("serial: %llx\n", fs64_to_cpu(sbi, sb->sb_serial));
0210     pr_debug("flags: %08x\n", fs32_to_cpu(sbi, sb->sb_flags));
0211     pr_debug("blocksize: %08x\n", fs32_to_cpu(sbi, sb->sb_blocksize));
0212     pr_debug("num_inodes: %08x\n", fs32_to_cpu(sbi, sb->sb_num_inodes));
0213     pr_debug("free_inodes: %08x\n", fs32_to_cpu(sbi, sb->sb_free_inodes));
0214     pr_debug("num_blocks: %08x\n", fs32_to_cpu(sbi, sb->sb_num_blocks));
0215     pr_debug("free_blocks: %08x\n", fs32_to_cpu(sbi, sb->sb_free_blocks));
0216     pr_debug("inode_levels: %02x\n", sb->Inode.levels);
0217 }
0218 #endif
0219 
0220 enum {
0221     Opt_mmifs,
0222     Opt_err
0223 };
0224 
0225 static const match_table_t tokens = {
0226     {Opt_mmifs, "mmi_fs"},
0227     {Opt_err, NULL}
0228 };
0229 
0230 static int qnx6_parse_options(char *options, struct super_block *sb)
0231 {
0232     char *p;
0233     struct qnx6_sb_info *sbi = QNX6_SB(sb);
0234     substring_t args[MAX_OPT_ARGS];
0235 
0236     if (!options)
0237         return 1;
0238 
0239     while ((p = strsep(&options, ",")) != NULL) {
0240         int token;
0241         if (!*p)
0242             continue;
0243 
0244         token = match_token(p, tokens, args);
0245         switch (token) {
0246         case Opt_mmifs:
0247             set_opt(sbi->s_mount_opt, MMI_FS);
0248             break;
0249         default:
0250             return 0;
0251         }
0252     }
0253     return 1;
0254 }
0255 
0256 static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
0257                 int offset, int silent)
0258 {
0259     struct qnx6_sb_info *sbi = QNX6_SB(s);
0260     struct buffer_head *bh;
0261     struct qnx6_super_block *sb;
0262 
0263     /* Check the superblock signatures
0264        start with the first superblock */
0265     bh = sb_bread(s, offset);
0266     if (!bh) {
0267         pr_err("unable to read the first superblock\n");
0268         return NULL;
0269     }
0270     sb = (struct qnx6_super_block *)bh->b_data;
0271     if (fs32_to_cpu(sbi, sb->sb_magic) != QNX6_SUPER_MAGIC) {
0272         sbi->s_bytesex = BYTESEX_BE;
0273         if (fs32_to_cpu(sbi, sb->sb_magic) == QNX6_SUPER_MAGIC) {
0274             /* we got a big endian fs */
0275             pr_debug("fs got different endianness.\n");
0276             return bh;
0277         } else
0278             sbi->s_bytesex = BYTESEX_LE;
0279         if (!silent) {
0280             if (offset == 0) {
0281                 pr_err("wrong signature (magic) in superblock #1.\n");
0282             } else {
0283                 pr_info("wrong signature (magic) at position (0x%lx) - will try alternative position (0x0000).\n",
0284                     offset * s->s_blocksize);
0285             }
0286         }
0287         brelse(bh);
0288         return NULL;
0289     }
0290     return bh;
0291 }
0292 
0293 static struct inode *qnx6_private_inode(struct super_block *s,
0294                     struct qnx6_root_node *p);
0295 
0296 static int qnx6_fill_super(struct super_block *s, void *data, int silent)
0297 {
0298     struct buffer_head *bh1 = NULL, *bh2 = NULL;
0299     struct qnx6_super_block *sb1 = NULL, *sb2 = NULL;
0300     struct qnx6_sb_info *sbi;
0301     struct inode *root;
0302     const char *errmsg;
0303     struct qnx6_sb_info *qs;
0304     int ret = -EINVAL;
0305     u64 offset;
0306     int bootblock_offset = QNX6_BOOTBLOCK_SIZE;
0307 
0308     qs = kzalloc(sizeof(struct qnx6_sb_info), GFP_KERNEL);
0309     if (!qs)
0310         return -ENOMEM;
0311     s->s_fs_info = qs;
0312 
0313     /* Superblock always is 512 Byte long */
0314     if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
0315         pr_err("unable to set blocksize\n");
0316         goto outnobh;
0317     }
0318 
0319     /* parse the mount-options */
0320     if (!qnx6_parse_options((char *) data, s)) {
0321         pr_err("invalid mount options.\n");
0322         goto outnobh;
0323     }
0324     if (test_opt(s, MMI_FS)) {
0325         sb1 = qnx6_mmi_fill_super(s, silent);
0326         if (sb1)
0327             goto mmi_success;
0328         else
0329             goto outnobh;
0330     }
0331     sbi = QNX6_SB(s);
0332     sbi->s_bytesex = BYTESEX_LE;
0333     /* Check the superblock signatures
0334        start with the first superblock */
0335     bh1 = qnx6_check_first_superblock(s,
0336         bootblock_offset / QNX6_SUPERBLOCK_SIZE, silent);
0337     if (!bh1) {
0338         /* try again without bootblock offset */
0339         bh1 = qnx6_check_first_superblock(s, 0, silent);
0340         if (!bh1) {
0341             pr_err("unable to read the first superblock\n");
0342             goto outnobh;
0343         }
0344         /* seems that no bootblock at partition start */
0345         bootblock_offset = 0;
0346     }
0347     sb1 = (struct qnx6_super_block *)bh1->b_data;
0348 
0349 #ifdef CONFIG_QNX6FS_DEBUG
0350     qnx6_superblock_debug(sb1, s);
0351 #endif
0352 
0353     /* checksum check - start at byte 8 and end at byte 512 */
0354     if (fs32_to_cpu(sbi, sb1->sb_checksum) !=
0355             crc32_be(0, (char *)(bh1->b_data + 8), 504)) {
0356         pr_err("superblock #1 checksum error\n");
0357         goto out;
0358     }
0359 
0360     /* set new blocksize */
0361     if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
0362         pr_err("unable to set blocksize\n");
0363         goto out;
0364     }
0365     /* blocksize invalidates bh - pull it back in */
0366     brelse(bh1);
0367     bh1 = sb_bread(s, bootblock_offset >> s->s_blocksize_bits);
0368     if (!bh1)
0369         goto outnobh;
0370     sb1 = (struct qnx6_super_block *)bh1->b_data;
0371 
0372     /* calculate second superblock blocknumber */
0373     offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) +
0374         (bootblock_offset >> s->s_blocksize_bits) +
0375         (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
0376 
0377     /* set bootblock offset */
0378     sbi->s_blks_off = (bootblock_offset >> s->s_blocksize_bits) +
0379               (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
0380 
0381     /* next the second superblock */
0382     bh2 = sb_bread(s, offset);
0383     if (!bh2) {
0384         pr_err("unable to read the second superblock\n");
0385         goto out;
0386     }
0387     sb2 = (struct qnx6_super_block *)bh2->b_data;
0388     if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) {
0389         if (!silent)
0390             pr_err("wrong signature (magic) in superblock #2.\n");
0391         goto out;
0392     }
0393 
0394     /* checksum check - start at byte 8 and end at byte 512 */
0395     if (fs32_to_cpu(sbi, sb2->sb_checksum) !=
0396                 crc32_be(0, (char *)(bh2->b_data + 8), 504)) {
0397         pr_err("superblock #2 checksum error\n");
0398         goto out;
0399     }
0400 
0401     if (fs64_to_cpu(sbi, sb1->sb_serial) >=
0402                     fs64_to_cpu(sbi, sb2->sb_serial)) {
0403         /* superblock #1 active */
0404         sbi->sb_buf = bh1;
0405         sbi->sb = (struct qnx6_super_block *)bh1->b_data;
0406         brelse(bh2);
0407         pr_info("superblock #1 active\n");
0408     } else {
0409         /* superblock #2 active */
0410         sbi->sb_buf = bh2;
0411         sbi->sb = (struct qnx6_super_block *)bh2->b_data;
0412         brelse(bh1);
0413         pr_info("superblock #2 active\n");
0414     }
0415 mmi_success:
0416     /* sanity check - limit maximum indirect pointer levels */
0417     if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
0418         pr_err("too many inode levels (max %i, sb %i)\n",
0419                QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
0420         goto out;
0421     }
0422     if (sb1->Longfile.levels > QNX6_PTR_MAX_LEVELS) {
0423         pr_err("too many longfilename levels (max %i, sb %i)\n",
0424                QNX6_PTR_MAX_LEVELS, sb1->Longfile.levels);
0425         goto out;
0426     }
0427     s->s_op = &qnx6_sops;
0428     s->s_magic = QNX6_SUPER_MAGIC;
0429     s->s_flags |= SB_RDONLY;        /* Yup, read-only yet */
0430     s->s_time_min = 0;
0431     s->s_time_max = U32_MAX;
0432 
0433     /* ease the later tree level calculations */
0434     sbi = QNX6_SB(s);
0435     sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
0436     sbi->inodes = qnx6_private_inode(s, &sb1->Inode);
0437     if (!sbi->inodes)
0438         goto out;
0439     sbi->longfile = qnx6_private_inode(s, &sb1->Longfile);
0440     if (!sbi->longfile)
0441         goto out1;
0442 
0443     /* prefetch root inode */
0444     root = qnx6_iget(s, QNX6_ROOT_INO);
0445     if (IS_ERR(root)) {
0446         pr_err("get inode failed\n");
0447         ret = PTR_ERR(root);
0448         goto out2;
0449     }
0450 
0451     ret = -ENOMEM;
0452     s->s_root = d_make_root(root);
0453     if (!s->s_root)
0454         goto out2;
0455 
0456     ret = -EINVAL;
0457     errmsg = qnx6_checkroot(s);
0458     if (errmsg != NULL) {
0459         if (!silent)
0460             pr_err("%s\n", errmsg);
0461         goto out3;
0462     }
0463     return 0;
0464 
0465 out3:
0466     dput(s->s_root);
0467     s->s_root = NULL;
0468 out2:
0469     iput(sbi->longfile);
0470 out1:
0471     iput(sbi->inodes);
0472 out:
0473     if (bh1)
0474         brelse(bh1);
0475     if (bh2)
0476         brelse(bh2);
0477 outnobh:
0478     kfree(qs);
0479     s->s_fs_info = NULL;
0480     return ret;
0481 }
0482 
0483 static void qnx6_put_super(struct super_block *sb)
0484 {
0485     struct qnx6_sb_info *qs = QNX6_SB(sb);
0486     brelse(qs->sb_buf);
0487     iput(qs->longfile);
0488     iput(qs->inodes);
0489     kfree(qs);
0490     sb->s_fs_info = NULL;
0491     return;
0492 }
0493 
0494 static sector_t qnx6_bmap(struct address_space *mapping, sector_t block)
0495 {
0496     return generic_block_bmap(mapping, block, qnx6_get_block);
0497 }
0498 static const struct address_space_operations qnx6_aops = {
0499     .read_folio = qnx6_read_folio,
0500     .readahead  = qnx6_readahead,
0501     .bmap       = qnx6_bmap
0502 };
0503 
0504 static struct inode *qnx6_private_inode(struct super_block *s,
0505                     struct qnx6_root_node *p)
0506 {
0507     struct inode *inode = new_inode(s);
0508     if (inode) {
0509         struct qnx6_inode_info *ei = QNX6_I(inode);
0510         struct qnx6_sb_info *sbi = QNX6_SB(s);
0511         inode->i_size = fs64_to_cpu(sbi, p->size);
0512         memcpy(ei->di_block_ptr, p->ptr, sizeof(p->ptr));
0513         ei->di_filelevels = p->levels;
0514         inode->i_mode = S_IFREG | S_IRUSR; /* probably wrong */
0515         inode->i_mapping->a_ops = &qnx6_aops;
0516     }
0517     return inode;
0518 }
0519 
0520 struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
0521 {
0522     struct qnx6_sb_info *sbi = QNX6_SB(sb);
0523     struct qnx6_inode_entry *raw_inode;
0524     struct inode *inode;
0525     struct qnx6_inode_info  *ei;
0526     struct address_space *mapping;
0527     struct page *page;
0528     u32 n, offs;
0529 
0530     inode = iget_locked(sb, ino);
0531     if (!inode)
0532         return ERR_PTR(-ENOMEM);
0533     if (!(inode->i_state & I_NEW))
0534         return inode;
0535 
0536     ei = QNX6_I(inode);
0537 
0538     inode->i_mode = 0;
0539 
0540     if (ino == 0) {
0541         pr_err("bad inode number on dev %s: %u is out of range\n",
0542                sb->s_id, ino);
0543         iget_failed(inode);
0544         return ERR_PTR(-EIO);
0545     }
0546     n = (ino - 1) >> (PAGE_SHIFT - QNX6_INODE_SIZE_BITS);
0547     offs = (ino - 1) & (~PAGE_MASK >> QNX6_INODE_SIZE_BITS);
0548     mapping = sbi->inodes->i_mapping;
0549     page = read_mapping_page(mapping, n, NULL);
0550     if (IS_ERR(page)) {
0551         pr_err("major problem: unable to read inode from dev %s\n",
0552                sb->s_id);
0553         iget_failed(inode);
0554         return ERR_CAST(page);
0555     }
0556     kmap(page);
0557     raw_inode = ((struct qnx6_inode_entry *)page_address(page)) + offs;
0558 
0559     inode->i_mode    = fs16_to_cpu(sbi, raw_inode->di_mode);
0560     i_uid_write(inode, (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid));
0561     i_gid_write(inode, (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid));
0562     inode->i_size    = fs64_to_cpu(sbi, raw_inode->di_size);
0563     inode->i_mtime.tv_sec   = fs32_to_cpu(sbi, raw_inode->di_mtime);
0564     inode->i_mtime.tv_nsec = 0;
0565     inode->i_atime.tv_sec   = fs32_to_cpu(sbi, raw_inode->di_atime);
0566     inode->i_atime.tv_nsec = 0;
0567     inode->i_ctime.tv_sec   = fs32_to_cpu(sbi, raw_inode->di_ctime);
0568     inode->i_ctime.tv_nsec = 0;
0569 
0570     /* calc blocks based on 512 byte blocksize */
0571     inode->i_blocks = (inode->i_size + 511) >> 9;
0572 
0573     memcpy(&ei->di_block_ptr, &raw_inode->di_block_ptr,
0574                 sizeof(raw_inode->di_block_ptr));
0575     ei->di_filelevels = raw_inode->di_filelevels;
0576 
0577     if (S_ISREG(inode->i_mode)) {
0578         inode->i_fop = &generic_ro_fops;
0579         inode->i_mapping->a_ops = &qnx6_aops;
0580     } else if (S_ISDIR(inode->i_mode)) {
0581         inode->i_op = &qnx6_dir_inode_operations;
0582         inode->i_fop = &qnx6_dir_operations;
0583         inode->i_mapping->a_ops = &qnx6_aops;
0584     } else if (S_ISLNK(inode->i_mode)) {
0585         inode->i_op = &page_symlink_inode_operations;
0586         inode_nohighmem(inode);
0587         inode->i_mapping->a_ops = &qnx6_aops;
0588     } else
0589         init_special_inode(inode, inode->i_mode, 0);
0590     qnx6_put_page(page);
0591     unlock_new_inode(inode);
0592     return inode;
0593 }
0594 
0595 static struct kmem_cache *qnx6_inode_cachep;
0596 
0597 static struct inode *qnx6_alloc_inode(struct super_block *sb)
0598 {
0599     struct qnx6_inode_info *ei;
0600     ei = alloc_inode_sb(sb, qnx6_inode_cachep, GFP_KERNEL);
0601     if (!ei)
0602         return NULL;
0603     return &ei->vfs_inode;
0604 }
0605 
0606 static void qnx6_free_inode(struct inode *inode)
0607 {
0608     kmem_cache_free(qnx6_inode_cachep, QNX6_I(inode));
0609 }
0610 
0611 static void init_once(void *foo)
0612 {
0613     struct qnx6_inode_info *ei = (struct qnx6_inode_info *) foo;
0614 
0615     inode_init_once(&ei->vfs_inode);
0616 }
0617 
0618 static int init_inodecache(void)
0619 {
0620     qnx6_inode_cachep = kmem_cache_create("qnx6_inode_cache",
0621                          sizeof(struct qnx6_inode_info),
0622                          0, (SLAB_RECLAIM_ACCOUNT|
0623                         SLAB_MEM_SPREAD|SLAB_ACCOUNT),
0624                          init_once);
0625     if (!qnx6_inode_cachep)
0626         return -ENOMEM;
0627     return 0;
0628 }
0629 
0630 static void destroy_inodecache(void)
0631 {
0632     /*
0633      * Make sure all delayed rcu free inodes are flushed before we
0634      * destroy cache.
0635      */
0636     rcu_barrier();
0637     kmem_cache_destroy(qnx6_inode_cachep);
0638 }
0639 
0640 static struct dentry *qnx6_mount(struct file_system_type *fs_type,
0641     int flags, const char *dev_name, void *data)
0642 {
0643     return mount_bdev(fs_type, flags, dev_name, data, qnx6_fill_super);
0644 }
0645 
0646 static struct file_system_type qnx6_fs_type = {
0647     .owner      = THIS_MODULE,
0648     .name       = "qnx6",
0649     .mount      = qnx6_mount,
0650     .kill_sb    = kill_block_super,
0651     .fs_flags   = FS_REQUIRES_DEV,
0652 };
0653 MODULE_ALIAS_FS("qnx6");
0654 
0655 static int __init init_qnx6_fs(void)
0656 {
0657     int err;
0658 
0659     err = init_inodecache();
0660     if (err)
0661         return err;
0662 
0663     err = register_filesystem(&qnx6_fs_type);
0664     if (err) {
0665         destroy_inodecache();
0666         return err;
0667     }
0668 
0669     pr_info("QNX6 filesystem 1.0.0 registered.\n");
0670     return 0;
0671 }
0672 
0673 static void __exit exit_qnx6_fs(void)
0674 {
0675     unregister_filesystem(&qnx6_fs_type);
0676     destroy_inodecache();
0677 }
0678 
0679 module_init(init_qnx6_fs)
0680 module_exit(exit_qnx6_fs)
0681 MODULE_LICENSE("GPL");