Skip to content

Commit 0db35a0

Browse files
Russell KingAl Viro
authored andcommitted
fs/adfs: bigdir: factor out directory entry offset calculation
Factor out the directory entry byte offset calculation. Signed-off-by: Russell King <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent aacc954 commit 0db35a0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

fs/adfs/dir_fplus.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
#include "adfs.h"
88
#include "dir_fplus.h"
99

10+
/* Return the byte offset to directory entry pos */
11+
static unsigned int adfs_fplus_offset(const struct adfs_bigdirheader *h,
12+
unsigned int pos)
13+
{
14+
return offsetof(struct adfs_bigdirheader, bigdirname) +
15+
ALIGN(le32_to_cpu(h->bigdirnamelen), 4) +
16+
pos * sizeof(struct adfs_bigdirentry);
17+
}
18+
1019
static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
1120
unsigned int size, struct adfs_dir *dir)
1221
{
@@ -83,9 +92,7 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
8392
if (dir->pos >= le32_to_cpu(h->bigdirentries))
8493
return -ENOENT;
8594

86-
offset = offsetof(struct adfs_bigdirheader, bigdirname);
87-
offset += ((le32_to_cpu(h->bigdirnamelen) + 4) & ~3);
88-
offset += dir->pos * sizeof(struct adfs_bigdirentry);
95+
offset = adfs_fplus_offset(h, dir->pos);
8996

9097
ret = adfs_dir_copyfrom(&bde, dir, offset,
9198
sizeof(struct adfs_bigdirentry));
@@ -99,9 +106,7 @@ adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
99106
obj->attr = le32_to_cpu(bde.bigdirattr);
100107
obj->name_len = le32_to_cpu(bde.bigdirobnamelen);
101108

102-
offset = offsetof(struct adfs_bigdirheader, bigdirname);
103-
offset += ((le32_to_cpu(h->bigdirnamelen) + 4) & ~3);
104-
offset += le32_to_cpu(h->bigdirentries) * sizeof(struct adfs_bigdirentry);
109+
offset = adfs_fplus_offset(h, le32_to_cpu(h->bigdirentries));
105110
offset += le32_to_cpu(bde.bigdirobnameptr);
106111

107112
ret = adfs_dir_copyfrom(obj->name, dir, offset, obj->name_len);

0 commit comments

Comments
 (0)