From 39429c5e4a2c56a39c9a1c9bdad54431c63104b0 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 23 Mar 2012 16:36:45 -0400 Subject: 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 --- include/linux/ext2_fs.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/linux/ext2_fs.h') 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 { ~EXT2_DIR_ROUND) #define EXT2_MAX_REC_LEN ((1<<16)-1) +#define EXT2_SB_MAGIC_OFFSET 0x38 +#define EXT2_SB_BLOCKS_OFFSET 0x04 +#define EXT2_SB_BSIZE_OFFSET 0x18 + +static inline u64 ext2_image_size(void *ext2_sb) +{ + __u8 *p = ext2_sb; + if (*(__le16 *)(p + EXT2_SB_MAGIC_OFFSET) != cpu_to_le16(EXT2_SUPER_MAGIC)) + return 0; + return (u64)le32_to_cpup((__le32 *)(p + EXT2_SB_BLOCKS_OFFSET)) << + le32_to_cpup((__le32 *)(p + EXT2_SB_BSIZE_OFFSET)); +} + +static inline void verify_offsets(void) +{ +#define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y)); + A(EXT2_SB_MAGIC_OFFSET, s_magic); + A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count); + A(EXT2_SB_BSIZE_OFFSET, s_log_block_size); +#undef A +} + #endif /* _LINUX_EXT2_FS_H */ -- cgit v1.2.3