Blame view

fs/omfs/inode.c 13.3 KB
555e3775c   Bob Copeland   omfs: add inode r...
1
2
3
4
5
  /*
   * Optimized MPEG FS - inode and super operations.
   * Copyright (C) 2006 Bob Copeland <me@bobcopeland.com>
   * Released under GPL v2.
   */
555e3775c   Bob Copeland   omfs: add inode r...
6
7
  #include <linux/module.h>
  #include <linux/sched.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
8
  #include <linux/slab.h>
555e3775c   Bob Copeland   omfs: add inode r...
9
10
11
12
13
  #include <linux/fs.h>
  #include <linux/vfs.h>
  #include <linux/parser.h>
  #include <linux/buffer_head.h>
  #include <linux/vmalloc.h>
a9185b41a   Christoph Hellwig   pass writeback_co...
14
  #include <linux/writeback.h>
555e3775c   Bob Copeland   omfs: add inode r...
15
16
17
18
19
20
  #include <linux/crc-itu-t.h>
  #include "omfs.h"
  
  MODULE_AUTHOR("Bob Copeland <me@bobcopeland.com>");
  MODULE_DESCRIPTION("OMFS (ReplayTV/Karma) Filesystem for Linux");
  MODULE_LICENSE("GPL");
f068272cb   Bob Copeland   omfs: check bound...
21
22
23
24
25
26
27
28
  struct buffer_head *omfs_bread(struct super_block *sb, sector_t block)
  {
  	struct omfs_sb_info *sbi = OMFS_SB(sb);
  	if (block >= sbi->s_num_blocks)
  		return NULL;
  
  	return sb_bread(sb, clus_to_blk(sbi, block));
  }
587228be4   Al Viro   omfs: propagate u...
29
  struct inode *omfs_new_inode(struct inode *dir, umode_t mode)
555e3775c   Bob Copeland   omfs: add inode r...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  {
  	struct inode *inode;
  	u64 new_block;
  	int err;
  	int len;
  	struct omfs_sb_info *sbi = OMFS_SB(dir->i_sb);
  
  	inode = new_inode(dir->i_sb);
  	if (!inode)
  		return ERR_PTR(-ENOMEM);
  
  	err = omfs_allocate_range(dir->i_sb, sbi->s_mirrors, sbi->s_mirrors,
  			&new_block, &len);
  	if (err)
  		goto fail;
  
  	inode->i_ino = new_block;
6a9e652c8   Dmitry Monakhov   omfs: replace ino...
47
  	inode_init_owner(inode, NULL, mode);
555e3775c   Bob Copeland   omfs: add inode r...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  	inode->i_mapping->a_ops = &omfs_aops;
  
  	inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  	switch (mode & S_IFMT) {
  	case S_IFDIR:
  		inode->i_op = &omfs_dir_inops;
  		inode->i_fop = &omfs_dir_operations;
  		inode->i_size = sbi->s_sys_blocksize;
  		inc_nlink(inode);
  		break;
  	case S_IFREG:
  		inode->i_op = &omfs_file_inops;
  		inode->i_fop = &omfs_file_operations;
  		inode->i_size = 0;
  		break;
  	}
  
  	insert_inode_hash(inode);
  	mark_inode_dirty(inode);
  	return inode;
  fail:
  	make_bad_inode(inode);
  	iput(inode);
  	return ERR_PTR(err);
  }
  
  /*
   * Update the header checksums for a dirty inode based on its contents.
   * Caller is expected to hold the buffer head underlying oi and mark it
   * dirty.
   */
  static void omfs_update_checksums(struct omfs_inode *oi)
  {
  	int xor, i, ofs = 0, count;
  	u16 crc = 0;
  	unsigned char *ptr = (unsigned char *) oi;
  
  	count = be32_to_cpu(oi->i_head.h_body_size);
  	ofs = sizeof(struct omfs_header);
  
  	crc = crc_itu_t(crc, ptr + ofs, count);
  	oi->i_head.h_crc = cpu_to_be16(crc);
  
  	xor = ptr[0];
  	for (i = 1; i < OMFS_XOR_COUNT; i++)
  		xor ^= ptr[i];
  
  	oi->i_head.h_check_xor = xor;
  }
a9185b41a   Christoph Hellwig   pass writeback_co...
97
  static int __omfs_write_inode(struct inode *inode, int wait)
555e3775c   Bob Copeland   omfs: add inode r...
98
99
100
101
  {
  	struct omfs_inode *oi;
  	struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
  	struct buffer_head *bh, *bh2;
555e3775c   Bob Copeland   omfs: add inode r...
102
103
104
105
106
107
  	u64 ctime;
  	int i;
  	int ret = -EIO;
  	int sync_failed = 0;
  
  	/* get current inode since we may have written sibling ptrs etc. */
f068272cb   Bob Copeland   omfs: check bound...
108
  	bh = omfs_bread(inode->i_sb, inode->i_ino);
555e3775c   Bob Copeland   omfs: add inode r...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  	if (!bh)
  		goto out;
  
  	oi = (struct omfs_inode *) bh->b_data;
  
  	oi->i_head.h_self = cpu_to_be64(inode->i_ino);
  	if (S_ISDIR(inode->i_mode))
  		oi->i_type = OMFS_DIR;
  	else if (S_ISREG(inode->i_mode))
  		oi->i_type = OMFS_FILE;
  	else {
  		printk(KERN_WARNING "omfs: unknown file type: %d
  ",
  			inode->i_mode);
  		goto out_brelse;
  	}
  
  	oi->i_head.h_body_size = cpu_to_be32(sbi->s_sys_blocksize -
  		sizeof(struct omfs_header));
  	oi->i_head.h_version = 1;
  	oi->i_head.h_type = OMFS_INODE_NORMAL;
  	oi->i_head.h_magic = OMFS_IMAGIC;
  	oi->i_size = cpu_to_be64(inode->i_size);
  
  	ctime = inode->i_ctime.tv_sec * 1000LL +
  		((inode->i_ctime.tv_nsec + 999)/1000);
  	oi->i_ctime = cpu_to_be64(ctime);
  
  	omfs_update_checksums(oi);
  
  	mark_buffer_dirty(bh);
  	if (wait) {
  		sync_dirty_buffer(bh);
  		if (buffer_req(bh) && !buffer_uptodate(bh))
  			sync_failed = 1;
  	}
  
  	/* if mirroring writes, copy to next fsblock */
  	for (i = 1; i < sbi->s_mirrors; i++) {
f068272cb   Bob Copeland   omfs: check bound...
148
  		bh2 = omfs_bread(inode->i_sb, inode->i_ino + i);
555e3775c   Bob Copeland   omfs: add inode r...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  		if (!bh2)
  			goto out_brelse;
  
  		memcpy(bh2->b_data, bh->b_data, bh->b_size);
  		mark_buffer_dirty(bh2);
  		if (wait) {
  			sync_dirty_buffer(bh2);
  			if (buffer_req(bh2) && !buffer_uptodate(bh2))
  				sync_failed = 1;
  		}
  		brelse(bh2);
  	}
  	ret = (sync_failed) ? -EIO : 0;
  out_brelse:
  	brelse(bh);
  out:
  	return ret;
  }
a9185b41a   Christoph Hellwig   pass writeback_co...
167
168
169
170
  static int omfs_write_inode(struct inode *inode, struct writeback_control *wbc)
  {
  	return __omfs_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
  }
555e3775c   Bob Copeland   omfs: add inode r...
171
172
  int omfs_sync_inode(struct inode *inode)
  {
a9185b41a   Christoph Hellwig   pass writeback_co...
173
  	return __omfs_write_inode(inode, 1);
555e3775c   Bob Copeland   omfs: add inode r...
174
175
176
177
178
179
  }
  
  /*
   * called when an entry is deleted, need to clear the bits in the
   * bitmaps.
   */
69c9e7501   Al Viro   switch omfs to ->...
180
  static void omfs_evict_inode(struct inode *inode)
