8
8
9
9
static int erofs_fill_dentries (struct inode * dir , struct dir_context * ctx ,
10
10
void * dentry_blk , struct erofs_dirent * de ,
11
- unsigned int nameoff , unsigned int maxsize )
11
+ unsigned int nameoff0 , unsigned int maxsize )
12
12
{
13
- const struct erofs_dirent * end = dentry_blk + nameoff ;
13
+ const struct erofs_dirent * end = dentry_blk + nameoff0 ;
14
14
15
15
while (de < end ) {
16
- const char * de_name ;
16
+ unsigned char d_type = fs_ftype_to_dtype (de -> file_type );
17
+ unsigned int nameoff = le16_to_cpu (de -> nameoff );
18
+ const char * de_name = (char * )dentry_blk + nameoff ;
17
19
unsigned int de_namelen ;
18
- unsigned char d_type ;
19
-
20
- d_type = fs_ftype_to_dtype (de -> file_type );
21
-
22
- nameoff = le16_to_cpu (de -> nameoff );
23
- de_name = (char * )dentry_blk + nameoff ;
24
20
25
21
/* the last dirent in the block? */
26
22
if (de + 1 >= end )
@@ -52,21 +48,20 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
52
48
struct erofs_buf buf = __EROFS_BUF_INITIALIZER ;
53
49
struct super_block * sb = dir -> i_sb ;
54
50
unsigned long bsz = sb -> s_blocksize ;
55
- const size_t dirsize = i_size_read (dir );
56
- unsigned int i = erofs_blknr (sb , ctx -> pos );
57
51
unsigned int ofs = erofs_blkoff (sb , ctx -> pos );
58
52
int err = 0 ;
59
53
bool initial = true;
60
54
61
55
buf .mapping = dir -> i_mapping ;
62
- while (ctx -> pos < dirsize ) {
56
+ while (ctx -> pos < dir -> i_size ) {
57
+ erofs_off_t dbstart = ctx -> pos - ofs ;
63
58
struct erofs_dirent * de ;
64
59
unsigned int nameoff , maxsize ;
65
60
66
- de = erofs_bread (& buf , erofs_pos ( sb , i ) , EROFS_KMAP );
61
+ de = erofs_bread (& buf , dbstart , EROFS_KMAP );
67
62
if (IS_ERR (de )) {
68
63
erofs_err (sb , "fail to readdir of logical block %u of nid %llu" ,
69
- i , EROFS_I (dir )-> nid );
64
+ erofs_blknr ( sb , dbstart ) , EROFS_I (dir )-> nid );
70
65
err = PTR_ERR (de );
71
66
break ;
72
67
}
@@ -79,25 +74,19 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
79
74
break ;
80
75
}
81
76
82
- maxsize = min_t (unsigned int , dirsize - ctx -> pos + ofs , bsz );
83
-
77
+ maxsize = min_t (unsigned int , dir -> i_size - dbstart , bsz );
84
78
/* search dirents at the arbitrary position */
85
79
if (initial ) {
86
80
initial = false;
87
-
88
81
ofs = roundup (ofs , sizeof (struct erofs_dirent ));
89
- ctx -> pos = erofs_pos (sb , i ) + ofs ;
90
- if (ofs >= nameoff )
91
- goto skip_this ;
82
+ ctx -> pos = dbstart + ofs ;
92
83
}
93
84
94
85
err = erofs_fill_dentries (dir , ctx , de , (void * )de + ofs ,
95
86
nameoff , maxsize );
96
87
if (err )
97
88
break ;
98
- skip_this :
99
- ctx -> pos = erofs_pos (sb , i ) + maxsize ;
100
- ++ i ;
89
+ ctx -> pos = dbstart + maxsize ;
101
90
ofs = 0 ;
102
91
}
103
92
erofs_put_metabuf (& buf );
0 commit comments