Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105872
b: refs/heads/master
c: 98a1516
h: refs/heads/master
v: v3
  • Loading branch information
OGAWA Hirofumi authored and Linus Torvalds committed Jul 25, 2008
1 parent ad26958 commit be0c2e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d688611674cc9c265ee67e89d2ea8bf060c17e8d
refs/heads/master: 98a15160049fc1a0f822047f33ff513906a35567
42 changes: 26 additions & 16 deletions trunk/fs/fat/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,19 @@ static int fat_parse_long(struct inode *dir, loff_t *pos,
return 0;
}

/*
* Maximum buffer size of short name.
* [(MSDOS_NAME + '.') * max one char + nul]
* For msdos style, ['.' (hidden) + MSDOS_NAME + '.' + nul]
*/
#define FAT_MAX_SHORT_SIZE ((MSDOS_NAME + 1) * NLS_MAX_CHARSET_SIZE + 1)
/*
* Maximum buffer size of unicode chars from slots.
* [(max longname slots * 13 (size in a slot) + nul) * sizeof(wchar_t)]
*/
#define FAT_MAX_UNI_CHARS ((MSDOS_SLOTS - 1) * 13 + 1)
#define FAT_MAX_UNI_SIZE (FAT_MAX_UNI_CHARS * sizeof(wchar_t))

/*
* Return values: negative -> error, 0 -> not found, positive -> found,
* value is the total amount of slots, including the shortname entry.
Expand All @@ -340,15 +353,11 @@ int fat_search_long(struct inode *inode, const unsigned char *name,
wchar_t bufuname[14];
wchar_t *unicode = NULL;
unsigned char work[MSDOS_NAME];
unsigned char *bufname = NULL;
unsigned char bufname[FAT_MAX_SHORT_SIZE];
unsigned short opt_shortname = sbi->options.shortname;
loff_t cpos = 0;
int chl, i, j, last_u, err, len;

bufname = __getname();
if (!bufname)
return -ENOMEM;

err = -ENOENT;
while (1) {
if (fat_get_entry(inode, &cpos, &bh, &de) == -1)
Expand Down Expand Up @@ -414,14 +423,17 @@ int fat_search_long(struct inode *inode, const unsigned char *name,

/* Compare shortname */
bufuname[last_u] = 0x0000;
len = fat_uni_to_x8(sbi, bufuname, bufname, PATH_MAX);
len = fat_uni_to_x8(sbi, bufuname, bufname, sizeof(bufname));
if (fat_name_match(sbi, name, name_len, bufname, len))
goto found;

if (nr_slots) {
void *longname = unicode + FAT_MAX_UNI_CHARS;
int size = PATH_MAX - FAT_MAX_UNI_SIZE;

/* Compare longname */
len = fat_uni_to_x8(sbi, unicode, bufname, PATH_MAX);
if (fat_name_match(sbi, name, name_len, bufname, len))
len = fat_uni_to_x8(sbi, unicode, longname, size);
if (fat_name_match(sbi, name, name_len, longname, len))
goto found;
}
}
Expand All @@ -435,8 +447,6 @@ int fat_search_long(struct inode *inode, const unsigned char *name,
sinfo->i_pos = fat_make_i_pos(sb, sinfo->bh, sinfo->de);
err = 0;
end_of_dir:
if (bufname)
__putname(bufname);
if (unicode)
__putname(unicode);

Expand Down Expand Up @@ -466,7 +476,8 @@ static int __fat_readdir(struct inode *inode, struct file *filp, void *dirent,
unsigned char nr_slots;
wchar_t bufuname[14];
wchar_t *unicode = NULL;
unsigned char c, work[MSDOS_NAME], bufname[56], *ptname = bufname;
unsigned char c, work[MSDOS_NAME];
unsigned char bufname[FAT_MAX_SHORT_SIZE], *ptname = bufname;
unsigned short opt_shortname = sbi->options.shortname;
int isvfat = sbi->options.isvfat;
int nocase = sbi->options.nocase;
Expand Down Expand Up @@ -620,11 +631,10 @@ static int __fat_readdir(struct inode *inode, struct file *filp, void *dirent,
fill_name = bufname;
fill_len = i;
if (!short_only && nr_slots) {
/* convert the unicode long name. 261 is maximum size
* of unicode buffer. (13 * slots + nul) */
void *longname = unicode + 261;
int buf_size = PATH_MAX - (261 * sizeof(unicode[0]));
int long_len = fat_uni_to_x8(sbi, unicode, longname, buf_size);
void *longname = unicode + FAT_MAX_UNI_CHARS;
int long_len, size = PATH_MAX - FAT_MAX_UNI_SIZE;

long_len = fat_uni_to_x8(sbi, unicode, longname, size);

if (!both) {
fill_name = longname;
Expand Down

0 comments on commit be0c2e3

Please sign in to comment.