original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

588 lines
13 KiB

include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
12 years ago
omfs: fix potential oops when directory size is corrupted Testing with a modified fsfuzzer reveals a couple of locations in omfs where filesystem variables are ultimately used as loop counters with insufficient sanity checking. In this case, dir->i_size is used to compute the number of buckets in the directory hash. If too large, readdir will overrun a buffer. Since it's an invariant that dir->i_size is equal to the sysblock size, and we already sanity check that, just use that value instead. This fixes the following oops: BUG: unable to handle kernel paging request at c978e004 IP: [<c032298e>] omfs_readdir+0x18e/0x32f Oops: 0000 [#1] PREEMPT DEBUG_PAGEALLOC Modules linked in: Pid: 4796, comm: ls Not tainted (2.6.27-rc2 #12) EIP: 0060:[<c032298e>] EFLAGS: 00010287 CPU: 0 EIP is at omfs_readdir+0x18e/0x32f EAX: c978d000 EBX: 00000000 ECX: cbfcfaf8 EDX: cb2cf100 ESI: 00001000 EDI: 00000800 EBP: cb2d3f68 ESP: cb2d3f0c DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 0068 Process ls (pid: 4796, ti=cb2d3000 task=cb175f40 task.ti=cb2d3000) Stack: 00000002 00000000 00000000 c018a820 cb2d3f94 cb2cf100 cbfb0000 ffffff10 cbfb3b80 cbfcfaf8 000001c9 00000a09 00000000 00000000 00000000 cbfcfbc8 c9697000 cbfb3b80 22222222 00001000 c08e6cd0 cb2cf100 cbfb3b80 cb2d3f88 Call Trace: [<c018a820>] ? filldir64+0x0/0xcd [<c018a9f2>] ? vfs_readdir+0x56/0x82 [<c018a820>] ? filldir64+0x0/0xcd [<c018aa7c>] ? sys_getdents64+0x5e/0xa0 [<c01038bd>] ? sysenter_do_call+0x12/0x31 ======================= Code: 00 89 f0 89 f3 0f ac f8 14 81 e3 ff ff 0f 00 48 8d 14 c5 b8 01 00 00 89 45 cc 89 55 f0 e9 8c 01 00 00 8b 4d c8 8b 75 f0 8b 41 18 <8b> 54 30 04 8b 04 30 31 f6 89 5d dc 89 d1 8b 55 b8 0f c8 0f c9 Reported-by: Eric Sesterhenn <snakebyte@gmx.de> Signed-off-by: Bob Copeland <me@bobcopeland.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
13 years ago
fs: Limit sys_mount to only request filesystem modules. Modify the request_module to prefix the file system type with "fs-" and add aliases to all of the filesystems that can be built as modules to match. A common practice is to build all of the kernel code and leave code that is not commonly needed as modules, with the result that many users are exposed to any bug anywhere in the kernel. Looking for filesystems with a fs- prefix limits the pool of possible modules that can be loaded by mount to just filesystems trivially making things safer with no real cost. Using aliases means user space can control the policy of which filesystem modules are auto-loaded by editing /etc/modprobe.d/*.conf with blacklist and alias directives. Allowing simple, safe, well understood work-arounds to known problematic software. This also addresses a rare but unfortunate problem where the filesystem name is not the same as it's module name and module auto-loading would not work. While writing this patch I saw a handful of such cases. The most significant being autofs that lives in the module autofs4. This is relevant to user namespaces because we can reach the request module in get_fs_type() without having any special permissions, and people get uncomfortable when a user specified string (in this case the filesystem type) goes all of the way to request_module. After having looked at this issue I don't think there is any particular reason to perform any filtering or permission checks beyond making it clear in the module request that we want a filesystem module. The common pattern in the kernel is to call request_module() without regards to the users permissions. In general all a filesystem module does once loaded is call register_filesystem() and go to sleep. Which means there is not much attack surface exposed by loading a filesytem module unless the filesystem is mounted. In a user namespace filesystems are not mounted unless .fs_flags = FS_USERNS_MOUNT, which most filesystems do not set today. Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Acked-by: Kees Cook <keescook@chromium.org> Reported-by: Kees Cook <keescook@google.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
9 years ago
  1. /*
  2. * Optimized MPEG FS - inode and super operations.
  3. * Copyright (C) 2006 Bob Copeland <me@bobcopeland.com>
  4. * Released under GPL v2.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/sched.h>
  8. #include <linux/slab.h>
  9. #include <linux/fs.h>
  10. #include <linux/vfs.h>
  11. #include <linux/parser.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/vmalloc.h>
  14. #include <linux/writeback.h>
  15. #include <linux/crc-itu-t.h>
  16. #include "omfs.h"
  17. MODULE_AUTHOR("Bob Copeland <me@bobcopeland.com>");
  18. MODULE_DESCRIPTION("OMFS (ReplayTV/Karma) Filesystem for Linux");
  19. MODULE_LICENSE("GPL");
  20. struct buffer_head *omfs_bread(struct super_block *sb, sector_t block)
  21. {
  22. struct omfs_sb_info *sbi = OMFS_SB(sb);
  23. if (block >= sbi->s_num_blocks)
  24. return NULL;
  25. return sb_bread(sb, clus_to_blk(sbi, block));
  26. }
  27. struct inode *omfs_new_inode(struct inode *dir, umode_t mode)
  28. {
  29. struct inode *inode;
  30. u64 new_block;
  31. int err;
  32. int len;
  33. struct omfs_sb_info *sbi = OMFS_SB(dir->i_sb);
  34. inode = new_inode(dir->i_sb);
  35. if (!inode)
  36. return ERR_PTR(-ENOMEM);
  37. err = omfs_allocate_range(dir->i_sb, sbi->s_mirrors, sbi->s_mirrors,
  38. &new_block, &len);
  39. if (err)
  40. goto fail;
  41. inode->i_ino = new_block;
  42. inode_init_owner(inode, NULL, mode);
  43. inode->i_mapping->a_ops = &omfs_aops;
  44. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  45. switch (mode & S_IFMT) {
  46. case S_IFDIR:
  47. inode->i_op = &omfs_dir_inops;
  48. inode->i_fop = &omfs_dir_operations;
  49. inode->i_size = sbi->s_sys_blocksize;
  50. inc_nlink(inode);
  51. break;
  52. case S_IFREG:
  53. inode->i_op = &omfs_file_inops;
  54. inode->i_fop = &omfs_file_operations;
  55. inode->i_size = 0;
  56. break;
  57. }
  58. insert_inode_hash(inode);
  59. mark_inode_dirty(inode);
  60. return inode;
  61. fail:
  62. make_bad_inode(inode);
  63. iput(inode);
  64. return ERR_PTR(err);
  65. }
  66. /*
  67. * Update the header checksums for a dirty inode based on its contents.
  68. * Caller is expected to hold the buffer head underlying oi and mark it
  69. * dirty.
  70. */
  71. static void omfs_update_checksums(struct omfs_inode *oi)
  72. {
  73. int xor, i, ofs = 0, count;
  74. u16 crc = 0;
  75. unsigned char *ptr = (unsigned char *) oi;
  76. count = be32_to_cpu(oi->i_head.h_body_size);
  77. ofs = sizeof(struct omfs_header);
  78. crc = crc_itu_t(crc, ptr + ofs, count);
  79. oi->i_head.h_crc = cpu_to_be16(crc);
  80. xor = ptr[0];
  81. for (i = 1; i < OMFS_XOR_COUNT; i++)
  82. xor ^= ptr[i];
  83. oi->i_head.h_check_xor = xor;
  84. }
  85. static int __omfs_write_inode(struct inode *inode, int wait)
  86. {
  87. struct omfs_inode *oi;
  88. struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
  89. struct buffer_head *bh, *bh2;
  90. u64 ctime;
  91. int i;
  92. int ret = -EIO;
  93. int sync_failed = 0;
  94. /* get current inode since we may have written sibling ptrs etc. */
  95. bh = omfs_bread(inode->i_sb, inode->i_ino);
  96. if (!bh)
  97. goto out;
  98. oi = (struct omfs_inode *) bh->b_data;
  99. oi->i_head.h_self = cpu_to_be64(inode->i_ino);
  100. if (S_ISDIR(inode->i_mode))
  101. oi->i_type = OMFS_DIR;
  102. else if (S_ISREG(inode->i_mode))
  103. oi->i_type = OMFS_FILE;
  104. else {
  105. printk(KERN_WARNING "omfs: unknown file type: %d\n",
  106. inode->i_mode);
  107. goto out_brelse;
  108. }
  109. oi->i_head.h_body_size = cpu_to_be32(sbi->s_sys_blocksize -
  110. sizeof(struct omfs_header));
  111. oi->i_head.h_version = 1;
  112. oi->i_head.h_type = OMFS_INODE_NORMAL;
  113. oi->i_head.h_magic = OMFS_IMAGIC;
  114. oi->i_size = cpu_to_be64(inode->i_size);
  115. ctime = inode->i_ctime.tv_sec * 1000LL +
  116. ((inode->i_ctime.tv_nsec + 999)/1000);
  117. oi->i_ctime = cpu_to_be64(ctime);
  118. omfs_update_checksums(oi);
  119. mark_buffer_dirty(bh);
  120. if (wait) {
  121. sync_dirty_buffer(bh);
  122. if (buffer_req(bh) && !buffer_uptodate(bh))
  123. sync_failed = 1;
  124. }
  125. /* if mirroring writes, copy to next fsblock */
  126. for (i = 1; i < sbi->s_mirrors; i++) {
  127. bh2 = omfs_bread(inode->i_sb, inode->i_ino + i);
  128. if (!bh2)
  129. goto out_brelse;
  130. memcpy(bh2->b_data, bh->b_data, bh->b_size);
  131. mark_buffer_dirty(bh2);
  132. if (wait) {
  133. sync_dirty_buffer(bh2);
  134. if (buffer_req(bh2) && !buffer_uptodate(bh2))
  135. sync_failed = 1;
  136. }
  137. brelse(bh2);
  138. }
  139. ret = (sync_failed) ? -EIO : 0;
  140. out_brelse:
  141. brelse(bh);
  142. out:
  143. return ret;
  144. }
  145. static int omfs_write_inode(struct inode *inode, struct writeback_control *wbc)
  146. {
  147. return __omfs_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
  148. }
  149. int omfs_sync_inode(struct inode *inode)
  150. {
  151. return __omfs_write_inode(inode, 1);
  152. }
  153. /*
  154. * called when an entry is deleted, need to clear the bits in the
  155. * bitmaps.
  156. */
  157. static void omfs_evict_inode(struct inode *inode)
  158. {
  159. truncate_inode_pages(&inode->i_data, 0);
  160. clear_inode(inode);
  161. if (inode->i_nlink)
  162. return;
  163. if (S_ISREG(inode->i_mode)) {
  164. inode->i_size = 0;
  165. omfs_shrink_inode(inode);
  166. }
  167. omfs_clear_range(inode->i_sb, inode->i_ino, 2);
  168. }
  169. struct inode *omfs_iget(struct super_block *sb, ino_t ino)
  170. {
  171. struct omfs_sb_info *sbi = OMFS_SB(sb);
  172. struct omfs_inode *oi;
  173. struct buffer_head *bh;
  174. u64 ctime;
  175. unsigned long nsecs;
  176. struct inode *inode;
  177. inode = iget_locked(sb, ino);
  178. if (!inode)
  179. return ERR_PTR(-ENOMEM);
  180. if (!(inode->i_state & I_NEW))
  181. return inode;
  182. bh = omfs_bread(inode->i_sb, ino);
  183. if (!bh)
  184. goto iget_failed;
  185. oi = (struct omfs_inode *)bh->b_data;
  186. /* check self */
  187. if (ino != be64_to_cpu(oi->i_head.h_self))
  188. goto fail_bh;
  189. inode->i_uid = sbi->s_uid;
  190. inode->i_gid = sbi->s_gid;
  191. ctime = be64_to_cpu(oi->i_ctime);
  192. nsecs = do_div(ctime, 1000) * 1000L;
  193. inode->i_atime.tv_sec = ctime;
  194. inode->i_mtime.tv_sec = ctime;
  195. inode->i_ctime.tv_sec = ctime;
  196. inode->i_atime.tv_nsec = nsecs;
  197. inode->i_mtime.tv_nsec = nsecs;
  198. inode->i_ctime.tv_nsec = nsecs;
  199. inode->i_mapping->a_ops = &omfs_aops;
  200. switch (oi->i_type) {
  201. case OMFS_DIR:
  202. inode->i_mode = S_IFDIR | (S_IRWXUGO & ~sbi->s_dmask);
  203. inode->i_op = &omfs_dir_inops;
  204. inode->i_fop = &omfs_dir_operations;
  205. inode->i_size = sbi->s_sys_blocksize;
  206. inc_nlink(inode);
  207. break;
  208. case OMFS_FILE:
  209. inode->i_mode = S_IFREG | (S_IRWXUGO & ~sbi->s_fmask);
  210. inode->i_fop = &omfs_file_operations;
  211. inode->i_size = be64_to_cpu(oi->i_size);
  212. break;
  213. }
  214. brelse(bh);
  215. unlock_new_inode(inode);
  216. return inode;
  217. fail_bh:
  218. brelse(bh);
  219. iget_failed:
  220. iget_failed(inode);
  221. return ERR_PTR(-EIO);
  222. }
  223. static void omfs_put_super(struct super_block *sb)
  224. {
  225. struct omfs_sb_info *sbi = OMFS_SB(sb);
  226. kfree(sbi->s_imap);
  227. kfree(sbi);
  228. sb->s_fs_info = NULL;
  229. }
  230. static int omfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  231. {
  232. struct super_block *s = dentry->d_sb;
  233. struct omfs_sb_info *sbi = OMFS_SB(s);
  234. u64 id = huge_encode_dev(s->s_bdev->bd_dev);
  235. buf->f_type = OMFS_MAGIC;
  236. buf->f_bsize = sbi->s_blocksize;
  237. buf->f_blocks = sbi->s_num_blocks;
  238. buf->f_files = sbi->s_num_blocks;
  239. buf->f_namelen = OMFS_NAMELEN;
  240. buf->f_fsid.val[0] = (u32)id;
  241. buf->f_fsid.val[1] = (u32)(id >> 32);
  242. buf->f_bfree = buf->f_bavail = buf->f_ffree =
  243. omfs_count_free(s);
  244. return 0;
  245. }
  246. static const struct super_operations omfs_sops = {
  247. .write_inode = omfs_write_inode,
  248. .evict_inode = omfs_evict_inode,
  249. .put_super = omfs_put_super,
  250. .statfs = omfs_statfs,
  251. .show_options = generic_show_options,
  252. };
  253. /*
  254. * For Rio Karma, there is an on-disk free bitmap whose location is
  255. * stored in the root block. For ReplayTV, there is no such free bitmap
  256. * so we have to walk the tree. Both inodes and file data are allocated
  257. * from the same map. This array can be big (300k) so we allocate
  258. * in units of the blocksize.
  259. */
  260. static int omfs_get_imap(struct super_block *sb)
  261. {
  262. int bitmap_size;
  263. int array_size;
  264. int count;
  265. struct omfs_sb_info *sbi = OMFS_SB(sb);
  266. struct buffer_head *bh;
  267. unsigned long **ptr;
  268. sector_t block;
  269. bitmap_size = DIV_ROUND_UP(sbi->s_num_blocks, 8);
  270. array_size = DIV_ROUND_UP(bitmap_size, sb->s_blocksize);
  271. if (sbi->s_bitmap_ino == ~0ULL)
  272. goto out;
  273. sbi->s_imap_size = array_size;
  274. sbi->s_imap = kzalloc(array_size * sizeof(unsigned long *), GFP_KERNEL);
  275. if (!sbi->s_imap)
  276. goto nomem;
  277. block = clus_to_blk(sbi, sbi->s_bitmap_ino);
  278. if (block >= sbi->s_num_blocks)
  279. goto nomem;
  280. ptr = sbi->s_imap;
  281. for (count = bitmap_size; count > 0; count -= sb->s_blocksize) {
  282. bh = sb_bread(sb, block++);
  283. if (!bh)
  284. goto nomem_free;
  285. *ptr = kmalloc(sb->s_blocksize, GFP_KERNEL);
  286. if (!*ptr) {
  287. brelse(bh);
  288. goto nomem_free;
  289. }
  290. memcpy(*ptr, bh->b_data, sb->s_blocksize);
  291. if (count < sb->s_blocksize)
  292. memset((void *)*ptr + count, 0xff,
  293. sb->s_blocksize - count);
  294. brelse(bh);
  295. ptr++;
  296. }
  297. out:
  298. return 0;
  299. nomem_free:
  300. for (count = 0; count < array_size; count++)
  301. kfree(sbi->s_imap[count]);
  302. kfree(sbi->s_imap);
  303. nomem:
  304. sbi->s_imap = NULL;
  305. sbi->s_imap_size = 0;
  306. return -ENOMEM;
  307. }
  308. enum {
  309. Opt_uid, Opt_gid, Opt_umask, Opt_dmask, Opt_fmask
  310. };
  311. static const match_table_t tokens = {
  312. {Opt_uid, "uid=%u"},
  313. {Opt_gid, "gid=%u"},
  314. {Opt_umask, "umask=%o"},
  315. {Opt_dmask, "dmask=%o"},
  316. {Opt_fmask, "fmask=%o"},
  317. };
  318. static int parse_options(char *options, struct omfs_sb_info *sbi)
  319. {
  320. char *p;
  321. substring_t args[MAX_OPT_ARGS];
  322. int option;
  323. if (!options)
  324. return 1;
  325. while ((p = strsep(&options, ",")) != NULL) {
  326. int token;
  327. if (!*p)
  328. continue;
  329. token = match_token(p, tokens, args);
  330. switch (token) {
  331. case Opt_uid:
  332. if (match_int(&args[0], &option))
  333. return 0;
  334. sbi->s_uid = make_kuid(current_user_ns(), option);
  335. if (!uid_valid(sbi->s_uid))
  336. return 0;
  337. break;
  338. case Opt_gid:
  339. if (match_int(&args[0], &option))
  340. return 0;
  341. sbi->s_gid = make_kgid(current_user_ns(), option);
  342. if (!gid_valid(sbi->s_gid))
  343. return 0;
  344. break;
  345. case Opt_umask:
  346. if (match_octal(&args[0], &option))
  347. return 0;
  348. sbi->s_fmask = sbi->s_dmask = option;
  349. break;
  350. case Opt_dmask:
  351. if (match_octal(&args[0], &option))
  352. return 0;
  353. sbi->s_dmask = option;
  354. break;
  355. case Opt_fmask:
  356. if (match_octal(&args[0], &option))
  357. return 0;
  358. sbi->s_fmask = option;
  359. break;
  360. default:
  361. return 0;
  362. }
  363. }
  364. return 1;
  365. }
  366. static int omfs_fill_super(struct super_block *sb, void *data, int silent)
  367. {
  368. struct buffer_head *bh, *bh2;
  369. struct omfs_super_block *omfs_sb;
  370. struct omfs_root_block *omfs_rb;
  371. struct omfs_sb_info *sbi;
  372. struct inode *root;
  373. int ret = -EINVAL;
  374. save_mount_options(sb, (char *) data);
  375. sbi = kzalloc(sizeof(struct omfs_sb_info), GFP_KERNEL);
  376. if (!sbi)
  377. return -ENOMEM;
  378. sb->s_fs_info = sbi;
  379. sbi->s_uid = current_uid();
  380. sbi->s_gid = current_gid();
  381. sbi->s_dmask = sbi->s_fmask = current_umask();
  382. if (!parse_options((char *) data, sbi))
  383. goto end;
  384. sb->s_maxbytes = 0xffffffff;
  385. sb_set_blocksize(sb, 0x200);
  386. bh = sb_bread(sb, 0);
  387. if (!bh)
  388. goto end;
  389. omfs_sb = (struct omfs_super_block *)bh->b_data;
  390. if (omfs_sb->s_magic != cpu_to_be32(OMFS_MAGIC)) {
  391. if (!silent)
  392. printk(KERN_ERR "omfs: Invalid superblock (%x)\n",
  393. omfs_sb->s_magic);
  394. goto out_brelse_bh;
  395. }
  396. sb->s_magic = OMFS_MAGIC;
  397. sbi->s_num_blocks = be64_to_cpu(omfs_sb->s_num_blocks);
  398. sbi->s_blocksize = be32_to_cpu(omfs_sb->s_blocksize);
  399. sbi->s_mirrors = be32_to_cpu(omfs_sb->s_mirrors);
  400. sbi->s_root_ino = be64_to_cpu(omfs_sb->s_root_block);
  401. sbi->s_sys_blocksize = be32_to_cpu(omfs_sb->s_sys_blocksize);
  402. mutex_init(&sbi->s_bitmap_lock);
  403. if (sbi->s_sys_blocksize > PAGE_SIZE) {
  404. printk(KERN_ERR "omfs: sysblock size (%d) is out of range\n",
  405. sbi->s_sys_blocksize);
  406. goto out_brelse_bh;
  407. }
  408. if (sbi->s_blocksize < sbi->s_sys_blocksize ||
  409. sbi->s_blocksize > OMFS_MAX_BLOCK_SIZE) {
  410. printk(KERN_ERR "omfs: block size (%d) is out of range\n",
  411. sbi->s_blocksize);
  412. goto out_brelse_bh;
  413. }
  414. /*
  415. * Use sys_blocksize as the fs block since it is smaller than a
  416. * page while the fs blocksize can be larger.
  417. */
  418. sb_set_blocksize(sb, sbi->s_sys_blocksize);
  419. /*
  420. * ...and the difference goes into a shift. sys_blocksize is always
  421. * a power of two factor of blocksize.
  422. */
  423. sbi->s_block_shift = get_bitmask_order(sbi->s_blocksize) -
  424. get_bitmask_order(sbi->s_sys_blocksize);
  425. bh2 = omfs_bread(sb, be64_to_cpu(omfs_sb->s_root_block));
  426. if (!bh2)
  427. goto out_brelse_bh;
  428. omfs_rb = (struct omfs_root_block *)bh2->b_data;
  429. sbi->s_bitmap_ino = be64_to_cpu(omfs_rb->r_bitmap);
  430. sbi->s_clustersize = be32_to_cpu(omfs_rb->r_clustersize);
  431. if (sbi->s_num_blocks != be64_to_cpu(omfs_rb->r_num_blocks)) {
  432. printk(KERN_ERR "omfs: block count discrepancy between "
  433. "super and root blocks (%llx, %llx)\n",
  434. (unsigned long long)sbi->s_num_blocks,
  435. (unsigned long long)be64_to_cpu(omfs_rb->r_num_blocks));
  436. goto out_brelse_bh2;
  437. }
  438. if (sbi->s_bitmap_ino != ~0ULL &&
  439. sbi->s_bitmap_ino > sbi->s_num_blocks) {
  440. printk(KERN_ERR "omfs: free space bitmap location is corrupt "
  441. "(%llx, total blocks %llx)\n",
  442. (unsigned long long) sbi->s_bitmap_ino,
  443. (unsigned long long) sbi->s_num_blocks);
  444. goto out_brelse_bh2;
  445. }
  446. if (sbi->s_clustersize < 1 ||
  447. sbi->s_clustersize > OMFS_MAX_CLUSTER_SIZE) {
  448. printk(KERN_ERR "omfs: cluster size out of range (%d)",
  449. sbi->s_clustersize);
  450. goto out_brelse_bh2;
  451. }
  452. ret = omfs_get_imap(sb);
  453. if (ret)
  454. goto out_brelse_bh2;
  455. sb->s_op = &omfs_sops;
  456. root = omfs_iget(sb, be64_to_cpu(omfs_rb->r_root_dir));
  457. if (IS_ERR(root)) {
  458. ret = PTR_ERR(root);
  459. goto out_brelse_bh2;
  460. }
  461. sb->s_root = d_make_root(root);
  462. if (!sb->s_root)
  463. goto out_brelse_bh2;
  464. printk(KERN_DEBUG "omfs: Mounted volume %s\n", omfs_rb->r_name);
  465. ret = 0;
  466. out_brelse_bh2:
  467. brelse(bh2);
  468. out_brelse_bh:
  469. brelse(bh);
  470. end:
  471. if (ret)
  472. kfree(sbi);
  473. return ret;
  474. }
  475. static struct dentry *omfs_mount(struct file_system_type *fs_type,
  476. int flags, const char *dev_name, void *data)
  477. {
  478. return mount_bdev(fs_type, flags, dev_name, data, omfs_fill_super);
  479. }
  480. static struct file_system_type omfs_fs_type = {
  481. .owner = THIS_MODULE,
  482. .name = "omfs",
  483. .mount = omfs_mount,
  484. .kill_sb = kill_block_super,
  485. .fs_flags = FS_REQUIRES_DEV,
  486. };
  487. MODULE_ALIAS_FS("omfs");
  488. static int __init init_omfs_fs(void)
  489. {
  490. return register_filesystem(&omfs_fs_type);
  491. }
  492. static void __exit exit_omfs_fs(void)
  493. {
  494. unregister_filesystem(&omfs_fs_type);
  495. }
  496. module_init(init_omfs_fs);
  497. module_exit(exit_omfs_fs);