fs/ntfs3: Rework ntfs_utf16_to_nls

Now ntfs_utf16_to_nls takes length as one of arguments.
If length of symlink > 255, then we tried to convert
length of symlink +- some random number.
Now 255 symbols limit was removed.
Signed-off-by: NKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
上级 9b75450d
...@@ -15,11 +15,10 @@ ...@@ -15,11 +15,10 @@
#include "ntfs_fs.h" #include "ntfs_fs.h"
/* Convert little endian UTF-16 to NLS string. */ /* Convert little endian UTF-16 to NLS string. */
int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni, int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const __le16 *name, u32 len,
u8 *buf, int buf_len) u8 *buf, int buf_len)
{ {
int ret, uni_len, warn; int ret, warn;
const __le16 *ip;
u8 *op; u8 *op;
struct nls_table *nls = sbi->options->nls; struct nls_table *nls = sbi->options->nls;
...@@ -27,18 +26,16 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni, ...@@ -27,18 +26,16 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni,
if (!nls) { if (!nls) {
/* UTF-16 -> UTF-8 */ /* UTF-16 -> UTF-8 */
ret = utf16s_to_utf8s((wchar_t *)uni->name, uni->len, ret = utf16s_to_utf8s(name, len, UTF16_LITTLE_ENDIAN, buf,
UTF16_LITTLE_ENDIAN, buf, buf_len); buf_len);
buf[ret] = '\0'; buf[ret] = '\0';
return ret; return ret;
} }
ip = uni->name;
op = buf; op = buf;
uni_len = uni->len;
warn = 0; warn = 0;
while (uni_len--) { while (len--) {
u16 ec; u16 ec;
int charlen; int charlen;
char dump[5]; char dump[5];
...@@ -49,7 +46,7 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni, ...@@ -49,7 +46,7 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni,
break; break;
} }
ec = le16_to_cpu(*ip++); ec = le16_to_cpu(*name++);
charlen = nls->uni2char(ec, op, buf_len); charlen = nls->uni2char(ec, op, buf_len);
if (charlen > 0) { if (charlen > 0) {
...@@ -304,8 +301,8 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni, ...@@ -304,8 +301,8 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
if (sbi->options->nohidden && (fname->dup.fa & FILE_ATTRIBUTE_HIDDEN)) if (sbi->options->nohidden && (fname->dup.fa & FILE_ATTRIBUTE_HIDDEN))
return 0; return 0;
name_len = ntfs_utf16_to_nls(sbi, (struct le_str *)&fname->name_len, name_len = ntfs_utf16_to_nls(sbi, fname->name, fname->name_len, name,
name, PATH_MAX); PATH_MAX);
if (name_len <= 0) { if (name_len <= 0) {
ntfs_warn(sbi->sb, "failed to convert name for inode %lx.", ntfs_warn(sbi->sb, "failed to convert name for inode %lx.",
ino); ino);
......
...@@ -475,7 +475,7 @@ bool are_bits_set(const ulong *map, size_t bit, size_t nbits); ...@@ -475,7 +475,7 @@ bool are_bits_set(const ulong *map, size_t bit, size_t nbits);
size_t get_set_bits_ex(const ulong *map, size_t bit, size_t nbits); size_t get_set_bits_ex(const ulong *map, size_t bit, size_t nbits);
/* Globals from dir.c */ /* Globals from dir.c */
int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni, int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const __le16 *name, u32 len,
u8 *buf, int buf_len); u8 *buf, int buf_len);
int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len, int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
struct cpu_str *uni, u32 max_ulen, struct cpu_str *uni, u32 max_ulen,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册