Skip to content

Commit

Permalink
fsck: move decode name into exfat_repair_rename_ask()
Browse files Browse the repository at this point in the history
Decoded filename is only needed if rename is needed, so moved
decoded filename into exfat_repair_rename_ask().

Signed-off-by: Yuezhang Mo <[email protected]>
Reviewed-by: Aoyama Wataru <[email protected]>
  • Loading branch information
YuezhangMo committed Jul 18, 2024
1 parent 2d37726 commit 1bcb87c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
31 changes: 11 additions & 20 deletions fsck/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ static int handle_duplicated_filename(struct exfat_de_iter *iter,
{
int ret;
struct exfat_lookup_filter filter;
char filename[PATH_MAX + 1] = {0};

ret = exfat_lookup_file_by_utf16name(iter->exfat, iter->parent,
inode->name, &filter);
Expand All @@ -660,14 +659,7 @@ static int handle_duplicated_filename(struct exfat_de_iter *iter,
if (exfat_de_iter_device_offset(iter) == filter.out.dev_offset)
return 0;

ret = exfat_utf16_dec(inode->name, NAME_BUFFER_SIZE, filename,
PATH_MAX);
if (ret < 0) {
exfat_err("failed to decode filename\n");
return ret;
}

return exfat_repair_rename_ask(&exfat_fsck, iter, filename,
return exfat_repair_rename_ask(&exfat_fsck, iter, inode->name,
ER_DE_DUPLICATED_NAME, "filename is duplicated");
}

Expand Down Expand Up @@ -713,21 +705,20 @@ static int check_name_dentry_set(struct exfat_de_iter *iter,
return ret;
}

const __le16 MSDOS_DOT[ENTRY_NAME_MAX] = {cpu_to_le16(46), 0, };
const __le16 MSDOS_DOTDOT[ENTRY_NAME_MAX] = {cpu_to_le16(46), cpu_to_le16(46), 0, };
#define MSDOS_DOT cpu_to_le16('.')

static int handle_dot_dotdot_filename(struct exfat_de_iter *iter,
struct exfat_dentry *dentry,
__le16 *filename,
int strm_name_len)
{
char *filename;
int i;

if (!memcmp(dentry->name_unicode, MSDOS_DOT, strm_name_len * 2))
filename = ".";
else if (!memcmp(dentry->name_unicode, MSDOS_DOTDOT,
strm_name_len * 2))
filename = "..";
else
for (i = 0; i < strm_name_len; i++) {
if (filename[i] != MSDOS_DOT)
return 0;
}

if (filename[i])
return 0;

return exfat_repair_rename_ask(&exfat_fsck, iter, filename,
Expand Down Expand Up @@ -817,7 +808,7 @@ static int read_file_dentry_set(struct exfat_de_iter *iter,
}

if (file_de->file_num_ext == 2 && stream_de->stream_name_len <= 2) {
ret = handle_dot_dotdot_filename(iter, dentry,
ret = handle_dot_dotdot_filename(iter, node->name,
stream_de->stream_name_len);
if (ret < 0) {
*skip_dentries = file_de->file_num_ext + 1;
Expand Down
8 changes: 7 additions & 1 deletion fsck/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,15 @@ static int generate_rename(struct exfat_de_iter *iter, __le16 *utf16_name,
}

int exfat_repair_rename_ask(struct exfat_fsck *fsck, struct exfat_de_iter *iter,
char *old_name, er_problem_code_t prcode, char *error_msg)
__le16 *uname, er_problem_code_t prcode, char *error_msg)
{
int num;
char old_name[PATH_MAX + 1] = {0};

if (exfat_utf16_dec(uname, NAME_BUFFER_SIZE, old_name, PATH_MAX) <= 0) {
exfat_err("failed to decode filename\n");
return -EINVAL;
}

ask_again:
num = exfat_repair_ask(fsck, prcode, "ERROR: '%s' %s.\n%s",
Expand Down
2 changes: 1 addition & 1 deletion fsck/repair.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ int exfat_repair_ask(struct exfat_fsck *fsck, er_problem_code_t prcode,
const char *fmt, ...);

int exfat_repair_rename_ask(struct exfat_fsck *fsck, struct exfat_de_iter *iter,
char *old_name, er_problem_code_t prcode, char *error_msg);
__le16 *uname, er_problem_code_t prcode, char *error_msg);
#endif

0 comments on commit 1bcb87c

Please sign in to comment.