Skip to content

Commit

Permalink
ufs: move calculation of offsets into ufs_getfrag_block()
Browse files Browse the repository at this point in the history
... and massage ufs_frag_map() to take those instead of fragment number.

As it is, we duplicate the damn thing on the write side, open-coded and
bloody hard to follow.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jul 6, 2015
1 parent 5a39c25 commit 4b7068c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fs/ufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,18 @@ static inline int grow_chain64(struct ufs_inode_info *ufsi,
* the beginning of the filesystem.
*/

static u64 ufs_frag_map(struct inode *inode, sector_t frag)
static u64 ufs_frag_map(struct inode *inode, unsigned offsets[4], int depth)
{
struct ufs_inode_info *ufsi = UFS_I(inode);
struct super_block *sb = inode->i_sb;
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
u64 mask = (u64) uspi->s_apbmask>>uspi->s_fpbshift;
int shift = uspi->s_apbshift-uspi->s_fpbshift;
unsigned offsets[4], *p;
Indirect chain[4], *q = chain;
int depth = ufs_block_to_path(inode, frag >> uspi->s_fpbshift, offsets);
unsigned *p;
unsigned flags = UFS_SB(sb)->s_flags;
u64 res = 0;

UFSD(": frag = %llu depth = %d\n", (unsigned long long)frag, depth);
UFSD(": uspi->s_fpbshift = %d ,uspi->s_apbmask = %x, mask=%llx\n",
uspi->s_fpbshift, uspi->s_apbmask,
(unsigned long long)mask);
Expand Down Expand Up @@ -191,7 +189,7 @@ static u64 ufs_frag_map(struct inode *inode, sector_t frag)
}
res = fs64_to_cpu(sb, q->key64);
found:
res += uspi->s_sbbase + (frag & uspi->s_fpbmask);
res += uspi->s_sbbase;
no_block:
while (q > chain) {
brelse(q->bh);
Expand Down Expand Up @@ -443,14 +441,17 @@ static int ufs_getfrag_block(struct inode *inode, sector_t fragment, struct buff
struct ufs_sb_private_info * uspi = sbi->s_uspi;
struct buffer_head * bh;
int ret, err, new;
unsigned offsets[4];
int depth = ufs_block_to_path(inode, fragment >> uspi->s_fpbshift, offsets);
unsigned long ptr,phys;
u64 phys64 = 0;

if (!create) {
phys64 = ufs_frag_map(inode, fragment);
UFSD("phys64 = %llu\n", (unsigned long long)phys64);
if (phys64)
phys64 = ufs_frag_map(inode, offsets, depth);
if (phys64) {
phys64 += fragment & uspi->s_fpbmask;
map_bh(bh_result, sb, phys64);
}
return 0;
}

Expand Down

0 comments on commit 4b7068c

Please sign in to comment.