diff --git a/include/ntfs-3g/unistr.h b/include/ntfs-3g/unistr.h index 639c5033..8cadc3c4 100644 --- a/include/ntfs-3g/unistr.h +++ b/include/ntfs-3g/unistr.h @@ -61,6 +61,7 @@ extern char *ntfs_uppercase_mbs(const char *low, const ntfschar *upcase, u32 upcase_len); extern void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len); +extern u32 ntfs_upcase_build_default(ntfschar **upcase); extern ntfschar *ntfs_locase_table_build(const ntfschar *uc, u32 uc_cnt); extern ntfschar *ntfs_str2ucs(const char *s, int *len); diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index 1d476759..c9ab98bb 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -1251,6 +1251,27 @@ void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len) } } +/* + * Allocate and build the default upcase table + * + * Returns the number of entries + * 0 if failed + */ + +#define UPCASE_LEN 65536 /* default number of entries in upcase */ + +u32 ntfs_upcase_build_default(ntfschar **upcase) +{ + u32 upcase_len; + + *upcase = (ntfschar*)ntfs_malloc(UPCASE_LEN*2); + if (*upcase) { + ntfs_upcase_table_build(*upcase, UPCASE_LEN*2); + upcase_len = UPCASE_LEN; + } + return (upcase_len); +} + /* * Build a table for converting to lower case * diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index 21e68e9a..f43f555f 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -482,13 +482,10 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags) goto error_exit; /* Create the default upcase table. */ - vol->upcase_len = 65536; - vol->upcase = ntfs_malloc(vol->upcase_len * sizeof(ntfschar)); - if (!vol->upcase) + vol->upcase_len = ntfs_upcase_build_default(&vol->upcase); + if (!vol->upcase_len || !vol->upcase) goto error_exit; - - ntfs_upcase_table_build(vol->upcase, - vol->upcase_len * sizeof(ntfschar)); + /* Default with no locase table and case sensitive file names */ vol->locase = (ntfschar*)NULL; NVolSetCaseSensitive(vol);