inode.c (f175ff8100eef0eb4b946c08e78a27bd17ca5896) inode.c (4f21e1ea09e1e337604f235a22ec2493ae1bd1db)
1/*
2 * Compressed rom filesystem for Linux.
3 *
4 * Copyright (C) 1999 Linus Torvalds.
5 *
6 * This file is released under the GPL.
7 */
8
9/*
10 * These are the VFS interfaces to the compressed rom filesystem.
11 * The actual compression is based on zlib, see the other files.
12 */
13
1/*
2 * Compressed rom filesystem for Linux.
3 *
4 * Copyright (C) 1999 Linus Torvalds.
5 *
6 * This file is released under the GPL.
7 */
8
9/*
10 * These are the VFS interfaces to the compressed rom filesystem.
11 * The actual compression is based on zlib, see the other files.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
14#include <linux/module.h>
15#include <linux/fs.h>
16#include <linux/pagemap.h>
17#include <linux/init.h>
18#include <linux/string.h>
19#include <linux/blkdev.h>
20#include <linux/slab.h>
21#include <linux/vfs.h>

--- 250 unchanged lines hidden (view full) ---

272 memcpy(&super, cramfs_read(sb, 0, sizeof(super)), sizeof(super));
273 mutex_unlock(&read_mutex);
274
275 /* Do sanity checks on the superblock */
276 if (super.magic != CRAMFS_MAGIC) {
277 /* check for wrong endianness */
278 if (super.magic == CRAMFS_MAGIC_WEND) {
279 if (!silent)
16#include <linux/module.h>
17#include <linux/fs.h>
18#include <linux/pagemap.h>
19#include <linux/init.h>
20#include <linux/string.h>
21#include <linux/blkdev.h>
22#include <linux/slab.h>
23#include <linux/vfs.h>

--- 250 unchanged lines hidden (view full) ---

274 memcpy(&super, cramfs_read(sb, 0, sizeof(super)), sizeof(super));
275 mutex_unlock(&read_mutex);
276
277 /* Do sanity checks on the superblock */
278 if (super.magic != CRAMFS_MAGIC) {
279 /* check for wrong endianness */
280 if (super.magic == CRAMFS_MAGIC_WEND) {
281 if (!silent)
280 pr_err("cramfs: wrong endianness\n");
282 pr_err("wrong endianness\n");
281 return -EINVAL;
282 }
283
284 /* check at 512 byte offset */
285 mutex_lock(&read_mutex);
286 memcpy(&super, cramfs_read(sb, 512, sizeof(super)), sizeof(super));
287 mutex_unlock(&read_mutex);
288 if (super.magic != CRAMFS_MAGIC) {
289 if (super.magic == CRAMFS_MAGIC_WEND && !silent)
283 return -EINVAL;
284 }
285
286 /* check at 512 byte offset */
287 mutex_lock(&read_mutex);
288 memcpy(&super, cramfs_read(sb, 512, sizeof(super)), sizeof(super));
289 mutex_unlock(&read_mutex);
290 if (super.magic != CRAMFS_MAGIC) {
291 if (super.magic == CRAMFS_MAGIC_WEND && !silent)
290 pr_err("cramfs: wrong endianness\n");
292 pr_err("wrong endianness\n");
291 else if (!silent)
293 else if (!silent)
292 pr_err("cramfs: wrong magic\n");
294 pr_err("wrong magic\n");
293 return -EINVAL;
294 }
295 }
296
297 /* get feature flags first */
298 if (super.flags & ~CRAMFS_SUPPORTED_FLAGS) {
295 return -EINVAL;
296 }
297 }
298
299 /* get feature flags first */
300 if (super.flags & ~CRAMFS_SUPPORTED_FLAGS) {
299 pr_err("cramfs: unsupported filesystem features\n");
301 pr_err("unsupported filesystem features\n");
300 return -EINVAL;
301 }
302
303 /* Check that the root inode is in a sane state */
304 if (!S_ISDIR(super.root.mode)) {
302 return -EINVAL;
303 }
304
305 /* Check that the root inode is in a sane state */
306 if (!S_ISDIR(super.root.mode)) {
305 pr_err("cramfs: root is not a directory\n");
307 pr_err("root is not a directory\n");
306 return -EINVAL;
307 }
308 /* correct strange, hard-coded permissions of mkcramfs */
309 super.root.mode |= (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
310
311 root_offset = super.root.offset << 2;
312 if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
313 sbi->size=super.size;
314 sbi->blocks=super.fsid.blocks;
315 sbi->files=super.fsid.files;
316 } else {
317 sbi->size=1<<28;
318 sbi->blocks=0;
319 sbi->files=0;
320 }
321 sbi->magic=super.magic;
322 sbi->flags=super.flags;
323 if (root_offset == 0)
308 return -EINVAL;
309 }
310 /* correct strange, hard-coded permissions of mkcramfs */
311 super.root.mode |= (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
312
313 root_offset = super.root.offset << 2;
314 if (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {
315 sbi->size=super.size;
316 sbi->blocks=super.fsid.blocks;
317 sbi->files=super.fsid.files;
318 } else {
319 sbi->size=1<<28;
320 sbi->blocks=0;
321 sbi->files=0;
322 }
323 sbi->magic=super.magic;
324 sbi->flags=super.flags;
325 if (root_offset == 0)
324 pr_info("cramfs: empty filesystem");
326 pr_info("empty filesystem");
325 else if (!(super.flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
326 ((root_offset != sizeof(struct cramfs_super)) &&
327 (root_offset != 512 + sizeof(struct cramfs_super))))
328 {
327 else if (!(super.flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
328 ((root_offset != sizeof(struct cramfs_super)) &&
329 (root_offset != 512 + sizeof(struct cramfs_super))))
330 {
329 pr_err("cramfs: bad root offset %lu\n", root_offset);
331 pr_err("bad root offset %lu\n", root_offset);
330 return -EINVAL;
331 }
332
333 /* Set it all up.. */
334 sb->s_op = &cramfs_ops;
335 root = get_cramfs_inode(sb, &super.root, 0);
336 if (IS_ERR(root))
337 return PTR_ERR(root);

--- 168 unchanged lines hidden (view full) ---

506 4);
507 compr_len = (*(u32 *) cramfs_read(sb, blkptr_offset, 4) -
508 start_offset);
509 mutex_unlock(&read_mutex);
510
511 if (compr_len == 0)
512 ; /* hole */
513 else if (unlikely(compr_len > (PAGE_CACHE_SIZE << 1))) {
332 return -EINVAL;
333 }
334
335 /* Set it all up.. */
336 sb->s_op = &cramfs_ops;
337 root = get_cramfs_inode(sb, &super.root, 0);
338 if (IS_ERR(root))
339 return PTR_ERR(root);

--- 168 unchanged lines hidden (view full) ---

508 4);
509 compr_len = (*(u32 *) cramfs_read(sb, blkptr_offset, 4) -
510 start_offset);
511 mutex_unlock(&read_mutex);
512
513 if (compr_len == 0)
514 ; /* hole */
515 else if (unlikely(compr_len > (PAGE_CACHE_SIZE << 1))) {
514 pr_err("cramfs: bad compressed blocksize %u\n",
516 pr_err("bad compressed blocksize %u\n",
515 compr_len);
516 goto err;
517 } else {
518 mutex_lock(&read_mutex);
519 bytes_filled = cramfs_uncompress_block(pgdata,
520 PAGE_CACHE_SIZE,
521 cramfs_read(sb, start_offset, compr_len),
522 compr_len);

--- 84 unchanged lines hidden ---
517 compr_len);
518 goto err;
519 } else {
520 mutex_lock(&read_mutex);
521 bytes_filled = cramfs_uncompress_block(pgdata,
522 PAGE_CACHE_SIZE,
523 cramfs_read(sb, start_offset, compr_len),
524 compr_len);

--- 84 unchanged lines hidden ---