|
14 | 14 | #if BITS_PER_LONG == 32
|
15 | 15 | #define __le_long __le32
|
16 | 16 | #define lel_to_cpu(A) le32_to_cpu(A)
|
| 17 | +#define cpu_to_lel(A) cpu_to_le32(A) |
17 | 18 | #elif BITS_PER_LONG == 64
|
18 | 19 | #define __le_long __le64
|
19 | 20 | #define lel_to_cpu(A) le64_to_cpu(A)
|
| 21 | +#define cpu_to_lel(A) cpu_to_le64(A) |
20 | 22 | #else
|
21 | 23 | #error "BITS_PER_LONG not 32 or 64"
|
22 | 24 | #endif
|
23 | 25 |
|
24 |
| -static const unsigned char free_bit[] = { |
25 |
| - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2,/* 0 ~ 19*/ |
26 |
| - 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3,/* 20 ~ 39*/ |
27 |
| - 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2,/* 40 ~ 59*/ |
28 |
| - 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4,/* 60 ~ 79*/ |
29 |
| - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2,/* 80 ~ 99*/ |
30 |
| - 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3,/*100 ~ 119*/ |
31 |
| - 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2,/*120 ~ 139*/ |
32 |
| - 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5,/*140 ~ 159*/ |
33 |
| - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2,/*160 ~ 179*/ |
34 |
| - 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3,/*180 ~ 199*/ |
35 |
| - 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2,/*200 ~ 219*/ |
36 |
| - 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4,/*220 ~ 239*/ |
37 |
| - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 /*240 ~ 254*/ |
38 |
| -}; |
39 |
| - |
40 | 26 | /*
|
41 | 27 | * Allocation Bitmap Management Functions
|
42 | 28 | */
|
@@ -195,32 +181,35 @@ unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned int clu)
|
195 | 181 | {
|
196 | 182 | unsigned int i, map_i, map_b, ent_idx;
|
197 | 183 | unsigned int clu_base, clu_free;
|
198 |
| - unsigned char k, clu_mask; |
| 184 | + unsigned long clu_bits, clu_mask; |
199 | 185 | struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
| 186 | + __le_long bitval; |
200 | 187 |
|
201 | 188 | WARN_ON(clu < EXFAT_FIRST_CLUSTER);
|
202 |
| - ent_idx = CLUSTER_TO_BITMAP_ENT(clu); |
203 |
| - clu_base = BITMAP_ENT_TO_CLUSTER(ent_idx & ~(BITS_PER_BYTE_MASK)); |
| 189 | + ent_idx = ALIGN_DOWN(CLUSTER_TO_BITMAP_ENT(clu), BITS_PER_LONG); |
| 190 | + clu_base = BITMAP_ENT_TO_CLUSTER(ent_idx); |
204 | 191 | clu_mask = IGNORED_BITS_REMAINED(clu, clu_base);
|
205 | 192 |
|
206 | 193 | map_i = BITMAP_OFFSET_SECTOR_INDEX(sb, ent_idx);
|
207 | 194 | map_b = BITMAP_OFFSET_BYTE_IN_SECTOR(sb, ent_idx);
|
208 | 195 |
|
209 | 196 | for (i = EXFAT_FIRST_CLUSTER; i < sbi->num_clusters;
|
210 |
| - i += BITS_PER_BYTE) { |
211 |
| - k = *(sbi->vol_amap[map_i]->b_data + map_b); |
| 197 | + i += BITS_PER_LONG) { |
| 198 | + bitval = *(__le_long *)(sbi->vol_amap[map_i]->b_data + map_b); |
212 | 199 | if (clu_mask > 0) {
|
213 |
| - k |= clu_mask; |
| 200 | + bitval |= cpu_to_lel(clu_mask); |
214 | 201 | clu_mask = 0;
|
215 | 202 | }
|
216 |
| - if (k < 0xFF) { |
217 |
| - clu_free = clu_base + free_bit[k]; |
| 203 | + if (lel_to_cpu(bitval) != ULONG_MAX) { |
| 204 | + clu_bits = lel_to_cpu(bitval); |
| 205 | + clu_free = clu_base + ffz(clu_bits); |
218 | 206 | if (clu_free < sbi->num_clusters)
|
219 | 207 | return clu_free;
|
220 | 208 | }
|
221 |
| - clu_base += BITS_PER_BYTE; |
| 209 | + clu_base += BITS_PER_LONG; |
| 210 | + map_b += sizeof(long); |
222 | 211 |
|
223 |
| - if (++map_b >= sb->s_blocksize || |
| 212 | + if (map_b >= sb->s_blocksize || |
224 | 213 | clu_base >= sbi->num_clusters) {
|
225 | 214 | if (++map_i >= sbi->map_sectors) {
|
226 | 215 | clu_base = EXFAT_FIRST_CLUSTER;
|
|
0 commit comments