Lines Matching +full:loc +full:- +full:code

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()
38 static int __exfat_ent_get(struct super_block *sb, unsigned int loc, in __exfat_ent_get() argument
45 sec = FAT_ENT_OFFSET_SECTOR(sb, loc); in __exfat_ent_get()
46 off = FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc); in __exfat_ent_get()
50 return -EIO; in __exfat_ent_get()
52 *content = le32_to_cpu(*(__le32 *)(&bh->b_data[off])); in __exfat_ent_get()
54 /* remap reserved clusters to simplify code */ in __exfat_ent_get()
62 int exfat_ent_set(struct super_block *sb, unsigned int loc, in exfat_ent_set() argument
70 sec = FAT_ENT_OFFSET_SECTOR(sb, loc); in exfat_ent_set()
71 off = FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc); in exfat_ent_set()
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()
85 int exfat_ent_get(struct super_block *sb, unsigned int loc, in exfat_ent_get() argument
91 if (!is_valid_cluster(sbi, loc)) { in exfat_ent_get()
93 loc); in exfat_ent_get()
94 return -EIO; in exfat_ent_get()
97 err = __exfat_ent_get(sb, loc, content); in exfat_ent_get()
101 loc, err); in exfat_ent_get()
108 loc); in exfat_ent_get()
109 return -EIO; in exfat_ent_get()
115 loc); in exfat_ent_get()
116 return -EIO; in exfat_ent_get()
122 loc, *content); 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()
154 sbi->sect_per_clus * num_clusters, GFP_NOFS, 0); in exfat_discard_cluster()
155 if (ret == -EOPNOTSUPP) { in exfat_discard_cluster()
157 sbi->options.discard = 0; in exfat_discard_cluster()
164 struct super_block *sb = inode->i_sb; in __exfat_free_cluster()
171 if (p_chain->dir == EXFAT_FREE_CLUSTER || in __exfat_free_cluster()
172 p_chain->dir == EXFAT_EOF_CLUSTER || in __exfat_free_cluster()
173 p_chain->dir < EXFAT_FIRST_CLUSTER) in __exfat_free_cluster()
177 if (p_chain->size == 0) in __exfat_free_cluster()
181 if (!is_valid_cluster(sbi, p_chain->dir)) { in __exfat_free_cluster()
182 exfat_err(sb, "invalid start cluster (%u)", p_chain->dir); in __exfat_free_cluster()
183 return -EIO; in __exfat_free_cluster()
186 clu = p_chain->dir; in __exfat_free_cluster()
191 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in __exfat_free_cluster()
193 unsigned int last_cluster = p_chain->dir + p_chain->size - 1; in __exfat_free_cluster()
212 } while (num_clusters < p_chain->size); in __exfat_free_cluster()
214 if (sbi->options.discard) in __exfat_free_cluster()
215 exfat_discard_cluster(sb, p_chain->dir, p_chain->size); in __exfat_free_cluster()
238 if (sbi->options.discard) { in __exfat_free_cluster()
242 exfat_discard_cluster(sb, clu - nr_clu + 1, nr_clu); in __exfat_free_cluster()
253 if (num_clusters >= sbi->num_clusters - EXFAT_FIRST_CLUSTER) { in __exfat_free_cluster()
258 exfat_count_used_clusters(sb, &sbi->used_clusters); in __exfat_free_cluster()
265 sbi->used_clusters -= num_clusters; in __exfat_free_cluster()
273 mutex_lock(&EXFAT_SB(inode->i_sb)->bitmap_lock); in exfat_free_cluster()
275 mutex_unlock(&EXFAT_SB(inode->i_sb)->bitmap_lock); in exfat_free_cluster()
286 next = p_chain->dir; in exfat_find_last_cluster()
287 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_find_last_cluster()
288 *ret_clu = next + p_chain->size - 1; in exfat_find_last_cluster()
296 return -EIO; in exfat_find_last_cluster()
297 } while (next != EXFAT_EOF_CLUSTER && count <= p_chain->size); in exfat_find_last_cluster()
299 if (p_chain->size != count) { in exfat_find_last_cluster()
302 p_chain->size, count); in exfat_find_last_cluster()
303 return -EIO; in exfat_find_last_cluster()
312 struct super_block *sb = dir->i_sb; in exfat_zeroed_cluster()
318 last_blknr = blknr + sbi->sect_per_clus; in exfat_zeroed_cluster()
320 if (last_blknr > sbi->num_sectors && sbi->num_sectors > 0) { in exfat_zeroed_cluster()
324 sbi->sect_per_clus); in exfat_zeroed_cluster()
325 return -EIO; in exfat_zeroed_cluster()
332 return -ENOMEM; in exfat_zeroed_cluster()
334 memset(bh->b_data, 0, sb->s_blocksize); in exfat_zeroed_cluster()
341 return sync_blockdev_range(sb->s_bdev, in exfat_zeroed_cluster()
343 EXFAT_BLK_TO_B(last_blknr, sb) - 1); in exfat_zeroed_cluster()
351 int ret = -ENOSPC; in exfat_alloc_cluster()
354 struct super_block *sb = inode->i_sb; in exfat_alloc_cluster()
359 if (unlikely(total_cnt < sbi->used_clusters)) { in exfat_alloc_cluster()
362 __func__, total_cnt, sbi->used_clusters); in exfat_alloc_cluster()
363 return -EIO; in exfat_alloc_cluster()
366 if (num_alloc > total_cnt - sbi->used_clusters) in exfat_alloc_cluster()
367 return -ENOSPC; in exfat_alloc_cluster()
369 mutex_lock(&sbi->bitmap_lock); in exfat_alloc_cluster()
371 hint_clu = p_chain->dir; in exfat_alloc_cluster()
374 if (sbi->clu_srch_ptr < EXFAT_FIRST_CLUSTER) { in exfat_alloc_cluster()
375 exfat_err(sb, "sbi->clu_srch_ptr is invalid (%u)", in exfat_alloc_cluster()
376 sbi->clu_srch_ptr); in exfat_alloc_cluster()
377 sbi->clu_srch_ptr = EXFAT_FIRST_CLUSTER; in exfat_alloc_cluster()
380 hint_clu = exfat_find_free_bitmap(sb, sbi->clu_srch_ptr); in exfat_alloc_cluster()
382 ret = -ENOSPC; in exfat_alloc_cluster()
389 if (hint_clu != sbi->num_clusters) in exfat_alloc_cluster()
393 p_chain->flags = ALLOC_FAT_CHAIN; in exfat_alloc_cluster()
396 p_chain->dir = EXFAT_EOF_CLUSTER; in exfat_alloc_cluster()
401 p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_alloc_cluster()
402 if (exfat_chain_cont_cluster(sb, p_chain->dir, in exfat_alloc_cluster()
403 p_chain->size)) { in exfat_alloc_cluster()
404 ret = -EIO; in exfat_alloc_cluster()
407 p_chain->flags = ALLOC_FAT_CHAIN; in exfat_alloc_cluster()
412 ret = -EIO; in exfat_alloc_cluster()
417 if (p_chain->flags == ALLOC_FAT_CHAIN) { in exfat_alloc_cluster()
419 ret = -EIO; in exfat_alloc_cluster()
424 if (p_chain->dir == EXFAT_EOF_CLUSTER) { in exfat_alloc_cluster()
425 p_chain->dir = new_clu; in exfat_alloc_cluster()
426 } else if (p_chain->flags == ALLOC_FAT_CHAIN) { in exfat_alloc_cluster()
428 ret = -EIO; in exfat_alloc_cluster()
432 p_chain->size++; in exfat_alloc_cluster()
436 if (p_chain->size == num_alloc) { in exfat_alloc_cluster()
437 sbi->clu_srch_ptr = hint_clu; in exfat_alloc_cluster()
438 sbi->used_clusters += num_alloc; in exfat_alloc_cluster()
440 mutex_unlock(&sbi->bitmap_lock); in exfat_alloc_cluster()
445 if (hint_clu >= sbi->num_clusters) { in exfat_alloc_cluster()
448 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_alloc_cluster()
449 if (exfat_chain_cont_cluster(sb, p_chain->dir, in exfat_alloc_cluster()
450 p_chain->size)) { in exfat_alloc_cluster()
451 ret = -EIO; in exfat_alloc_cluster()
454 p_chain->flags = ALLOC_FAT_CHAIN; in exfat_alloc_cluster()
461 mutex_unlock(&sbi->bitmap_lock); in exfat_alloc_cluster()
472 if (!p_chain->dir || p_chain->dir == EXFAT_EOF_CLUSTER) { in exfat_count_num_clusters()
477 if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { in exfat_count_num_clusters()
478 *ret_count = p_chain->size; in exfat_count_num_clusters()
482 clu = p_chain->dir; in exfat_count_num_clusters()
484 for (i = EXFAT_FIRST_CLUSTER; i < sbi->num_clusters; i++) { in exfat_count_num_clusters()
487 return -EIO; in exfat_count_num_clusters()