inode.c 18 KB

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