inode.c 17 KB

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