aboutsummaryrefslogtreecommitdiffstats
path: root/fs/qnx4/inode.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-02-14 17:48:20 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2012-03-20 21:29:52 -0400
commit7cd916f6ea86e8538b1e8136847dfb941813fe94 (patch)
tree4373e84fd6953fedd1015478c9b945ef39909a96 /fs/qnx4/inode.c
parent8f82ecae53347ec65721e1c0683c3f26647e3c97 (diff)
qnx4: new helper - try_extent()
checking if an extent is the one we are looking for is done twice in qnx4_block_map(); gather that code into a helper function. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/qnx4/inode.c')
-rw-r--r--fs/qnx4/inode.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index 7900a813d90f..552e994e3aa1 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -66,23 +66,31 @@ static int qnx4_get_block( struct inode *inode, sector_t iblock, struct buffer_h
66 return 0; 66 return 0;
67} 67}
68 68
69static inline u32 try_extent(qnx4_xtnt_t *extent, u32 *offset)
70{
71 u32 size = le32_to_cpu(extent->xtnt_size);
72 if (*offset < size)
73 return le32_to_cpu(extent->xtnt_blk) + *offset - 1;
74 *offset -= size;
75 return 0;
76}
77
69unsigned long qnx4_block_map( struct inode *inode, long iblock ) 78unsigned long qnx4_block_map( struct inode *inode, long iblock )
70{ 79{
71 int ix; 80 int ix;
72 long offset, i_xblk; 81 long i_xblk;
73 unsigned long block = 0;
74 struct buffer_head *bh = NULL; 82 struct buffer_head *bh = NULL;
75 struct qnx4_xblk *xblk = NULL; 83 struct qnx4_xblk *xblk = NULL;
76 struct qnx4_inode_entry *qnx4_inode = qnx4_raw_inode(inode); 84 struct qnx4_inode_entry *qnx4_inode = qnx4_raw_inode(inode);
77 u16 nxtnt = le16_to_cpu(qnx4_inode->di_num_xtnts); 85 u16 nxtnt = le16_to_cpu(qnx4_inode->di_num_xtnts);
86 u32 offset = iblock;
87 u32 block = try_extent(&qnx4_inode->di_first_xtnt, &offset);
78 88
79 if ( iblock < le32_to_cpu(qnx4_inode->di_first_xtnt.xtnt_size) ) { 89 if (block) {
80 // iblock is in the first extent. This is easy. 90 // iblock is in the first extent. This is easy.
81 block = le32_to_cpu(qnx4_inode->di_first_xtnt.xtnt_blk) + iblock - 1;
82 } else { 91 } else {
83 // iblock is beyond first extent. We have to follow the extent chain. 92 // iblock is beyond first extent. We have to follow the extent chain.
84 i_xblk = le32_to_cpu(qnx4_inode->di_xblk); 93 i_xblk = le32_to_cpu(qnx4_inode->di_xblk);
85 offset = iblock - le32_to_cpu(qnx4_inode->di_first_xtnt.xtnt_size);
86 ix = 0; 94 ix = 0;
87 while ( --nxtnt > 0 ) { 95 while ( --nxtnt > 0 ) {
88 if ( ix == 0 ) { 96 if ( ix == 0 ) {
@@ -98,12 +106,11 @@ unsigned long qnx4_block_map( struct inode *inode, long iblock )
98 return -EIO; 106 return -EIO;
99 } 107 }
100 } 108 }
101 if ( offset < le32_to_cpu(xblk->xblk_xtnts[ix].xtnt_size) ) { 109 block = try_extent(&xblk->xblk_xtnts[ix], &offset);
110 if (block) {
102 // got it! 111 // got it!
103 block = le32_to_cpu(xblk->xblk_xtnts[ix].xtnt_blk) + offset - 1;
104 break; 112 break;
105 } 113 }
106 offset -= le32_to_cpu(xblk->xblk_xtnts[ix].xtnt_size);
107 if ( ++ix >= xblk->xblk_num_xtnts ) { 114 if ( ++ix >= xblk->xblk_num_xtnts ) {
108 i_xblk = le32_to_cpu(xblk->xblk_next_xblk); 115 i_xblk = le32_to_cpu(xblk->xblk_next_xblk);
109 ix = 0; 116 ix = 0;