555e3775c   Bob Copeland   omfs: add inode r...
181
182
  {
  	truncate_inode_pages(&inode->i_data, 0);
69c9e7501   Al Viro   switch omfs to ->...
183
184
185
186
  	end_writeback(inode);
  
  	if (inode->i_nlink)
  		return;
555e3775c   Bob Copeland   omfs: add inode r...
187
188
189
190
191
192
193
  
  	if (S_ISREG(inode->i_mode)) {
  		inode->i_size = 0;
  		omfs_shrink_inode(inode);
  	}
  
  	omfs_clear_range(inode->i_sb, inode->i_ino, 2);
555e3775c   Bob Copeland   omfs: add inode r...
194
195
196
197
198
199
200
  }
  
  struct inode *omfs_iget(struct super_block *sb, ino_t ino)
  {
  	struct omfs_sb_info *sbi = OMFS_SB(sb);
  	struct omfs_inode *oi;
  	struct buffer_head *bh;
555e3775c   Bob Copeland   omfs: add inode r...
201
202
203
204
205
206
207
208
209
  	u64 ctime;
  	unsigned long nsecs;
  	struct inode *inode;
  
  	inode = iget_locked(sb, ino);
  	if (!inode)
  		return ERR_PTR(-ENOMEM);
  	if (!(inode->i_state & I_NEW))
  		return inode;
f068272cb   Bob Copeland   omfs: check bound...
210
  	bh = omfs_bread(inode->i_sb, ino);
555e3775c   Bob Copeland   omfs: add inode r...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  	if (!bh)
  		goto iget_failed;
  
  	oi = (struct omfs_inode *)bh->b_data;
  
  	/* check self */
  	if (ino != be64_to_cpu(oi->i_head.h_self))
  		goto fail_bh;
  
  	inode->i_uid = sbi->s_uid;
  	inode->i_gid = sbi->s_gid;
  
  	ctime = be64_to_cpu(oi->i_ctime);
  	nsecs = do_div(ctime, 1000) * 1000L;
  
  	inode->i_atime.tv_sec = ctime;
  	inode->i_mtime.tv_sec = ctime;
  	inode->i_ctime.tv_sec = ctime;
  	inode->i_atime.tv_nsec = nsecs;
  	inode->i_mtime.tv_nsec = nsecs;
  	inode->i_ctime.tv_nsec = nsecs;
  
  	inode->i_mapping->a_ops = &omfs_aops;
  
  	switch (oi->i_type) {
  	case OMFS_DIR:
  		inode->i_mode = S_IFDIR | (S_IRWXUGO & ~sbi->s_dmask);
  		inode->i_op = &omfs_dir_inops;
  		inode->i_fop = &omfs_dir_operations;
c963343a1   Bob Copeland   omfs: fix potenti...
240
  		inode->i_size = sbi->s_sys_blocksize;
555e3775c   Bob Copeland   omfs: add inode r...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
  		inc_nlink(inode);
  		break;
  	case OMFS_FILE:
  		inode->i_mode = S_IFREG | (S_IRWXUGO & ~sbi->s_fmask);
  		inode->i_fop = &omfs_file_operations;
  		inode->i_size = be64_to_cpu(oi->i_size);
  		break;
  	}
  	brelse(bh);
  	unlock_new_inode(inode);
  	return inode;
  fail_bh:
  	brelse(bh);
  iget_failed:
  	iget_failed(inode);
  	return ERR_PTR(-EIO);
  }
  
  static void omfs_put_super(struct super_block *sb)
  {
  	struct omfs_sb_info *sbi = OMFS_SB(sb);
  	kfree(sbi->s_imap);
  	kfree(sbi);
  	sb->s_fs_info = NULL;
  }
  
  static int omfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  {
  	struct super_block *s = dentry->d_sb;
  	struct omfs_sb_info *sbi = OMFS_SB(s);
197e671ee   Coly Li   fs/omfs: return f...
271
  	u64 id = huge_encode_dev(s->s_bdev->bd_dev);
555e3775c   Bob Copeland   omfs: add inode r...
272
273
274
275
276
  	buf->f_type = OMFS_MAGIC;
  	buf->f_bsize = sbi->s_blocksize;
  	buf->f_blocks = sbi->s_num_blocks;
  	buf->f_files = sbi->s_num_blocks;
  	buf->f_namelen = OMFS_NAMELEN;
197e671ee   Coly Li   fs/omfs: return f...
277
278
  	buf->f_fsid.val[0] = (u32)id;
  	buf->f_fsid.val[1] = (u32)(id >> 32);
555e3775c   Bob Copeland   omfs: add inode r...
279
280
281
  
  	buf->f_bfree = buf->f_bavail = buf->f_ffree =
  		omfs_count_free(s);
197e671ee   Coly Li   fs/omfs: return f...
282

555e3775c   Bob Copeland   omfs: add inode r...
283
284
  	return 0;
  }
