Lines Matching +full:cluster +full:- +full:index

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
22 if (sbi->FAT2_start_sector != sbi->FAT1_start_sector) { in exfat_mirror_bh()
23 sec2 = sec - sbi->FAT1_start_sector + sbi->FAT2_start_sector; in exfat_mirror_bh()
26 return -ENOMEM; in exfat_mirror_bh()
27 memcpy(c_bh->b_data, bh->b_data, sb->s_blocksize); in exfat_mirror_bh()
30 if (sb->s_flags & SB_SYNCHRONOUS) in exfat_mirror_bh()
50 return -EIO; in __exfat_ent_get()
52 *content = le32_to_cpu(*(__le32 *)(&bh->b_data[off])); in __exfat_ent_get()
75 return -EIO; in exfat_ent_set()
77 fat_entry = (__le32 *)&(bh->b_data[off]); in exfat_ent_set()
79 exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); in exfat_ent_set()
94 return -EIO; in exfat_ent_get()
107 "invalid access to FAT free cluster (entry 0x%08x)", in exfat_ent_get()
109 return -EIO; in exfat_ent_get()
114 "invalid access to FAT bad cluster (entry 0x%08x)", in exfat_ent_get()
116 return -EIO; in exfat_ent_get()
123 return -EIO; in exfat_ent_get()
137 return -EIO; in exfat_chain_cont_cluster()
139 len--; in exfat_chain_cont_cluster()
143 return -EIO; in exfat_chain_cont_cluster()
150 struct super_block *sb = inode->i_sb; in __exfat_free_cluster()
156 /* invalid cluster number */ in __exfat_free_cluster()
157 if (p_chain->dir == EXFAT_FREE_CLUSTER || in __exfat_free_cluster()
158 p_chain->dir == EXFAT_EOF_CLUSTER || in __exfat_free_cluster()
159 p_chain->dir < EXFAT_FIRST_CLUSTER) in __exfat_free_cluster()
162 /* no cluster to truncate */ in __exfat_free_cluster()
163 if (p_chain->size == 0) in __exfat_free_cluster()
166 /* check cluster validation */ in __exfat_free_cluster()
167 if (!is_valid_cluster(sbi, p_chain->dir)) { in __exfat_free_cluster()
168 exfat_err(sb, "invalid start cluster (%u)", p_chain->dir); in __exfat_free_cluster()
169 return -EIO; in __exfat_free_cluster()
172 clu = p_chain->dir; in __exfat_free_cluster()
177 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in __exfat_free_cluster()
178 unsigned int last_cluster = p_chain->dir + p_chain->size - 1; in __exfat_free_cluster()
186 /* flush bitmap only if index would be changed or for last cluster */ in __exfat_free_cluster()
195 } while (num_clusters < p_chain->size); in __exfat_free_cluster()
223 sbi->used_clusters -= num_clusters; in __exfat_free_cluster()
231 mutex_lock(&EXFAT_SB(inode->i_sb)->bitmap_lock); in exfat_free_cluster()
233 mutex_unlock(&EXFAT_SB(inode->i_sb)->bitmap_lock); in exfat_free_cluster()
244 next = p_chain->dir; in exfat_find_last_cluster()
245 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_find_last_cluster()
246 *ret_clu = next + p_chain->size - 1; in exfat_find_last_cluster()
254 return -EIO; in exfat_find_last_cluster()
257 if (p_chain->size != count) { in exfat_find_last_cluster()
260 p_chain->size, count); in exfat_find_last_cluster()
261 return -EIO; in exfat_find_last_cluster()
270 struct super_block *sb = dir->i_sb; in exfat_zeroed_cluster()
276 last_blknr = blknr + sbi->sect_per_clus; in exfat_zeroed_cluster()
278 if (last_blknr > sbi->num_sectors && sbi->num_sectors > 0) { in exfat_zeroed_cluster()
282 sbi->sect_per_clus); in exfat_zeroed_cluster()
283 return -EIO; in exfat_zeroed_cluster()
286 /* Zeroing the unused blocks on this cluster */ in exfat_zeroed_cluster()
290 return -ENOMEM; in exfat_zeroed_cluster()
292 memset(bh->b_data, 0, sb->s_blocksize); in exfat_zeroed_cluster()
299 return sync_blockdev_range(sb->s_bdev, in exfat_zeroed_cluster()
301 EXFAT_BLK_TO_B(last_blknr, sb) - 1); in exfat_zeroed_cluster()
309 int ret = -ENOSPC; in exfat_alloc_cluster()
312 struct super_block *sb = inode->i_sb; in exfat_alloc_cluster()
317 if (unlikely(total_cnt < sbi->used_clusters)) { in exfat_alloc_cluster()
320 __func__, total_cnt, sbi->used_clusters); in exfat_alloc_cluster()
321 return -EIO; in exfat_alloc_cluster()
324 if (num_alloc > total_cnt - sbi->used_clusters) in exfat_alloc_cluster()
325 return -ENOSPC; in exfat_alloc_cluster()
327 mutex_lock(&sbi->bitmap_lock); in exfat_alloc_cluster()
329 hint_clu = p_chain->dir; in exfat_alloc_cluster()
330 /* find new cluster */ in exfat_alloc_cluster()
332 if (sbi->clu_srch_ptr < EXFAT_FIRST_CLUSTER) { in exfat_alloc_cluster()
333 exfat_err(sb, "sbi->clu_srch_ptr is invalid (%u)", in exfat_alloc_cluster()
334 sbi->clu_srch_ptr); in exfat_alloc_cluster()
335 sbi->clu_srch_ptr = EXFAT_FIRST_CLUSTER; in exfat_alloc_cluster()
338 hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr); in exfat_alloc_cluster()
340 ret = -ENOSPC; in exfat_alloc_cluster()
345 /* check cluster validation */ in exfat_alloc_cluster()
347 if (hint_clu != sbi->num_clusters) in exfat_alloc_cluster()
348 exfat_err(sb, "hint_cluster is invalid (%u), rewind to the first cluster", in exfat_alloc_cluster()
351 p_chain->flags = ALLOC_FAT_CHAIN; in exfat_alloc_cluster()
354 p_chain->dir = EXFAT_EOF_CLUSTER; in exfat_alloc_cluster()
359 p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_alloc_cluster()
360 if (exfat_chain_cont_cluster(sb, p_chain->dir, in exfat_alloc_cluster()
361 p_chain->size)) { in exfat_alloc_cluster()
362 ret = -EIO; in exfat_alloc_cluster()
365 p_chain->flags = ALLOC_FAT_CHAIN; in exfat_alloc_cluster()
370 ret = -EIO; in exfat_alloc_cluster()
375 if (p_chain->flags == ALLOC_FAT_CHAIN) { in exfat_alloc_cluster()
377 ret = -EIO; in exfat_alloc_cluster()
382 if (p_chain->dir == EXFAT_EOF_CLUSTER) { in exfat_alloc_cluster()
383 p_chain->dir = new_clu; in exfat_alloc_cluster()
384 } else if (p_chain->flags == ALLOC_FAT_CHAIN) { in exfat_alloc_cluster()
386 ret = -EIO; in exfat_alloc_cluster()
390 p_chain->size++; in exfat_alloc_cluster()
394 if (p_chain->size == num_alloc) { in exfat_alloc_cluster()
395 sbi->clu_srch_ptr = hint_clu; in exfat_alloc_cluster()
396 sbi->used_clusters += num_alloc; in exfat_alloc_cluster()
398 mutex_unlock(&sbi->bitmap_lock); in exfat_alloc_cluster()
403 if (hint_clu >= sbi->num_clusters) { in exfat_alloc_cluster()
406 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_alloc_cluster()
407 if (exfat_chain_cont_cluster(sb, p_chain->dir, in exfat_alloc_cluster()
408 p_chain->size)) { in exfat_alloc_cluster()
409 ret = -EIO; in exfat_alloc_cluster()
412 p_chain->flags = ALLOC_FAT_CHAIN; in exfat_alloc_cluster()
419 mutex_unlock(&sbi->bitmap_lock); in exfat_alloc_cluster()
430 if (!p_chain->dir || p_chain->dir == EXFAT_EOF_CLUSTER) { in exfat_count_num_clusters()
435 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_count_num_clusters()
436 *ret_count = p_chain->size; in exfat_count_num_clusters()
440 clu = p_chain->dir; in exfat_count_num_clusters()
442 for (i = EXFAT_FIRST_CLUSTER; i < sbi->num_clusters; i++) { in exfat_count_num_clusters()
445 return -EIO; in exfat_count_num_clusters()