inode.c 17 KB

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