[snip ]
on 2007-02-21?ha ha <[EMAIL PROTECTED]> wrote :
>First when the ntfs was mounted by ntfs-3g
> you could not find the files for doucments name in Chinese
I am also a Chinese people , in this case , you should specify suitable locale
set when mount
for example , you can do like this :
ntfs-3g /dev/sda1 /tmp/disk1 -o locale=zh_CN.GB2312
and then ,if you can use ssh client to login the linux , and execute the
command : "ls /tmp/disk1 " ,it will show correct Chinese files or dirs . The
reason of using ssh client is that it supports displaying Chinese Set , in
contrast , the black console don't display Chinese Character though ntfs-3g
driver has supported Chinese locale .
FYI : if you are ready for porting the ntfs-3g to embeded platform , for
example , ARM platform , locale is extravagant , because porting locale is more
difficult ,at least for me it is like this .
you can use libiconv instead of locale on ARM or others embeded environment .
I sent a mail last year about this aspec , I have tested it ,it works OK !
FYI: mail sent before :
Hello Szaka,
I found that ntfs-3g support i18n very well by using Locale ,it is good on
PC ,because on general PC, our locale can works normal for linux distribution,
for example ,Redhat.xx
But for embeded development , general board has limited resources ,such as
memory ,CPU speed .
And I tried to build my locale enviroment on my ARM board , I find that that is
a complex thing and so hard to finish . So I supply a easy method to support
simple i18n need .
Maybe ,this will give other arm developers some helps
If it can run on your ARM , I will be very happy .
I modified libntfs/unistr.c ==> ntfs_mbstoucs() and ntfs_ucstombs()
Note :I retain the interface not changed , I only changed its implementation
I tested it OK on my ARM , it should work on PC(I not tested)
prerequisite :
you should download libiconv library from GNU source , I used the version of
1.8 , Now its version changed to 1.11
you only need to coross compile it and copy libiconv.so.0.0 into your /lib/ on
your ARM board .
/* Author is Bob Zhang
* Written time : 20061117
* You can copy it anywhere if you like
* I think ,it should be of part of ntfs-3g
*/
#if defined(HAVE_USE_ICONV)
#include <wchar.h>
#include <iconv.h>
#define SIMPLE_CN "CP936" //Chinsese Simple , if you are of others
language , you can modify it
//you can query it by using command "iconv
--list |grep "your language"
#define UTF_CHARSET "WCHAR_T" //I found that WCHAR_T is OK , I can't
converted into "UTF-8" ,I don't know reason
#endif
#if defined(HAVE_USE_ICONV)
int ntfs_mbstoucs(const char *ins, ntfschar **outs, int outs_len)
{
//defined two varibles :unicode_wchar ? unicode_ntfschar
ntfschar *unicode_ntfschar = NULL;
wchar_t *unicode_wchar = NULL; //later will malloc
char *iconv_char = NULL;
int insize = strlen(ins);
int ucs_len =0; //should = outs_len
int ins_len = 0;
int ucs_bytes_len = 0;
iconv_t cd;
int i=0;
int nconv = 0;
int written_unicode = 0;
char *tt_char = NULL;
mbstate_t mbstate;
const char *s = ins;
ucs_len = outs_len;
unicode_ntfschar = *outs;
ucs_bytes_len = outs_len ;
printf("insize=%d\n",insize);
//ins_len = ((insize + 4) & ~3) /4 + 1;
ins_len = insize;
printf("ins_len = %d\n",ins_len);
/* only test the length of unicode
memset(&mbstate, 0, sizeof(mbstate));
setlocale(LC_ALL,"zh_CN.GB2312");
ins_len = mbsrtowcs(NULL, (const char **)&ins, 0, &mbstate);//
*/
printf("ins_len = %d\n",ins_len);
ins_len++;
if( ! unicode_ntfschar)
{
ucs_len = ins_len;
unicode_ntfschar = (ntfschar *)malloc(ucs_len * sizeof(ntfschar));
if(unicode_ntfschar == NULL)
return -1;
*outs = unicode_ntfschar ;
ucs_bytes_len = ucs_len * sizeof(wchar_t);
}
printf("sizeof(wchar_t) = %d\n",sizeof(wchar_t));
unicode_wchar = (wchar_t *)malloc(ucs_len * sizeof(wchar_t));
if(unicode_wchar == NULL)
{
printf("Can't malloc wchar \n");
return -1;
}
iconv_char = (char *)unicode_wchar ;
tt_char = iconv_char ;
cd = libiconv_open(UTF_CHARSET,SIMPLE_CN); //Chinse to unicode
if (cd == (iconv_t) -1) {
/* Something went wrong. */
if (errno == EINVAL)
printf ("conversion from '%s' to '%s' not available",SIMPLE_CN,UTF_CHARSET);
else
perror ("iconv_open");
/* Terminate the output string. */
*(*outs) = cpu_to_le16(L'\0');
return -1;
}
printf("before iconv_char address =%p\n",iconv_char);
nconv = libiconv(cd, (char **)&ins, &insize, &iconv_char, &ucs_bytes_len);
//cd (conversion descriptor )
if (nconv == (size_t) -1) {
if (errno == EINVAL) {
perror("mbstoucs: iconv error");
return -1;
}else {
perror("mbstoucs: iconv error not EINVAL ");
return -1;
}
}
printf("after iconv() , iconv_char address =%p\n",iconv_char);
printf("tt_char =%ls\n",(wchar_t *)tt_char);
/* Terminate the output string. */
*((wchar_t *) iconv_char) = cpu_to_le16(L'\0');
printf("chinese:%ls\n",unicode_wchar);
written_unicode = (wchar_t *)iconv_char - unicode_wchar ;
for(i=0;i<written_unicode;i++)
{
//assign and endian conversion
unicode_ntfschar[i] = cpu_to_le16(unicode_wchar[i]);
}
unicode_ntfschar[i] = cpu_to_le16(L'\0');
if (libiconv_close (cd) != 0)
perror ("iconv_close");
return written_unicode; //don't include '\0'
}
#endif
------------------------------------------
#if defined(HAVE_USE_ICONV)
int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs,
int outs_len)
{
wchar_t *unicode_wchar = NULL; //later will malloc
char *mbs = *outs; //
char *mbs_start = NULL;
int mbs_len ;
char *iconv_char = NULL;
iconv_t cd;
int i=0;
int nconv = 0;
int written_mbs = 0;
int ucs_len = 0;
int ins_bytes_len = 0;
ucs_len = ins_len+1; //ucs_len is used for malloc wchar data
mbs_len = outs_len;
printf("ucs_len = %d\n",ucs_len);
ins_bytes_len = ins_len*sizeof(wchar_t);
if ( mbs==NULL )
{
mbs_len = (ins_len+1) * sizeof(wchar_t);
mbs=(char *)malloc(mbs_len*sizeof(char));
if(!mbs)
{
return -1;
}
*outs = mbs;
}
unicode_wchar = (wchar_t *)malloc(ucs_len * sizeof(wchar_t));
if(unicode_wchar == NULL )
{
printf("can't malloc unicode_wchar \n");
*(*outs) = '\0';
return -1;
}
for(i=0;i<ins_len;i++)
{
unicode_wchar[i] = (wchar_t)le16_to_cpu(ins[i]);
}
//bob
unicode_wchar[i] = (wchar_t)(L'\0'); //
cd = libiconv_open(SIMPLE_CN,UTF_CHARSET); //Chinse to unicode
if (cd == (iconv_t) -1) {
/* Something went wrong. */
if (errno == EINVAL)
printf ("conversion from '%s' to '%s' not available",UTF_CHARSET,SIMPLE_CN);
else
perror ("libiconv_open");
/* Terminate the output string. */
*(*outs) = '\0';
return -1;
}
mbs_start = mbs;
nconv = libiconv(cd, (char **)&unicode_wchar, &ins_bytes_len , &mbs,
&mbs_len); //cd (conversion descriptor )
if (nconv == (size_t) -1) {
if (errno == EINVAL) {
perror("ucstombs :iconv error");
}else{
perror("ucstombs :iconv error not EINVAL ");
}
*(*outs) = '\0';
return -1;
}
*mbs = '\0';
if (libiconv_close (cd) != 0)
perror ("iconv_close");
return mbs - mbs_start; //
}
#endif-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
ntfs-3g-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel