inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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/seq_file.h>
  22. #include <linux/crc32.h>
  23. #include <linux/mpage.h>
  24. #include <linux/fs_parser.h>
  25. #include <linux/fs_context.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_reconfigure(struct fs_context *fc);
  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. .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_reconfigure(struct fs_context *fc)
  50. {
  51. struct super_block *sb = fc->root->d_sb;
  52. sync_filesystem(sb);
  53. fc->sb_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_read_folio(struct file *file, struct folio *folio)
  84. {
  85. return mpage_read_folio(folio, 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. int error = 0;
  156. struct qnx6_dir_entry *dir_entry;
  157. struct inode *root = d_inode(s->s_root);
  158. struct address_space *mapping = root->i_mapping;
  159. struct folio *folio = read_mapping_folio(mapping, 0, NULL);
  160. if (IS_ERR(folio))
  161. return "error reading root directory";
  162. dir_entry = kmap_local_folio(folio, 0);
  163. if (memcmp(dir_entry[0].de_fname, ".", 2) ||
  164. memcmp(dir_entry[1].de_fname, "..", 3))
  165. error = 1;
  166. folio_release_kmap(folio, dir_entry);
  167. if (error)
  168. return "error reading root directory.";
  169. return NULL;
  170. }
  171. #ifdef CONFIG_QNX6FS_DEBUG
  172. void qnx6_superblock_debug(struct qnx6_super_block *sb, struct super_block *s)
  173. {
  174. struct qnx6_sb_info *sbi = QNX6_SB(s);
  175. pr_debug("magic: %08x\n", fs32_to_cpu(sbi, sb->sb_magic));
  176. pr_debug("checksum: %08x\n", fs32_to_cpu(sbi, sb->sb_checksum));
  177. pr_debug("serial: %llx\n", fs64_to_cpu(sbi, sb->sb_serial));
  178. pr_debug("flags: %08x\n", fs32_to_cpu(sbi, sb->sb_flags));
  179. pr_debug("blocksize: %08x\n", fs32_to_cpu(sbi, sb->sb_blocksize));
  180. pr_debug("num_inodes: %08x\n", fs32_to_cpu(sbi, sb->sb_num_inodes));
  181. pr_debug("free_inodes: %08x\n", fs32_to_cpu(sbi, sb->sb_free_inodes));
  182. pr_debug("num_blocks: %08x\n", fs32_to_cpu(sbi, sb->sb_num_blocks));
  183. pr_debug("free_blocks: %08x\n", fs32_to_cpu(sbi, sb->sb_free_blocks));
  184. pr_debug("inode_levels: %02x\n", sb->Inode.levels);
  185. }
  186. #endif
  187. enum {
  188. Opt_mmifs
  189. };
  190. struct qnx6_context {
  191. unsigned long s_mount_opts;
  192. };
  193. static const struct fs_parameter_spec qnx6_param_spec[] = {
  194. fsparam_flag ("mmi_fs", Opt_mmifs),
  195. {}
  196. };
  197. static int qnx6_parse_param(struct fs_context *fc, struct fs_parameter *param)
  198. {
  199. struct qnx6_context *ctx = fc->fs_private;
  200. struct fs_parse_result result;
  201. int opt;
  202. opt = fs_parse(fc, qnx6_param_spec, param, &result);
  203. if (opt < 0)
  204. return opt;
  205. switch (opt) {
  206. case Opt_mmifs:
  207. ctx->s_mount_opts |= QNX6_MOUNT_MMI_FS;
  208. break;
  209. default:
  210. return -EINVAL;
  211. }
  212. return 0;
  213. }
  214. static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
  215. int offset, int silent)
  216. {
  217. struct qnx6_sb_info *sbi = QNX6_SB(s);
  218. struct buffer_head *bh;
  219. struct qnx6_super_block *sb;
  220. /* Check the superblock signatures
  221. start with the first superblock */
  222. bh = sb_bread(s, offset);
  223. if (!bh) {
  224. pr_err("unable to read the first superblock\n");
  225. return NULL;
  226. }
  227. sb = (struct qnx6_super_block *)bh->b_data;
  228. if (fs32_to_cpu(sbi, sb->sb_magic) != QNX6_SUPER_MAGIC) {
  229. sbi->s_bytesex = BYTESEX_BE;
  230. if (fs32_to_cpu(sbi, sb->sb_magic) == QNX6_SUPER_MAGIC) {
  231. /* we got a big endian fs */
  232. pr_debug("fs got different endianness.\n");
  233. return bh;
  234. } else
  235. sbi->s_bytesex = BYTESEX_LE;
  236. if (!silent) {
  237. if (offset == 0) {
  238. pr_err("wrong signature (magic) in superblock #1.\n");
  239. } else {
  240. pr_info("wrong signature (magic) at position (0x%lx) - will try alternative position (0x0000).\n",
  241. offset * s->s_blocksize);
  242. }
  243. }
  244. brelse(bh);
  245. return NULL;
  246. }
  247. return bh;
  248. }
  249. static struct inode *qnx6_private_inode(struct super_block *s,
  250. struct qnx6_root_node *p);
  251. static int qnx6_fill_super(struct super_block *s, struct fs_context *fc)
  252. {
  253. struct buffer_head *bh1 = NULL, *bh2 = NULL;
  254. struct qnx6_super_block *sb1 = NULL, *sb2 = NULL;
  255. struct qnx6_sb_info *sbi;
  256. struct qnx6_context *ctx = fc->fs_private;
  257. struct inode *root;
  258. const char *errmsg;
  259. struct qnx6_sb_info *qs;
  260. int ret = -EINVAL;
  261. u64 offset;
  262. int bootblock_offset = QNX6_BOOTBLOCK_SIZE;
  263. int silent = fc->sb_flags & SB_SILENT;
  264. qs = kzalloc(sizeof(struct qnx6_sb_info), GFP_KERNEL);
  265. if (!qs)
  266. return -ENOMEM;
  267. s->s_fs_info = qs;
  268. qs->s_mount_opt = ctx->s_mount_opts;
  269. /* Superblock always is 512 Byte long */
  270. if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
  271. pr_err("unable to set blocksize\n");
  272. goto outnobh;
  273. }
  274. if (qs->s_mount_opt == QNX6_MOUNT_MMI_FS) {
  275. sb1 = qnx6_mmi_fill_super(s, silent);
  276. if (sb1)
  277. goto mmi_success;
  278. else
  279. goto outnobh;
  280. }
  281. sbi = QNX6_SB(s);
  282. sbi->s_bytesex = BYTESEX_LE;
  283. /* Check the superblock signatures
  284. start with the first superblock */
  285. bh1 = qnx6_check_first_superblock(s,
  286. bootblock_offset / QNX6_SUPERBLOCK_SIZE, silent);
  287. if (!bh1) {
  288. /* try again without bootblock offset */
  289. bh1 = qnx6_check_first_superblock(s, 0, silent);
  290. if (!bh1) {
  291. pr_err("unable to read the first superblock\n");
  292. goto outnobh;
  293. }
  294. /* seems that no bootblock at partition start */
  295. bootblock_offset = 0;
  296. }
  297. sb1 = (struct qnx6_super_block *)bh1->b_data;
  298. #ifdef CONFIG_QNX6FS_DEBUG
  299. qnx6_superblock_debug(sb1, s);
  300. #endif
  301. /* checksum check - start at byte 8 and end at byte 512 */
  302. if (fs32_to_cpu(sbi, sb1->sb_checksum) !=
  303. crc32_be(0, (char *)(bh1->b_data + 8), 504)) {
  304. pr_err("superblock #1 checksum error\n");
  305. goto out;
  306. }
  307. /* set new blocksize */
  308. if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
  309. pr_err("unable to set blocksize\n");
  310. goto out;
  311. }
  312. /* blocksize invalidates bh - pull it back in */
  313. brelse(bh1);
  314. bh1 = sb_bread(s, bootblock_offset >> s->s_blocksize_bits);
  315. if (!bh1)
  316. goto outnobh;
  317. sb1 = (struct qnx6_super_block *)bh1->b_data;
  318. /* calculate second superblock blocknumber */
  319. offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) +
  320. (bootblock_offset >> s->s_blocksize_bits) +
  321. (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
  322. /* set bootblock offset */
  323. sbi->s_blks_off = (bootblock_offset >> s->s_blocksize_bits) +
  324. (QNX6_SUPERBLOCK_AREA >> s->s_blocksize_bits);
  325. /* next the second superblock */
  326. bh2 = sb_bread(s, offset);
  327. if (!bh2) {
  328. pr_err("unable to read the second superblock\n");
  329. goto out;
  330. }
  331. sb2 = (struct qnx6_super_block *)bh2->b_data;
  332. if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) {
  333. if (!silent)
  334. pr_err("wrong signature (magic) in superblock #2.\n");
  335. goto out;
  336. }
  337. /* checksum check - start at byte 8 and end at byte 512 */
  338. if (fs32_to_cpu(sbi, sb2->sb_checksum) !=
  339. crc32_be(0, (char *)(bh2->b_data + 8), 504)) {
  340. pr_err("superblock #2 checksum error\n");
  341. goto out;
  342. }
  343. if (fs64_to_cpu(sbi, sb1->sb_serial) >=
  344. fs64_to_cpu(sbi, sb2->sb_serial)) {
  345. /* superblock #1 active */
  346. sbi->sb_buf = bh1;
  347. sbi->sb = (struct qnx6_super_block *)bh1->b_data;
  348. brelse(bh2);
  349. pr_info("superblock #1 active\n");
  350. } else {
  351. /* superblock #2 active */
  352. sbi->sb_buf = bh2;
  353. sbi->sb = (struct qnx6_super_block *)bh2->b_data;
  354. brelse(bh1);
  355. pr_info("superblock #2 active\n");
  356. }
  357. mmi_success:
  358. /* sanity check - limit maximum indirect pointer levels */
  359. if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
  360. pr_err("too many inode levels (max %i, sb %i)\n",
  361. QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
  362. goto out;
  363. }
  364. if (sb1->Longfile.levels > QNX6_PTR_MAX_LEVELS) {
  365. pr_err("too many longfilename levels (max %i, sb %i)\n",
  366. QNX6_PTR_MAX_LEVELS, sb1->Longfile.levels);
  367. goto out;
  368. }
  369. s->s_op = &qnx6_sops;
  370. s->s_magic = QNX6_SUPER_MAGIC;
  371. s->s_flags |= SB_RDONLY; /* Yup, read-only yet */
  372. s->s_time_min = 0;
  373. s->s_time_max = U32_MAX;
  374. /* ease the later tree level calculations */
  375. sbi = QNX6_SB(s);
  376. sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
  377. sbi->inodes = qnx6_private_inode(s, &sb1->Inode);
  378. if (!sbi->inodes)
  379. goto out;
  380. sbi->longfile = qnx6_private_inode(s, &sb1->Longfile);
  381. if (!sbi->longfile)
  382. goto out1;
  383. /* prefetch root inode */
  384. root = qnx6_iget(s, QNX6_ROOT_INO);
  385. if (IS_ERR(root)) {
  386. pr_err("get inode failed\n");
  387. ret = PTR_ERR(root);
  388. goto out2;
  389. }
  390. ret = -ENOMEM;
  391. s->s_root = d_make_root(root);
  392. if (!s->s_root)
  393. goto out2;
  394. ret = -EINVAL;
  395. errmsg = qnx6_checkroot(s);
  396. if (errmsg != NULL) {
  397. if (!silent)
  398. pr_err("%s\n", errmsg);
  399. goto out3;
  400. }
  401. return 0;
  402. out3:
  403. dput(s->s_root);
  404. s->s_root = NULL;
  405. out2:
  406. iput(sbi->longfile);
  407. out1:
  408. iput(sbi->inodes);
  409. out:
  410. brelse(bh1);
  411. brelse(bh2);
  412. outnobh:
  413. kfree(qs);
  414. s->s_fs_info = NULL;
  415. return ret;
  416. }
  417. static void qnx6_put_super(struct super_block *sb)
  418. {
  419. struct qnx6_sb_info *qs = QNX6_SB(sb);
  420. brelse(qs->sb_buf);
  421. iput(qs->longfile);
  422. iput(qs->inodes);
  423. kfree(qs);
  424. sb->s_fs_info = NULL;
  425. return;
  426. }
  427. static sector_t qnx6_bmap(struct address_space *mapping, sector_t block)
  428. {
  429. return generic_block_bmap(mapping, block, qnx6_get_block);
  430. }
  431. static const struct address_space_operations qnx6_aops = {
  432. .read_folio = qnx6_read_folio,
  433. .readahead = qnx6_readahead,
  434. .bmap = qnx6_bmap
  435. };
  436. static struct inode *qnx6_private_inode(struct super_block *s,
  437. struct qnx6_root_node *p)
  438. {
  439. struct inode *inode = new_inode(s);
  440. if (inode) {
  441. struct qnx6_inode_info *ei = QNX6_I(inode);
  442. struct qnx6_sb_info *sbi = QNX6_SB(s);
  443. inode->i_size = fs64_to_cpu(sbi, p->size);
  444. memcpy(ei->di_block_ptr, p->ptr, sizeof(p->ptr));
  445. ei->di_filelevels = p->levels;
  446. inode->i_mode = S_IFREG | S_IRUSR; /* probably wrong */
  447. inode->i_mapping->a_ops = &qnx6_aops;
  448. }
  449. return inode;
  450. }
  451. struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
  452. {
  453. struct qnx6_sb_info *sbi = QNX6_SB(sb);
  454. struct qnx6_inode_entry *raw_inode;
  455. struct inode *inode;
  456. struct qnx6_inode_info *ei;
  457. struct address_space *mapping;
  458. struct folio *folio;
  459. u32 n, offs;
  460. inode = iget_locked(sb, ino);
  461. if (!inode)
  462. return ERR_PTR(-ENOMEM);
  463. if (!(inode->i_state & I_NEW))
  464. return inode;
  465. ei = QNX6_I(inode);
  466. inode->i_mode = 0;
  467. if (ino == 0) {
  468. pr_err("bad inode number on dev %s: %u is out of range\n",
  469. sb->s_id, ino);
  470. iget_failed(inode);
  471. return ERR_PTR(-EIO);
  472. }
  473. n = (ino - 1) >> (PAGE_SHIFT - QNX6_INODE_SIZE_BITS);
  474. mapping = sbi->inodes->i_mapping;
  475. folio = read_mapping_folio(mapping, n, NULL);
  476. if (IS_ERR(folio)) {
  477. pr_err("major problem: unable to read inode from dev %s\n",
  478. sb->s_id);
  479. iget_failed(inode);
  480. return ERR_CAST(folio);
  481. }
  482. offs = offset_in_folio(folio, (ino - 1) << QNX6_INODE_SIZE_BITS);
  483. raw_inode = kmap_local_folio(folio, offs);
  484. inode->i_mode = fs16_to_cpu(sbi, raw_inode->di_mode);
  485. i_uid_write(inode, (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid));
  486. i_gid_write(inode, (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid));
  487. inode->i_size = fs64_to_cpu(sbi, raw_inode->di_size);
  488. inode_set_mtime(inode, fs32_to_cpu(sbi, raw_inode->di_mtime), 0);
  489. inode_set_atime(inode, fs32_to_cpu(sbi, raw_inode->di_atime), 0);
  490. inode_set_ctime(inode, fs32_to_cpu(sbi, raw_inode->di_ctime), 0);
  491. /* calc blocks based on 512 byte blocksize */
  492. inode->i_blocks = (inode->i_size + 511) >> 9;
  493. memcpy(&ei->di_block_ptr, &raw_inode->di_block_ptr,
  494. sizeof(raw_inode->di_block_ptr));
  495. ei->di_filelevels = raw_inode->di_filelevels;
  496. if (S_ISREG(inode->i_mode)) {
  497. inode->i_fop = &generic_ro_fops;
  498. inode->i_mapping->a_ops = &qnx6_aops;
  499. } else if (S_ISDIR(inode->i_mode)) {
  500. inode->i_op = &qnx6_dir_inode_operations;
  501. inode->i_fop = &qnx6_dir_operations;
  502. inode->i_mapping->a_ops = &qnx6_aops;
  503. } else if (S_ISLNK(inode->i_mode)) {
  504. inode->i_op = &page_symlink_inode_operations;
  505. inode_nohighmem(inode);
  506. inode->i_mapping->a_ops = &qnx6_aops;
  507. } else
  508. init_special_inode(inode, inode->i_mode, 0);
  509. folio_release_kmap(folio, raw_inode);
  510. unlock_new_inode(inode);
  511. return inode;
  512. }
  513. static struct kmem_cache *qnx6_inode_cachep;
  514. static struct inode *qnx6_alloc_inode(struct super_block *sb)
  515. {
  516. struct qnx6_inode_info *ei;
  517. ei = alloc_inode_sb(sb, qnx6_inode_cachep, GFP_KERNEL);
  518. if (!ei)
  519. return NULL;
  520. return &ei->vfs_inode;
  521. }
  522. static void qnx6_free_inode(struct inode *inode)
  523. {
  524. kmem_cache_free(qnx6_inode_cachep, QNX6_I(inode));
  525. }
  526. static void init_once(void *foo)
  527. {
  528. struct qnx6_inode_info *ei = (struct qnx6_inode_info *) foo;
  529. inode_init_once(&ei->vfs_inode);
  530. }
  531. static int init_inodecache(void)
  532. {
  533. qnx6_inode_cachep = kmem_cache_create("qnx6_inode_cache",
  534. sizeof(struct qnx6_inode_info),
  535. 0, (SLAB_RECLAIM_ACCOUNT|
  536. SLAB_ACCOUNT),
  537. init_once);
  538. if (!qnx6_inode_cachep)
  539. return -ENOMEM;
  540. return 0;
  541. }
  542. static void destroy_inodecache(void)
  543. {
  544. /*
  545. * Make sure all delayed rcu free inodes are flushed before we
  546. * destroy cache.
  547. */
  548. rcu_barrier();
  549. kmem_cache_destroy(qnx6_inode_cachep);
  550. }
  551. static int qnx6_get_tree(struct fs_context *fc)
  552. {
  553. return get_tree_bdev(fc, qnx6_fill_super);
  554. }
  555. static void qnx6_free_fc(struct fs_context *fc)
  556. {
  557. kfree(fc->fs_private);
  558. }
  559. static const struct fs_context_operations qnx6_context_ops = {
  560. .parse_param = qnx6_parse_param,
  561. .get_tree = qnx6_get_tree,
  562. .reconfigure = qnx6_reconfigure,
  563. .free = qnx6_free_fc,
  564. };
  565. static int qnx6_init_fs_context(struct fs_context *fc)
  566. {
  567. struct qnx6_context *ctx;
  568. ctx = kzalloc(sizeof(struct qnx6_context), GFP_KERNEL);
  569. if (!ctx)
  570. return -ENOMEM;
  571. fc->ops = &qnx6_context_ops;
  572. fc->fs_private = ctx;
  573. return 0;
  574. }
  575. static struct file_system_type qnx6_fs_type = {
  576. .owner = THIS_MODULE,
  577. .name = "qnx6",
  578. .kill_sb = kill_block_super,
  579. .fs_flags = FS_REQUIRES_DEV,
  580. .init_fs_context = qnx6_init_fs_context,
  581. .parameters = qnx6_param_spec,
  582. };
  583. MODULE_ALIAS_FS("qnx6");
  584. static int __init init_qnx6_fs(void)
  585. {
  586. int err;
  587. err = init_inodecache();
  588. if (err)
  589. return err;
  590. err = register_filesystem(&qnx6_fs_type);
  591. if (err) {
  592. destroy_inodecache();
  593. return err;
  594. }
  595. pr_info("QNX6 filesystem 1.0.0 registered.\n");
  596. return 0;
  597. }
  598. static void __exit exit_qnx6_fs(void)
  599. {
  600. unregister_filesystem(&qnx6_fs_type);
  601. destroy_inodecache();
  602. }
  603. module_init(init_qnx6_fs)
  604. module_exit(exit_qnx6_fs)
  605. MODULE_DESCRIPTION("QNX6 file system");
  606. MODULE_LICENSE("GPL");