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