b87221de6   Alexey Dobriyan   const: mark remai...
285
  static const struct super_operations omfs_sops = {
555e3775c   Bob Copeland   omfs: add inode r...
286
  	.write_inode	= omfs_write_inode,
69c9e7501   Al Viro   switch omfs to ->...
287
  	.evict_inode	= omfs_evict_inode,
555e3775c   Bob Copeland   omfs: add inode r...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  	.put_super	= omfs_put_super,
  	.statfs		= omfs_statfs,
  	.show_options	= generic_show_options,
  };
  
  /*
   * For Rio Karma, there is an on-disk free bitmap whose location is
   * stored in the root block.  For ReplayTV, there is no such free bitmap
   * so we have to walk the tree.  Both inodes and file data are allocated
   * from the same map.  This array can be big (300k) so we allocate
   * in units of the blocksize.
   */
  static int omfs_get_imap(struct super_block *sb)
  {
  	int bitmap_size;
  	int array_size;
  	int count;
  	struct omfs_sb_info *sbi = OMFS_SB(sb);
  	struct buffer_head *bh;
  	unsigned long **ptr;
  	sector_t block;
  
  	bitmap_size = DIV_ROUND_UP(sbi->s_num_blocks, 8);
  	array_size = DIV_ROUND_UP(bitmap_size, sb->s_blocksize);
  
  	if (sbi->s_bitmap_ino == ~0ULL)
  		goto out;
  
  	sbi->s_imap_size = array_size;
  	sbi->s_imap = kzalloc(array_size * sizeof(unsigned long *), GFP_KERNEL);
  	if (!sbi->s_imap)
  		goto nomem;
  
  	block = clus_to_blk(sbi, sbi->s_bitmap_ino);
f068272cb   Bob Copeland   omfs: check bound...
322
323
  	if (block >= sbi->s_num_blocks)
  		goto nomem;
555e3775c   Bob Copeland   omfs: add inode r...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
  	ptr = sbi->s_imap;
  	for (count = bitmap_size; count > 0; count -= sb->s_blocksize) {
  		bh = sb_bread(sb, block++);
  		if (!bh)
  			goto nomem_free;
  		*ptr = kmalloc(sb->s_blocksize, GFP_KERNEL);
  		if (!*ptr) {
  			brelse(bh);
  			goto nomem_free;
  		}
  		memcpy(*ptr, bh->b_data, sb->s_blocksize);
  		if (count < sb->s_blocksize)
  			memset((void *)*ptr + count, 0xff,
  				sb->s_blocksize - count);
  		brelse(bh);
  		ptr++;
  	}
  out:
  	return 0;
  
  nomem_free:
  	for (count = 0; count < array_size; count++)
  		kfree(sbi->s_imap[count]);
  
  	kfree(sbi->s_imap);
  nomem:
  	sbi->s_imap = NULL;
  	sbi->s_imap_size = 0;
  	return -ENOMEM;
  }
  
  enum {
  	Opt_uid, Opt_gid, Opt_umask, Opt_dmask, Opt_fmask
  };
a447c0932   Steven Whitehouse   vfs: Use const fo...
358
  static const match_table_t tokens = {
555e3775c   Bob Copeland   omfs: add inode r...
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
  	{Opt_uid, "uid=%u"},
  	{Opt_gid, "gid=%u"},
  	{Opt_umask, "umask=%o"},
  	{Opt_dmask, "dmask=%o"},
  	{Opt_fmask, "fmask=%o"},
  };
  
  static int parse_options(char *options, struct omfs_sb_info *sbi)
  {
  	char *p;
  	substring_t args[MAX_OPT_ARGS];
  	int option;
  
  	if (!options)
  		return 1;
  
  	while ((p = strsep(&options, ",")) != NULL) {
  		int token;
  		if (!*p)
  			continue;
  
  		token = match_token(p, tokens, args);
  		switch (token) {
  		case Opt_uid:
  			if (match_int(&args[0], &option))
  				return 0;
  			sbi->s_uid = option;
  			break;
  		case Opt_gid:
  			if (match_int(&args[0], &option))
  				return 0;
  			sbi->s_gid = option;
  			break;
  		case Opt_umask:
  			if (match_octal(&args[0], &option))
  				return 0;
  			sbi->s_fmask = sbi->s_dmask = option;
  			break;
  		case Opt_dmask:
  			if (match_octal(&args[0], &option))
  				return 0;
  			sbi->s_dmask = option;
  			break;
  		case Opt_fmask:
  			if (match_octal(&args[0], &option))
  				return 0;
  			sbi->s_fmask = option;
  			break;
  		default:
  			return 0;
  		}
  	}
  	return 1;
  }
  
  static int omfs_fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct buffer_head *bh, *bh2;
  	struct omfs_super_block *omfs_sb;
  	struct omfs_root_block *omfs_rb;
  	struct omfs_sb_info *sbi;
  	struct inode *root;
