Skip to content

Commit

Permalink
fs/adfs: dir: use pointers to access directory head/tails
Browse files Browse the repository at this point in the history
Add and use pointers in the adfs_dir structure to access the directory
head and tail structures, which will always be contiguous in a buffer.
This allows us to avoid memcpy()ing the data in the new directory code,
making it slightly more efficient.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Russell King authored and Al Viro committed Jan 21, 2020
1 parent 4287e4d commit 016936b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
12 changes: 8 additions & 4 deletions fs/adfs/adfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ static inline u16 adfs_filetype(u32 loadaddr)
#define ADFS_NDA_PUBLIC_READ (1 << 5)
#define ADFS_NDA_PUBLIC_WRITE (1 << 6)

#include "dir_f.h"

/*
* adfs file system inode data in memory
*/
Expand Down Expand Up @@ -98,8 +96,14 @@ struct adfs_dir {
unsigned int pos;
__u32 parent_id;

struct adfs_dirheader dirhead;
union adfs_dirtail dirtail;
union {
struct adfs_dirheader *dirhead;
struct adfs_bigdirheader *bighead;
};
union {
struct adfs_newdirtail *newtail;
struct adfs_bigdirtail *bigtail;
};
};

/*
Expand Down
42 changes: 17 additions & 25 deletions fs/adfs/dir_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static inline void adfs_writeval(unsigned char *p, int len, unsigned int val)
#define bufoff(_bh,_idx) \
({ int _buf = _idx >> blocksize_bits; \
int _off = _idx - (_buf << blocksize_bits);\
(u8 *)(_bh[_buf]->b_data + _off); \
(void *)(_bh[_buf]->b_data + _off); \
})

/*
Expand Down Expand Up @@ -139,18 +139,18 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
if (ret)
return ret;

memcpy(&dir->dirhead, bufoff(dir->bh, 0), sizeof(dir->dirhead));
memcpy(&dir->dirtail, bufoff(dir->bh, 2007), sizeof(dir->dirtail));
dir->dirhead = bufoff(dir->bh, 0);
dir->newtail = bufoff(dir->bh, 2007);

if (dir->dirhead.startmasseq != dir->dirtail.new.endmasseq ||
memcmp(&dir->dirhead.startname, &dir->dirtail.new.endname, 4))
if (dir->dirhead->startmasseq != dir->newtail->endmasseq ||
memcmp(&dir->dirhead->startname, &dir->newtail->endname, 4))
goto bad_dir;

if (memcmp(&dir->dirhead.startname, "Nick", 4) &&
memcmp(&dir->dirhead.startname, "Hugo", 4))
if (memcmp(&dir->dirhead->startname, "Nick", 4) &&
memcmp(&dir->dirhead->startname, "Hugo", 4))
goto bad_dir;

if (adfs_dir_checkbyte(dir) != dir->dirtail.new.dircheckbyte)
if (adfs_dir_checkbyte(dir) != dir->newtail->dircheckbyte)
goto bad_dir;

return 0;
Expand Down Expand Up @@ -275,7 +275,7 @@ static int adfs_f_read(struct super_block *sb, u32 indaddr, unsigned int size,
if (ret)
adfs_error(sb, "unable to read directory");
else
dir->parent_id = adfs_readval(dir->dirtail.new.dirparent, 3);
dir->parent_id = adfs_readval(dir->newtail->dirparent, 3);

return ret;
}
Expand Down Expand Up @@ -322,7 +322,6 @@ static int adfs_f_iterate(struct adfs_dir *dir, struct dir_context *ctx)
static int
adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
{
struct super_block *sb = dir->sb;
int ret;

ret = adfs_dir_find_entry(dir, obj->indaddr);
Expand All @@ -336,33 +335,26 @@ adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
/*
* Increment directory sequence number
*/
dir->bh[0]->b_data[0] += 1;
dir->bh[dir->nr_buffers - 1]->b_data[sb->s_blocksize - 6] += 1;
dir->dirhead->startmasseq += 1;
dir->newtail->endmasseq += 1;

ret = adfs_dir_checkbyte(dir);
/*
* Update directory check byte
*/
dir->bh[dir->nr_buffers - 1]->b_data[sb->s_blocksize - 1] = ret;
dir->newtail->dircheckbyte = ret;

#if 1
{
const unsigned int blocksize_bits = sb->s_blocksize_bits;

memcpy(&dir->dirhead, bufoff(dir->bh, 0), sizeof(dir->dirhead));
memcpy(&dir->dirtail, bufoff(dir->bh, 2007), sizeof(dir->dirtail));

if (dir->dirhead.startmasseq != dir->dirtail.new.endmasseq ||
memcmp(&dir->dirhead.startname, &dir->dirtail.new.endname, 4))
if (dir->dirhead->startmasseq != dir->newtail->endmasseq ||
memcmp(&dir->dirhead->startname, &dir->newtail->endname, 4))
goto bad_dir;

if (memcmp(&dir->dirhead.startname, "Nick", 4) &&
memcmp(&dir->dirhead.startname, "Hugo", 4))
if (memcmp(&dir->dirhead->startname, "Nick", 4) &&
memcmp(&dir->dirhead->startname, "Hugo", 4))
goto bad_dir;

if (adfs_dir_checkbyte(dir) != dir->dirtail.new.dircheckbyte)
if (adfs_dir_checkbyte(dir) != dir->newtail->dircheckbyte)
goto bad_dir;
}
#endif
ret = 0;
out:
Expand Down
11 changes: 4 additions & 7 deletions fs/adfs/dir_fplus.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
if (ret)
return ret;

h = (struct adfs_bigdirheader *)dir->bhs[0]->b_data;
dir->bighead = h = (void *)dir->bhs[0]->b_data;
dirsize = le32_to_cpu(h->bigdirsize);
if (dirsize != size) {
adfs_msg(sb, KERN_WARNING,
Expand All @@ -40,7 +40,7 @@ static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
if (ret)
return ret;

t = (struct adfs_bigdirtail *)
dir->bigtail = t = (struct adfs_bigdirtail *)
(dir->bhs[dir->nr_buffers - 1]->b_data + (sb->s_blocksize - 8));

if (t->bigdirendname != cpu_to_le32(BIGDIRENDNAME) ||
Expand All @@ -62,11 +62,9 @@ static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
static int
adfs_fplus_setpos(struct adfs_dir *dir, unsigned int fpos)
{
struct adfs_bigdirheader *h =
(struct adfs_bigdirheader *) dir->bhs[0]->b_data;
int ret = -ENOENT;

if (fpos <= le32_to_cpu(h->bigdirentries)) {
if (fpos <= le32_to_cpu(dir->bighead->bigdirentries)) {
dir->pos = fpos;
ret = 0;
}
Expand All @@ -77,8 +75,7 @@ adfs_fplus_setpos(struct adfs_dir *dir, unsigned int fpos)
static int
adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
{
struct adfs_bigdirheader *h =
(struct adfs_bigdirheader *) dir->bhs[0]->b_data;
struct adfs_bigdirheader *h = dir->bighead;
struct adfs_bigdirentry bde;
unsigned int offset;
int ret;
Expand Down

0 comments on commit 016936b

Please sign in to comment.