Skip to content

Commit 016936b

Browse files
Russell KingAl Viro
authored andcommitted
fs/adfs: dir: use pointers to access directory head/tails
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 <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 4287e4d commit 016936b

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

fs/adfs/adfs.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ static inline u16 adfs_filetype(u32 loadaddr)
2626
#define ADFS_NDA_PUBLIC_READ (1 << 5)
2727
#define ADFS_NDA_PUBLIC_WRITE (1 << 6)
2828

29-
#include "dir_f.h"
30-
3129
/*
3230
* adfs file system inode data in memory
3331
*/
@@ -98,8 +96,14 @@ struct adfs_dir {
9896
unsigned int pos;
9997
__u32 parent_id;
10098

101-
struct adfs_dirheader dirhead;
102-
union adfs_dirtail dirtail;
99+
union {
100+
struct adfs_dirheader *dirhead;
101+
struct adfs_bigdirheader *bighead;
102+
};
103+
union {
104+
struct adfs_newdirtail *newtail;
105+
struct adfs_bigdirtail *bigtail;
106+
};
103107
};
104108

105109
/*

fs/adfs/dir_f.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static inline void adfs_writeval(unsigned char *p, int len, unsigned int val)
5858
#define bufoff(_bh,_idx) \
5959
({ int _buf = _idx >> blocksize_bits; \
6060
int _off = _idx - (_buf << blocksize_bits);\
61-
(u8 *)(_bh[_buf]->b_data + _off); \
61+
(void *)(_bh[_buf]->b_data + _off); \
6262
})
6363

6464
/*
@@ -139,18 +139,18 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
139139
if (ret)
140140
return ret;
141141

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

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

149-
if (memcmp(&dir->dirhead.startname, "Nick", 4) &&
150-
memcmp(&dir->dirhead.startname, "Hugo", 4))
149+
if (memcmp(&dir->dirhead->startname, "Nick", 4) &&
150+
memcmp(&dir->dirhead->startname, "Hugo", 4))
151151
goto bad_dir;
152152

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

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

280280
return ret;
281281
}
@@ -322,7 +322,6 @@ static int adfs_f_iterate(struct adfs_dir *dir, struct dir_context *ctx)
322322
static int
323323
adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
324324
{
325-
struct super_block *sb = dir->sb;
326325
int ret;
327326

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

342341
ret = adfs_dir_checkbyte(dir);
343342
/*
344343
* Update directory check byte
345344
*/
346-
dir->bh[dir->nr_buffers - 1]->b_data[sb->s_blocksize - 1] = ret;
345+
dir->newtail->dircheckbyte = ret;
347346

348347
#if 1
349-
{
350-
const unsigned int blocksize_bits = sb->s_blocksize_bits;
351-
352-
memcpy(&dir->dirhead, bufoff(dir->bh, 0), sizeof(dir->dirhead));
353-
memcpy(&dir->dirtail, bufoff(dir->bh, 2007), sizeof(dir->dirtail));
354-
355-
if (dir->dirhead.startmasseq != dir->dirtail.new.endmasseq ||
356-
memcmp(&dir->dirhead.startname, &dir->dirtail.new.endname, 4))
348+
if (dir->dirhead->startmasseq != dir->newtail->endmasseq ||
349+
memcmp(&dir->dirhead->startname, &dir->newtail->endname, 4))
357350
goto bad_dir;
358351

359-
if (memcmp(&dir->dirhead.startname, "Nick", 4) &&
360-
memcmp(&dir->dirhead.startname, "Hugo", 4))
352+
if (memcmp(&dir->dirhead->startname, "Nick", 4) &&
353+
memcmp(&dir->dirhead->startname, "Hugo", 4))
361354
goto bad_dir;
362355

363-
if (adfs_dir_checkbyte(dir) != dir->dirtail.new.dircheckbyte)
356+
if (adfs_dir_checkbyte(dir) != dir->newtail->dircheckbyte)
364357
goto bad_dir;
365-
}
366358
#endif
367359
ret = 0;
368360
out:

fs/adfs/dir_fplus.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static int adfs_fplus_read(struct super_block *sb, u32 indaddr,
2020
if (ret)
2121
return ret;
2222

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

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

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

69-
if (fpos <= le32_to_cpu(h->bigdirentries)) {
67+
if (fpos <= le32_to_cpu(dir->bighead->bigdirentries)) {
7068
dir->pos = fpos;
7169
ret = 0;
7270
}
@@ -77,8 +75,7 @@ adfs_fplus_setpos(struct adfs_dir *dir, unsigned int fpos)
7775
static int
7876
adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
7977
{
80-
struct adfs_bigdirheader *h =
81-
(struct adfs_bigdirheader *) dir->bhs[0]->b_data;
78+
struct adfs_bigdirheader *h = dir->bighead;
8279
struct adfs_bigdirentry bde;
8380
unsigned int offset;
8481
int ret;

0 commit comments

Comments
 (0)