diff options
author | Yuezhang Mo <Yuezhang.Mo@sony.com> | 2023-07-20 16:22:53 +0800 |
---|---|---|
committer | Namjae Jeon <linkinjeon@kernel.org> | 2023-09-12 22:09:09 +0900 |
commit | 8580f1b68a928479ed19f8613504b88562cf45ff (patch) | |
tree | c5b5a382eb37a3136281c9283119f1158ff24e52 | |
parent | c7782c4556d0bd1212827c981aca5124a748ae62 (diff) | |
download | exfatprogs-8580f1b68a928479ed19f8613504b88562cf45ff.tar.gz |
Revert "fsck: Add the capability to fix zero size directory"
This reverts commit fcd68a50e104b7f3bea3d893eaa883db033e10de.
The zero-size directory is compliant with the exFAT specification,
does not need repairing.
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Acked-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
-rw-r--r-- | fsck/fsck.c | 50 | ||||
-rw-r--r-- | fsck/repair.c | 1 | ||||
-rw-r--r-- | fsck/repair.h | 2 | ||||
-rw-r--r-- | include/exfat_dir.h | 1 | ||||
-rw-r--r-- | lib/exfat_dir.c | 4 |
5 files changed, 7 insertions, 51 deletions
diff --git a/fsck/fsck.c b/fsck/fsck.c index 612f158..20f3453 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -103,31 +103,21 @@ static void usage(char *name) }) static int check_clus_chain(struct exfat_de_iter *de_iter, - struct exfat_inode *node) + struct exfat_inode *node) { struct exfat *exfat = de_iter->exfat; struct exfat_dentry *stream_de; - clus_t clus, prev, next, new_clus; + clus_t clus, prev, next; uint64_t count, max_count; - int err; clus = node->first_clus; prev = EXFAT_EOF_CLUSTER; count = 0; max_count = DIV_ROUND_UP(node->size, exfat->clus_size); - if (node->size == 0 && node->first_clus == EXFAT_FREE_CLUSTER) { - /* locate a cluster for the empty dir if the dir starts with EXFAT_FREE_CLUSTER */ - if (node->attr & ATTR_SUBDIR) { - if (repair_file_ask(de_iter, node, - ER_DE_FIRST_CLUS, - "size %#" PRIx64 ", but the first cluster %#x", - node->size, node->first_clus)) - goto allocate_cluster; - return -EINVAL; - } + if (node->size == 0 && node->first_clus == EXFAT_FREE_CLUSTER) return 0; - } + /* the first cluster is wrong */ if ((node->size == 0 && node->first_clus != EXFAT_FREE_CLUSTER) || (node->size > 0 && !exfat_heap_clus(exfat, node->first_clus))) { @@ -225,38 +215,6 @@ static int check_clus_chain(struct exfat_de_iter *de_iter, } return 0; -allocate_cluster: - exfat_de_iter_get_dirty(de_iter, 1, &stream_de); - err = exfat_find_free_cluster(exfat, exfat->start_clu, &new_clus); - if (err) { - exfat->start_clu = EXFAT_FIRST_CLUSTER; - exfat_err("failed to find a free cluster\n"); - return -ENOSPC; - } - exfat->start_clu = new_clus; - - if (exfat_set_fat(exfat, new_clus, EXFAT_EOF_CLUSTER)) - return -EIO; - - /* zero out the new cluster */ - if (exfat_write(exfat->blk_dev->dev_fd, exfat->zero_cluster, - exfat->clus_size, exfat_c2o(exfat, new_clus)) != - (ssize_t)exfat->clus_size) { - exfat_err("failed to fill new cluster with zeroes\n"); - return -EIO; - } - - /* modify the number of cluster form 0 to 1 */ - count = 1; - stream_de->stream_start_clu = cpu_to_le32(new_clus); - stream_de->stream_size = cpu_to_le64(count * exfat->clus_size); - stream_de->stream_valid_size = cpu_to_le64(count * exfat->clus_size); - stream_de->dentry.stream.flags |= EXFAT_SF_CONTIGUOUS; - node->first_clus = new_clus; - node->size = count * exfat->clus_size; - node->is_contiguous = true; - exfat_bitmap_set(exfat->alloc_bitmap, new_clus); - return 1; truncate_file: node->size = count * exfat->clus_size; if (!exfat_heap_clus(exfat, prev)) diff --git a/fsck/repair.c b/fsck/repair.c index ba02622..f983ee1 100644 --- a/fsck/repair.c +++ b/fsck/repair.c @@ -62,7 +62,6 @@ static struct exfat_repair_problem problems[] = { {ER_FILE_LARGER_SIZE, ERF_PREEN_YES, ERP_TRUNCATE, 0, 0, 0}, {ER_FILE_DUPLICATED_CLUS, ERF_PREEN_YES, ERP_TRUNCATE, 0, 0, 0}, {ER_FILE_ZERO_NOFAT, ERF_PREEN_YES, ERP_FIX, 0, 0, 0}, - {ER_DE_FIRST_CLUS, ERF_PREEN_YES, ERP_FIX, 0, 0, 0} }; static struct exfat_repair_problem *find_problem(er_problem_code_t prcode) diff --git a/fsck/repair.h b/fsck/repair.h index a387e5b..634cc49 100644 --- a/fsck/repair.h +++ b/fsck/repair.h @@ -26,7 +26,7 @@ #define ER_FILE_LARGER_SIZE 0x00002005 #define ER_FILE_DUPLICATED_CLUS 0x00002006 #define ER_FILE_ZERO_NOFAT 0x00002007 -#define ER_DE_FIRST_CLUS 0x00002008 + typedef unsigned int er_problem_code_t; struct exfat_fsck; diff --git a/include/exfat_dir.h b/include/exfat_dir.h index 61f11cd..174c501 100644 --- a/include/exfat_dir.h +++ b/include/exfat_dir.h @@ -81,7 +81,6 @@ int exfat_update_file_dentry_set(struct exfat *exfat, int exfat_build_file_dentry_set(struct exfat *exfat, const char *name, unsigned short attr, struct exfat_dentry **dentry_set, int *dentry_count); -int exfat_find_free_cluster(struct exfat *exfat, clus_t start, clus_t *new_clu); int exfat_add_dentry_set(struct exfat *exfat, struct exfat_dentry_loc *loc, struct exfat_dentry *dset, int dcount, bool need_next_loc); diff --git a/lib/exfat_dir.c b/lib/exfat_dir.c index 3450fd9..c3c4183 100644 --- a/lib/exfat_dir.c +++ b/lib/exfat_dir.c @@ -689,7 +689,7 @@ int exfat_update_file_dentry_set(struct exfat *exfat, return 0; } -int exfat_find_free_cluster(struct exfat *exfat, +static int find_free_cluster(struct exfat *exfat, clus_t start, clus_t *new_clu) { clus_t end = le32_to_cpu(exfat->bs->bsx.clu_count) + @@ -816,7 +816,7 @@ static int exfat_alloc_cluster(struct exfat *exfat, struct exfat_inode *inode, if ((need_dset && !inode->dentry_set) || inode->is_contiguous) return -EINVAL; - err = exfat_find_free_cluster(exfat, exfat->start_clu, new_clu); + err = find_free_cluster(exfat, exfat->start_clu, new_clu); if (err) { exfat->start_clu = EXFAT_FIRST_CLUSTER; exfat_err("failed to find an free cluster\n"); |