@@ -97,17 +97,48 @@ static int get_compacted_la_distance(unsigned int lobits,
97
97
return d1 ;
98
98
}
99
99
100
- static int unpack_compacted_index (struct z_erofs_maprecorder * m ,
101
- unsigned int amortizedshift ,
102
- erofs_off_t pos , bool lookahead )
100
+ static int z_erofs_load_compact_lcluster (struct z_erofs_maprecorder * m ,
101
+ unsigned long lcn , bool lookahead )
103
102
{
104
- struct erofs_inode * const vi = EROFS_I (m -> inode );
103
+ struct inode * const inode = m -> inode ;
104
+ struct erofs_inode * const vi = EROFS_I (inode );
105
+ const erofs_off_t ebase = sizeof (struct z_erofs_map_header ) +
106
+ ALIGN (erofs_iloc (inode ) + vi -> inode_isize + vi -> xattr_isize , 8 );
105
107
const unsigned int lclusterbits = vi -> z_logical_clusterbits ;
108
+ const unsigned int totalidx = erofs_iblks (inode );
109
+ unsigned int compacted_4b_initial , compacted_2b , amortizedshift ;
106
110
unsigned int vcnt , lo , lobits , encodebits , nblk , bytes ;
107
- bool big_pcluster ;
111
+ bool big_pcluster = vi -> z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1 ;
112
+ erofs_off_t pos ;
108
113
u8 * in , type ;
109
114
int i ;
110
115
116
+ if (lcn >= totalidx || lclusterbits > 14 )
117
+ return - EINVAL ;
118
+
119
+ m -> lcn = lcn ;
120
+ /* used to align to 32-byte (compacted_2b) alignment */
121
+ compacted_4b_initial = ((32 - ebase % 32 ) / 4 ) & 7 ;
122
+ compacted_2b = 0 ;
123
+ if ((vi -> z_advise & Z_EROFS_ADVISE_COMPACTED_2B ) &&
124
+ compacted_4b_initial < totalidx )
125
+ compacted_2b = rounddown (totalidx - compacted_4b_initial , 16 );
126
+
127
+ pos = ebase ;
128
+ amortizedshift = 2 ; /* compact_4b */
129
+ if (lcn >= compacted_4b_initial ) {
130
+ pos += compacted_4b_initial * 4 ;
131
+ lcn -= compacted_4b_initial ;
132
+ if (lcn < compacted_2b ) {
133
+ amortizedshift = 1 ;
134
+ } else {
135
+ pos += compacted_2b * 2 ;
136
+ lcn -= compacted_2b ;
137
+ }
138
+ }
139
+ pos += lcn * (1 << amortizedshift );
140
+
141
+ /* figure out the lcluster count in this pack */
111
142
if (1 << amortizedshift == 4 && lclusterbits <= 14 )
112
143
vcnt = 2 ;
113
144
else if (1 << amortizedshift == 2 && lclusterbits <= 12 )
@@ -122,7 +153,6 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
122
153
/* it doesn't equal to round_up(..) */
123
154
m -> nextpackoff = round_down (pos , vcnt << amortizedshift ) +
124
155
(vcnt << amortizedshift );
125
- big_pcluster = vi -> z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1 ;
126
156
lobits = max (lclusterbits , ilog2 (Z_EROFS_LI_D0_CBLKCNT ) + 1U );
127
157
encodebits = ((vcnt << amortizedshift ) - sizeof (__le32 )) * 8 / vcnt ;
128
158
bytes = pos & ((vcnt << amortizedshift ) - 1 );
@@ -207,53 +237,6 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
207
237
return 0 ;
208
238
}
209
239
210
- static int z_erofs_load_compact_lcluster (struct z_erofs_maprecorder * m ,
211
- unsigned long lcn , bool lookahead )
212
- {
213
- struct inode * const inode = m -> inode ;
214
- struct erofs_inode * const vi = EROFS_I (inode );
215
- const erofs_off_t ebase = sizeof (struct z_erofs_map_header ) +
216
- ALIGN (erofs_iloc (inode ) + vi -> inode_isize + vi -> xattr_isize , 8 );
217
- unsigned int totalidx = erofs_iblks (inode );
218
- unsigned int compacted_4b_initial , compacted_2b ;
219
- unsigned int amortizedshift ;
220
- erofs_off_t pos ;
221
-
222
- if (lcn >= totalidx || vi -> z_logical_clusterbits > 14 )
223
- return - EINVAL ;
224
-
225
- m -> lcn = lcn ;
226
- /* used to align to 32-byte (compacted_2b) alignment */
227
- compacted_4b_initial = (32 - ebase % 32 ) / 4 ;
228
- if (compacted_4b_initial == 32 / 4 )
229
- compacted_4b_initial = 0 ;
230
-
231
- if ((vi -> z_advise & Z_EROFS_ADVISE_COMPACTED_2B ) &&
232
- compacted_4b_initial < totalidx )
233
- compacted_2b = rounddown (totalidx - compacted_4b_initial , 16 );
234
- else
235
- compacted_2b = 0 ;
236
-
237
- pos = ebase ;
238
- if (lcn < compacted_4b_initial ) {
239
- amortizedshift = 2 ;
240
- goto out ;
241
- }
242
- pos += compacted_4b_initial * 4 ;
243
- lcn -= compacted_4b_initial ;
244
-
245
- if (lcn < compacted_2b ) {
246
- amortizedshift = 1 ;
247
- goto out ;
248
- }
249
- pos += compacted_2b * 2 ;
250
- lcn -= compacted_2b ;
251
- amortizedshift = 2 ;
252
- out :
253
- pos += lcn * (1 << amortizedshift );
254
- return unpack_compacted_index (m , amortizedshift , pos , lookahead );
255
- }
256
-
257
240
static int z_erofs_load_lcluster_from_disk (struct z_erofs_maprecorder * m ,
258
241
unsigned int lcn , bool lookahead )
259
242
{
0 commit comments