555e3775c   Bob Copeland   omfs: add inode r...
421
422
423
424
425
426
427
428
429
  	int ret = -EINVAL;
  
  	save_mount_options(sb, (char *) data);
  
  	sbi = kzalloc(sizeof(struct omfs_sb_info), GFP_KERNEL);
  	if (!sbi)
  		return -ENOMEM;
  
  	sb->s_fs_info = sbi;
c222d53eb   David Howells   CRED: Wrap task c...
430
431
  	sbi->s_uid = current_uid();
  	sbi->s_gid = current_gid();
ce3b0f8d5   Al Viro   New helper - curr...
432
  	sbi->s_dmask = sbi->s_fmask = current_umask();
555e3775c   Bob Copeland   omfs: add inode r...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
  
  	if (!parse_options((char *) data, sbi))
  		goto end;
  
  	sb->s_maxbytes = 0xffffffff;
  
  	sb_set_blocksize(sb, 0x200);
  
  	bh = sb_bread(sb, 0);
  	if (!bh)
  		goto end;
  
  	omfs_sb = (struct omfs_super_block *)bh->b_data;
  
  	if (omfs_sb->s_magic != cpu_to_be32(OMFS_MAGIC)) {
  		if (!silent)
  			printk(KERN_ERR "omfs: Invalid superblock (%x)
  ",
  				   omfs_sb->s_magic);
  		goto out_brelse_bh;
  	}
  	sb->s_magic = OMFS_MAGIC;
  
  	sbi->s_num_blocks = be64_to_cpu(omfs_sb->s_num_blocks);
  	sbi->s_blocksize = be32_to_cpu(omfs_sb->s_blocksize);
  	sbi->s_mirrors = be32_to_cpu(omfs_sb->s_mirrors);
  	sbi->s_root_ino = be64_to_cpu(omfs_sb->s_root_block);
  	sbi->s_sys_blocksize = be32_to_cpu(omfs_sb->s_sys_blocksize);
  	mutex_init(&sbi->s_bitmap_lock);
  
  	if (sbi->s_sys_blocksize > PAGE_SIZE) {
  		printk(KERN_ERR "omfs: sysblock size (%d) is out of range
  ",
  			sbi->s_sys_blocksize);
  		goto out_brelse_bh;
  	}
  
  	if (sbi->s_blocksize < sbi->s_sys_blocksize ||
  	    sbi->s_blocksize > OMFS_MAX_BLOCK_SIZE) {
  		printk(KERN_ERR "omfs: block size (%d) is out of range
  ",
  			sbi->s_blocksize);
  		goto out_brelse_bh;
  	}
  
  	/*
  	 * Use sys_blocksize as the fs block since it is smaller than a
  	 * page while the fs blocksize can be larger.
  	 */
  	sb_set_blocksize(sb, sbi->s_sys_blocksize);
  
  	/*
  	 * ...and the difference goes into a shift.  sys_blocksize is always
  	 * a power of two factor of blocksize.
  	 */
  	sbi->s_block_shift = get_bitmask_order(sbi->s_blocksize) -
  		get_bitmask_order(sbi->s_sys_blocksize);
f068272cb   Bob Copeland   omfs: check bound...
490
  	bh2 = omfs_bread(sb, be64_to_cpu(omfs_sb->s_root_block));
