Commit 1e96b7ca authored by Duane Griffin's avatar Duane Griffin Committed by Linus Torvalds

HFS+: refactor ASCII to unicode conversion routine for later reuse

The HFS+ filesystem is case-insensitive and does automatic unicode
decomposition by default, but does not provide custom dentry operations.  This
can lead to multiple dentries being cached for lookups on a filename with
varying case and/or character (de)composition.

These patches add custom dentry hash and comparison operations for
case-sensitive and/or automatically decomposing HFS+ filesystems.  Unicode
decomposition and case-folding are performed as required to ensure equivalent
filenames are hashed to the same values and compare as equal.

This patch:

Refactor existing HFS+ ASCII to unicode string conversion routine to split out
character conversion functionality.  This will be reused by the custom dentry
hash and comparison routines.  This approach avoids unnecessary memory
allocation compared to using the string conversion routine directly in the new
functions.

[akpm@linux-foundation.org: avoid use-of-uninitialised]
Signed-off-by: default avatarDuane Griffin <duaneg@dghda.com>
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 29bc5b4f
...@@ -239,58 +239,75 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c ...@@ -239,58 +239,75 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c
return res; return res;
} }
int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, const char *astr, int len) /*
* Convert one or more ASCII characters into a single unicode character.
* Returns the number of ASCII characters corresponding to the unicode char.
*/
static inline int asc2unichar(struct super_block *sb, const char *astr, int len,
wchar_t *uc)
{ {
struct nls_table *nls = HFSPLUS_SB(sb).nls; int size = HFSPLUS_SB(sb).nls->char2uni(astr, len, uc);
int size, off, decompose; if (size <= 0) {
*uc = '?';
size = 1;
}
switch (*uc) {
case 0x2400:
*uc = 0;
break;
case ':':
*uc = '/';
break;
}
return size;
}
/* Decomposes a single unicode character. */
static inline u16 *decompose_unichar(wchar_t uc, int *size)
{
int off;
off = hfsplus_decompose_table[(uc >> 12) & 0xf];
if (off == 0 || off == 0xffff)
return NULL;
off = hfsplus_decompose_table[off + ((uc >> 8) & 0xf)];
if (!off)
return NULL;
off = hfsplus_decompose_table[off + ((uc >> 4) & 0xf)];
if (!off)
return NULL;
off = hfsplus_decompose_table[off + (uc & 0xf)];
*size = off & 3;
if (*size == 0)
return NULL;
return hfsplus_decompose_table + (off / 4);
}
int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
const char *astr, int len)
{
int size, dsize, decompose;
u16 *dstr, outlen = 0;
wchar_t c; wchar_t c;
u16 outlen = 0;
decompose = !(HFSPLUS_SB(sb).flags & HFSPLUS_SB_NODECOMPOSE); decompose = !(HFSPLUS_SB(sb).flags & HFSPLUS_SB_NODECOMPOSE);
while (outlen < HFSPLUS_MAX_STRLEN && len > 0) { while (outlen < HFSPLUS_MAX_STRLEN && len > 0) {
size = nls->char2uni(astr, len, &c); size = asc2unichar(sb, astr, len, &c);
if (size <= 0) {
c = '?'; if (decompose && (dstr = decompose_unichar(c, &dsize))) {
size = 1; if (outlen + dsize > HFSPLUS_MAX_STRLEN)
}
astr += size;
len -= size;
switch (c) {
case 0x2400:
c = 0;
break;
case ':':
c = '/';
break;
}
if (c >= 0xc0 && decompose) {
off = hfsplus_decompose_table[(c >> 12) & 0xf];
if (!off)
goto done;
if (off == 0xffff) {
goto done;
}
off = hfsplus_decompose_table[off + ((c >> 8) & 0xf)];
if (!off)
goto done;
off = hfsplus_decompose_table[off + ((c >> 4) & 0xf)];
if (!off)
goto done;
off = hfsplus_decompose_table[off + (c & 0xf)];
size = off & 3;
if (!size)
goto done;
off /= 4;
if (outlen + size > HFSPLUS_MAX_STRLEN)
break; break;
do { do {
ustr->unicode[outlen++] = cpu_to_be16(hfsplus_decompose_table[off++]); ustr->unicode[outlen++] = cpu_to_be16(*dstr++);
} while (--size > 0); } while (--dsize > 0);
continue; } else
} ustr->unicode[outlen++] = cpu_to_be16(c);
done:
ustr->unicode[outlen++] = cpu_to_be16(c); astr += size;
len -= size;
} }
ustr->length = cpu_to_be16(outlen); ustr->length = cpu_to_be16(outlen);
if (len > 0) if (len > 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment