From patchwork Fri Dec 18 01:30:52 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 68574 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id nBI4ixxC005715 for ; Fri, 18 Dec 2009 04:48:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753944AbZLRB3L (ORCPT ); Thu, 17 Dec 2009 20:29:11 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754673AbZLRB3I (ORCPT ); Thu, 17 Dec 2009 20:29:08 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:63709 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753915AbZLRB3D (ORCPT ); Thu, 17 Dec 2009 20:29:03 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 0D74C17011F; Fri, 18 Dec 2009 09:29:02 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id nBI1SxI6029865; Fri, 18 Dec 2009 09:28:59 +0800 Received: from [127.0.0.1] (unknown [10.167.141.121]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 5345ED45E1; Fri, 18 Dec 2009 09:29:24 +0800 (CST) Message-ID: <4B2ADB4C.7010900@cn.fujitsu.com> Date: Fri, 18 Dec 2009 09:30:52 +0800 From: Zhaolei User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: "linux-btrfs@vger.kernel.org" CC: LKML Subject: [PATCH] btrfs: Simplify offset calculation method for ctree.h Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e5dd628..44a3e98 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1264,12 +1264,12 @@ BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, static inline char *btrfs_device_uuid(struct btrfs_dev_item *d) { - return (char *)d + offsetof(struct btrfs_dev_item, uuid); + return (char *)&d->uuid; } static inline char *btrfs_device_fsid(struct btrfs_dev_item *d) { - return (char *)d + offsetof(struct btrfs_dev_item, fsid); + return (char *)&d->fsid; } BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); @@ -1286,7 +1286,7 @@ BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) { - return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); + return (char *)&s->dev_uuid; } BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); @@ -1310,10 +1310,7 @@ BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, int nr) { - unsigned long offset = (unsigned long)c; - offset += offsetof(struct btrfs_chunk, stripe); - offset += nr * sizeof(struct btrfs_stripe); - return (struct btrfs_stripe *)offset; + return &c->stripe + nr; } static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) @@ -1383,33 +1380,25 @@ BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); static inline struct btrfs_timespec * btrfs_inode_atime(struct btrfs_inode_item *inode_item) { - unsigned long ptr = (unsigned long)inode_item; - ptr += offsetof(struct btrfs_inode_item, atime); - return (struct btrfs_timespec *)ptr; + return &inode_item->atime; } static inline struct btrfs_timespec * btrfs_inode_mtime(struct btrfs_inode_item *inode_item) { - unsigned long ptr = (unsigned long)inode_item; - ptr += offsetof(struct btrfs_inode_item, mtime); - return (struct btrfs_timespec *)ptr; + return &inode_item->mtime; } static inline struct btrfs_timespec * btrfs_inode_ctime(struct btrfs_inode_item *inode_item) { - unsigned long ptr = (unsigned long)inode_item; - ptr += offsetof(struct btrfs_inode_item, ctime); - return (struct btrfs_timespec *)ptr; + return &inode_item->ctime; } static inline struct btrfs_timespec * btrfs_inode_otime(struct btrfs_inode_item *inode_item) { - unsigned long ptr = (unsigned long)inode_item; - ptr += offsetof(struct btrfs_inode_item, otime); - return (struct btrfs_timespec *)ptr; + return &inode_item->otime; } BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); @@ -1426,8 +1415,7 @@ BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev) { - unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid); - return (u8 *)((unsigned long)dev + ptr); + return (u8 *)&dev->chunk_tree_uuid; } BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); @@ -1731,26 +1719,22 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, static inline u8 *btrfs_header_fsid(struct extent_buffer *eb) { - unsigned long ptr = offsetof(struct btrfs_header, fsid); - return (u8 *)ptr; + return (u8 *)offsetof(struct btrfs_header, fsid); } static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb) { - unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid); - return (u8 *)ptr; + return (u8 *)offsetof(struct btrfs_header, chunk_tree_uuid); } static inline u8 *btrfs_super_fsid(struct extent_buffer *eb) { - unsigned long ptr = offsetof(struct btrfs_super_block, fsid); - return (u8 *)ptr; + return (u8 *)offsetof(struct btrfs_super_block, fsid); } static inline u8 *btrfs_header_csum(struct extent_buffer *eb) { - unsigned long ptr = offsetof(struct btrfs_header, csum); - return (u8 *)ptr; + return (u8 *)offsetof(struct btrfs_header, csum); } static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb) @@ -1858,9 +1842,7 @@ BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); static inline unsigned long btrfs_file_extent_inline_start(struct btrfs_file_extent_item *e) { - unsigned long offset = (unsigned long)e; - offset += offsetof(struct btrfs_file_extent_item, disk_bytenr); - return offset; + return (unsigned long)&e->disk_bytenr; } static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)