diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2012-03-23 16:36:45 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-03-31 16:03:16 -0400 |
commit | 39429c5e4a2c56a39c9a1c9bdad54431c63104b0 (patch) | |
tree | 06abc2a4ff8d323b0358b768a71c7b651c3229f3 | |
parent | 2f99c36986ff27a86f06f27212c5f5fa8c7164a3 (diff) |
new helper: ext2_image_size()
... implemented that way since the next commit will leave it
almost alone in ext2_fs.h - most of the file (including
struct ext2_super_block) is going to move to fs/ext2/ext2.h.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | arch/blackfin/kernel/setup.c | 7 | ||||
-rw-r--r-- | include/linux/ext2_fs.h | 22 | ||||
-rw-r--r-- | init/do_mounts_rd.c | 9 |
3 files changed, 30 insertions, 8 deletions
diff --git a/arch/blackfin/kernel/setup.c b/arch/blackfin/kernel/setup.c index 2aa019368504..2ad747e909fb 100644 --- a/arch/blackfin/kernel/setup.c +++ b/arch/blackfin/kernel/setup.c | |||
@@ -550,6 +550,7 @@ static __init void memory_setup(void) | |||
550 | { | 550 | { |
551 | #ifdef CONFIG_MTD_UCLINUX | 551 | #ifdef CONFIG_MTD_UCLINUX |
552 | unsigned long mtd_phys = 0; | 552 | unsigned long mtd_phys = 0; |
553 | unsigned long n; | ||
553 | #endif | 554 | #endif |
554 | unsigned long max_mem; | 555 | unsigned long max_mem; |
555 | 556 | ||
@@ -593,9 +594,9 @@ static __init void memory_setup(void) | |||
593 | mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8))); | 594 | mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8))); |
594 | 595 | ||
595 | # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS) | 596 | # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS) |
596 | if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC) | 597 | n = ext2_image_size((void *)(mtd_phys + 0x400)); |
597 | mtd_size = | 598 | if (n) |
598 | PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10); | 599 | mtd_size = PAGE_ALIGN(n * 1024); |
599 | # endif | 600 | # endif |
600 | 601 | ||
601 | # if defined(CONFIG_CRAMFS) | 602 | # if defined(CONFIG_CRAMFS) |
diff --git a/include/linux/ext2_fs.h b/include/linux/ext2_fs.h index f28dba518a4a..5f65ec75b48a 100644 --- a/include/linux/ext2_fs.h +++ b/include/linux/ext2_fs.h | |||
@@ -536,4 +536,26 @@ enum { | |||
536 | ~EXT2_DIR_ROUND) | 536 | ~EXT2_DIR_ROUND) |
537 | #define EXT2_MAX_REC_LEN ((1<<16)-1) | 537 | #define EXT2_MAX_REC_LEN ((1<<16)-1) |
538 | 538 | ||
539 | #define EXT2_SB_MAGIC_OFFSET 0x38 | ||
540 | #define EXT2_SB_BLOCKS_OFFSET 0x04 | ||
541 | #define EXT2_SB_BSIZE_OFFSET 0x18 | ||
542 | |||
543 | static inline u64 ext2_image_size(void *ext2_sb) | ||
544 | { | ||
545 | __u8 *p = ext2_sb; | ||
546 | if (*(__le16 *)(p + EXT2_SB_MAGIC_OFFSET) != cpu_to_le16(EXT2_SUPER_MAGIC)) | ||
547 | return 0; | ||
548 | return (u64)le32_to_cpup((__le32 *)(p + EXT2_SB_BLOCKS_OFFSET)) << | ||
549 | le32_to_cpup((__le32 *)(p + EXT2_SB_BSIZE_OFFSET)); | ||
550 | } | ||
551 | |||
552 | static inline void verify_offsets(void) | ||
553 | { | ||
554 | #define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y)); | ||
555 | A(EXT2_SB_MAGIC_OFFSET, s_magic); | ||
556 | A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count); | ||
557 | A(EXT2_SB_BSIZE_OFFSET, s_log_block_size); | ||
558 | #undef A | ||
559 | } | ||
560 | |||
539 | #endif /* _LINUX_EXT2_FS_H */ | 561 | #endif /* _LINUX_EXT2_FS_H */ |
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 01f1306aa26e..6212586df29a 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c | |||
@@ -54,20 +54,19 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) | |||
54 | { | 54 | { |
55 | const int size = 512; | 55 | const int size = 512; |
56 | struct minix_super_block *minixsb; | 56 | struct minix_super_block *minixsb; |
57 | struct ext2_super_block *ext2sb; | ||
58 | struct romfs_super_block *romfsb; | 57 | struct romfs_super_block *romfsb; |
59 | struct cramfs_super *cramfsb; | 58 | struct cramfs_super *cramfsb; |
60 | struct squashfs_super_block *squashfsb; | 59 | struct squashfs_super_block *squashfsb; |
61 | int nblocks = -1; | 60 | int nblocks = -1; |
62 | unsigned char *buf; | 61 | unsigned char *buf; |
63 | const char *compress_name; | 62 | const char *compress_name; |
63 | unsigned long n; | ||
64 | 64 | ||
65 | buf = kmalloc(size, GFP_KERNEL); | 65 | buf = kmalloc(size, GFP_KERNEL); |
66 | if (!buf) | 66 | if (!buf) |
67 | return -ENOMEM; | 67 | return -ENOMEM; |
68 | 68 | ||
69 | minixsb = (struct minix_super_block *) buf; | 69 | minixsb = (struct minix_super_block *) buf; |
70 | ext2sb = (struct ext2_super_block *) buf; | ||
71 | romfsb = (struct romfs_super_block *) buf; | 70 | romfsb = (struct romfs_super_block *) buf; |
72 | cramfsb = (struct cramfs_super *) buf; | 71 | cramfsb = (struct cramfs_super *) buf; |
73 | squashfsb = (struct squashfs_super_block *) buf; | 72 | squashfsb = (struct squashfs_super_block *) buf; |
@@ -150,12 +149,12 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) | |||
150 | } | 149 | } |
151 | 150 | ||
152 | /* Try ext2 */ | 151 | /* Try ext2 */ |
153 | if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) { | 152 | n = ext2_image_size(buf); |
153 | if (n) { | ||
154 | printk(KERN_NOTICE | 154 | printk(KERN_NOTICE |
155 | "RAMDISK: ext2 filesystem found at block %d\n", | 155 | "RAMDISK: ext2 filesystem found at block %d\n", |
156 | start_block); | 156 | start_block); |
157 | nblocks = le32_to_cpu(ext2sb->s_blocks_count) << | 157 | nblocks = n; |
158 | le32_to_cpu(ext2sb->s_log_block_size); | ||
159 | goto done; | 158 | goto done; |
160 | } | 159 | } |
161 | 160 | ||