555e3775c   Bob Copeland   omfs: add inode r...
491
492
493
494
495
496
497
498
499
500
501
502
  	if (!bh2)
  		goto out_brelse_bh;
  
  	omfs_rb = (struct omfs_root_block *)bh2->b_data;
  
  	sbi->s_bitmap_ino = be64_to_cpu(omfs_rb->r_bitmap);
  	sbi->s_clustersize = be32_to_cpu(omfs_rb->r_clustersize);
  
  	if (sbi->s_num_blocks != be64_to_cpu(omfs_rb->r_num_blocks)) {
  		printk(KERN_ERR "omfs: block count discrepancy between "
  			"super and root blocks (%llx, %llx)
  ",
dc60bf1d8   Alexander Beregalov   omfs: fix warning
503
504
  			(unsigned long long)sbi->s_num_blocks,
  			(unsigned long long)be64_to_cpu(omfs_rb->r_num_blocks));
555e3775c   Bob Copeland   omfs: add inode r...
505
506
  		goto out_brelse_bh2;
  	}
9442e54f4   Bob Copeland   omfs: refuse to m...
507
508
509
510
511
512
513
514
515
  	if (sbi->s_bitmap_ino != ~0ULL &&
  	    sbi->s_bitmap_ino > sbi->s_num_blocks) {
  		printk(KERN_ERR "omfs: free space bitmap location is corrupt "
  			"(%llx, total blocks %llx)
  ",
  			(unsigned long long) sbi->s_bitmap_ino,
  			(unsigned long long) sbi->s_num_blocks);
  		goto out_brelse_bh2;
  	}
8800a044c   Bob Copeland   omfs: sanity chec...
516
517
518
519
520
521
  	if (sbi->s_clustersize < 1 ||
  	    sbi->s_clustersize > OMFS_MAX_CLUSTER_SIZE) {
  		printk(KERN_ERR "omfs: cluster size out of range (%d)",
  			sbi->s_clustersize);
  		goto out_brelse_bh2;
  	}
9442e54f4   Bob Copeland   omfs: refuse to m...
522

555e3775c   Bob Copeland   omfs: add inode r...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
  	ret = omfs_get_imap(sb);
  	if (ret)
  		goto out_brelse_bh2;
  
  	sb->s_op = &omfs_sops;
  
  	root = omfs_iget(sb, be64_to_cpu(omfs_rb->r_root_dir));
  	if (IS_ERR(root)) {
  		ret = PTR_ERR(root);
  		goto out_brelse_bh2;
  	}
  
  	sb->s_root = d_alloc_root(root);
  	if (!sb->s_root) {
  		iput(root);
  		goto out_brelse_bh2;
  	}
  	printk(KERN_DEBUG "omfs: Mounted volume %s
  ", omfs_rb->r_name);
  
  	ret = 0;
  out_brelse_bh2:
  	brelse(bh2);
  out_brelse_bh:
  	brelse(bh);
  end:
70d9e384a   Davidlohr Bueso   omfs: fix memory ...
549
550
  	if (ret)
  		kfree(sbi);
555e3775c   Bob Copeland   omfs: add inode r...
551
552
  	return ret;
  }
152a08366   Al Viro   new helper: mount...
553
554
  static struct dentry *omfs_mount(struct file_system_type *fs_type,
  			int flags, const char *dev_name, void *data)
555e3775c   Bob Copeland   omfs: add inode r...
555
  {
152a08366   Al Viro   new helper: mount...
556
  	return mount_bdev(fs_type, flags, dev_name, data, omfs_fill_super);
555e3775c   Bob Copeland   omfs: add inode r...
557
558
559
560
561
  }
  
  static struct file_system_type omfs_fs_type = {
  	.owner = THIS_MODULE,
  	.name = "omfs",
152a08366   Al Viro   new helper: mount...
562
  	.mount = omfs_mount,
555e3775c   Bob Copeland   omfs: add inode r...
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
  	.kill_sb = kill_block_super,
  	.fs_flags = FS_REQUIRES_DEV,
  };
  
  static int __init init_omfs_fs(void)
  {
  	return register_filesystem(&omfs_fs_type);
  }
  
  static void __exit exit_omfs_fs(void)
  {
  	unregister_filesystem(&omfs_fs_type);
  }
  
  module_init(init_omfs_fs);
  module_exit(exit_omfs_fs);