Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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