Commit 5be94d3e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] centralize some nls helpers

This patch adds common nls_tolower, nls_toupper and nls_strnicmp helpers to
nls.h and uses them in various filesystems instead of local duplicates.

The situation for ncpfs isn't as nice as it allows to compile without nls
support even if the kernel has CONFIG_NLS set, so we need wrappers there.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 94486dbd
...@@ -93,14 +93,6 @@ static void dump_de(struct msdos_dir_entry *de) ...@@ -93,14 +93,6 @@ static void dump_de(struct msdos_dir_entry *de)
} }
#endif #endif
static inline unsigned char
fat_tolower(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2lower[c];
return nc ? nc : c;
}
static inline int static inline int
fat_short2uni(struct nls_table *t, unsigned char *c, int clen, wchar_t *uni) fat_short2uni(struct nls_table *t, unsigned char *c, int clen, wchar_t *uni)
{ {
...@@ -140,17 +132,6 @@ fat_short2lower_uni(struct nls_table *t, unsigned char *c, int clen, wchar_t *un ...@@ -140,17 +132,6 @@ fat_short2lower_uni(struct nls_table *t, unsigned char *c, int clen, wchar_t *un
return charlen; return charlen;
} }
static int
fat_strnicmp(struct nls_table *t, const unsigned char *s1,
const unsigned char *s2, int len)
{
while(len--)
if (fat_tolower(t, *s1++) != fat_tolower(t, *s2++))
return 1;
return 0;
}
static inline int static inline int
fat_shortname2uni(struct nls_table *nls, unsigned char *buf, int buf_size, fat_shortname2uni(struct nls_table *nls, unsigned char *buf, int buf_size,
wchar_t *uni_buf, unsigned short opt, int lower) wchar_t *uni_buf, unsigned short opt, int lower)
...@@ -311,7 +292,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name, ...@@ -311,7 +292,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name,
:uni16_to_x8(bufname, bufuname, uni_xlate, nls_io); :uni16_to_x8(bufname, bufuname, uni_xlate, nls_io);
if (xlate_len == name_len) if (xlate_len == name_len)
if ((!anycase && !memcmp(name, bufname, xlate_len)) || if ((!anycase && !memcmp(name, bufname, xlate_len)) ||
(anycase && !fat_strnicmp(nls_io, name, bufname, (anycase && !nls_strnicmp(nls_io, name, bufname,
xlate_len))) xlate_len)))
goto Found; goto Found;
...@@ -322,7 +303,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name, ...@@ -322,7 +303,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name,
if (xlate_len != name_len) if (xlate_len != name_len)
continue; continue;
if ((!anycase && !memcmp(name, bufname, xlate_len)) || if ((!anycase && !memcmp(name, bufname, xlate_len)) ||
(anycase && !fat_strnicmp(nls_io, name, bufname, (anycase && !nls_strnicmp(nls_io, name, bufname,
xlate_len))) xlate_len)))
goto Found; goto Found;
} }
......
...@@ -1115,22 +1115,6 @@ ncp_ClearPhysicalRecord(struct ncp_server *server, const char *file_id, ...@@ -1115,22 +1115,6 @@ ncp_ClearPhysicalRecord(struct ncp_server *server, const char *file_id,
* from the vfat file system and hints from Petr Vandrovec. * from the vfat file system and hints from Petr Vandrovec.
*/ */
inline unsigned char
ncp__tolower(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2lower[c];
return nc ? nc : c;
}
inline unsigned char
ncp__toupper(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2upper[c];
return nc ? nc : c;
}
int int
ncp__io2vol(struct ncp_server *server, unsigned char *vname, unsigned int *vlen, ncp__io2vol(struct ncp_server *server, unsigned char *vname, unsigned int *vlen,
const unsigned char *iname, unsigned int ilen, int cc) const unsigned char *iname, unsigned int ilen, int cc)
...@@ -1346,16 +1330,3 @@ ncp__vol2io(unsigned char *iname, unsigned int *ilen, ...@@ -1346,16 +1330,3 @@ ncp__vol2io(unsigned char *iname, unsigned int *ilen,
} }
#endif #endif
inline int
ncp_strnicmp(struct nls_table *t, const unsigned char *s1,
const unsigned char *s2, int n)
{
int i;
for (i=0; i<n; i++)
if (ncp_tolower(t, s1[i]) != ncp_tolower(t, s2[i]))
return 1;
return 0;
}
...@@ -132,8 +132,6 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln ...@@ -132,8 +132,6 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
#ifdef CONFIG_NCPFS_NLS #ifdef CONFIG_NCPFS_NLS
unsigned char ncp__tolower(struct nls_table *, unsigned char);
unsigned char ncp__toupper(struct nls_table *, unsigned char);
int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *, int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
const unsigned char *, unsigned int, int); const unsigned char *, unsigned int, int);
int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *, int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
...@@ -141,8 +139,10 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *, ...@@ -141,8 +139,10 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
#define NCP_ESC ':' #define NCP_ESC ':'
#define NCP_IO_TABLE(dentry) (NCP_SERVER((dentry)->d_inode)->nls_io) #define NCP_IO_TABLE(dentry) (NCP_SERVER((dentry)->d_inode)->nls_io)
#define ncp_tolower(t, c) ncp__tolower(t, c) #define ncp_tolower(t, c) nls_tolower(t, c)
#define ncp_toupper(t, c) ncp__toupper(t, c) #define ncp_toupper(t, c) nls_toupper(t, c)
#define ncp_strnicmp(t, s1, s2, len) \
nls_strnicmp(t, s1, s2, len)
#define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U) #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U)
#define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U) #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U)
...@@ -159,11 +159,19 @@ int ncp__vol2io(unsigned char *, unsigned int *, ...@@ -159,11 +159,19 @@ int ncp__vol2io(unsigned char *, unsigned int *,
#define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U) #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U)
#define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U) #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U)
#endif /* CONFIG_NCPFS_NLS */
int static inline int ncp_strnicmp(struct nls_table *t, const unsigned char *s1,
ncp_strnicmp(struct nls_table *, const unsigned char *s2, int len)
const unsigned char *, const unsigned char *, int); {
while (len--) {
if (tolower(*s1++) != tolower(*s2++))
return 1;
}
return 0;
}
#endif /* CONFIG_NCPFS_NLS */
#define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time) #define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time)
#define NCP_MAX_AGE(server) ((server)->dentry_ttl) #define NCP_MAX_AGE(server) ((server)->dentry_ttl)
......
...@@ -73,33 +73,6 @@ static int vfat_revalidate(struct dentry *dentry, struct nameidata *nd) ...@@ -73,33 +73,6 @@ static int vfat_revalidate(struct dentry *dentry, struct nameidata *nd)
return ret; return ret;
} }
static inline unsigned char
vfat_tolower(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2lower[c];
return nc ? nc : c;
}
static inline unsigned char
vfat_toupper(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2upper[c];
return nc ? nc : c;
}
static inline int
vfat_strnicmp(struct nls_table *t, const unsigned char *s1,
const unsigned char *s2, int len)
{
while(len--)
if (vfat_tolower(t, *s1++) != vfat_tolower(t, *s2++))
return 1;
return 0;
}
/* returns the length of a struct qstr, ignoring trailing dots */ /* returns the length of a struct qstr, ignoring trailing dots */
static unsigned int vfat_striptail_len(struct qstr *qstr) static unsigned int vfat_striptail_len(struct qstr *qstr)
{ {
...@@ -142,7 +115,7 @@ static int vfat_hashi(struct dentry *dentry, struct qstr *qstr) ...@@ -142,7 +115,7 @@ static int vfat_hashi(struct dentry *dentry, struct qstr *qstr)
hash = init_name_hash(); hash = init_name_hash();
while (len--) while (len--)
hash = partial_name_hash(vfat_tolower(t, *name++), hash); hash = partial_name_hash(nls_tolower(t, *name++), hash);
qstr->hash = end_name_hash(hash); qstr->hash = end_name_hash(hash);
return 0; return 0;
...@@ -160,7 +133,7 @@ static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b) ...@@ -160,7 +133,7 @@ static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b)
alen = vfat_striptail_len(a); alen = vfat_striptail_len(a);
blen = vfat_striptail_len(b); blen = vfat_striptail_len(b);
if (alen == blen) { if (alen == blen) {
if (vfat_strnicmp(t, a->name, b->name, alen) == 0) if (nls_strnicmp(t, a->name, b->name, alen) == 0)
return 0; return 0;
} }
return 1; return 1;
...@@ -341,7 +314,7 @@ static inline int to_shortname_char(struct nls_table *nls, ...@@ -341,7 +314,7 @@ static inline int to_shortname_char(struct nls_table *nls,
info->upper = 0; info->upper = 0;
} }
buf[0] = vfat_toupper(nls, buf[0]); buf[0] = nls_toupper(nls, buf[0]);
if (isalpha(buf[0])) { if (isalpha(buf[0])) {
if (buf[0] == prev) if (buf[0] == prev)
info->lower = 0; info->lower = 0;
......
...@@ -33,6 +33,31 @@ extern int utf8_mbstowcs(wchar_t *, const __u8 *, int); ...@@ -33,6 +33,31 @@ extern int utf8_mbstowcs(wchar_t *, const __u8 *, int);
extern int utf8_wctomb(__u8 *, wchar_t, int); extern int utf8_wctomb(__u8 *, wchar_t, int);
extern int utf8_wcstombs(__u8 *, const wchar_t *, int); extern int utf8_wcstombs(__u8 *, const wchar_t *, int);
static inline unsigned char nls_tolower(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2lower[c];
return nc ? nc : c;
}
static inline unsigned char nls_toupper(struct nls_table *t, unsigned char c)
{
unsigned char nc = t->charset2upper[c];
return nc ? nc : c;
}
static inline int nls_strnicmp(struct nls_table *t, const unsigned char *s1,
const unsigned char *s2, int len)
{
while (len--) {
if (nls_tolower(t, *s1++) != nls_tolower(t, *s2++))
return 1;
}
return 0;
}
#define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name)) #define MODULE_ALIAS_NLS(name) MODULE_ALIAS("nls_" __stringify(name))
#endif /* _LINUX_NLS_H */ #endif /* _LINUX_NLS_H */
......
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