centos在root用户下不能使用ibus和mount的中文乱码

(1)root用户下Qt程序不能使用ibus

修改/etc/profile  文件
export QT_IM_MODULE=xim
export XMODIFIERS="@im=ibus"
(2)在windows上显示正常的文件名,在Linux下mount后全部显示为问号

如果需要显示出中文,需要使用uft8模式挂载U盘。
解决中文字符显示问号的方法:
mount /dev/sdb4 /mnt/ho1 -o iocharset=utf8
或者如下命令:
mount /dev/sdb /mnt -t vfat -o codepage=936,iocharset=utf8
mount /dev/sdb /mnt -t vfat -o iocharset=utf8
mount /dev/sdb /mnt -t vfat -o codepage=936,iocharset=gb2312
mount /dev/sdb /mnt -t vfat -o codepage=936,iocharset=gbk
mount /dev/sdb /mnt -t vfat -o codepage=936,iocharset=gb18030

然而,在程序中,使用mount函数来这样挂载,却出现了问题。

首先,我们看看mount函数的定义:

int  mount(const  char  *source,  const char *target, const char *filesystemtype, unsigned long mountflags, const void *data);
source :设备 /dev/sda等;
target :挂载点/mnt/usb等;
*filesystemtype:"minix","ext2", "msdos", "proc", "nfs", "iso9660" ,“vfat”etc.;
mountflags:MS_MGC_VAL/还有别的参数;
*data:例如:”codepage=936,iocharset=cp936“。

其中:

mountflags 经查阅资料有如下选项:

// MS_RELATIME  //(default for Linux >= 2.6.30) 
// MS_STRICTATIME //(default for Linux < 2.6.30) 

// http://harmattan-dev.nokia.com/docs/library/html/manpages/headers/sys/mount.html
public enum MountFlags : ulong
{
    MS_RDONLY = 1,         // Mount read-only.
    MS_NOSUID = 2,         // Ignore suid and sgid bits.
    MS_NODEV = 4,         // Disallow access to device special files.
    MS_NOEXEC = 8,         // Disallow program execution.
    MS_SYNCHRONOUS = 16,    // Writes are synced at once.
    MS_REMOUNT = 32,    // Alter flags of a mounted FS.
    MS_MANDLOCK = 64,    // Allow mandatory locks on an FS.
    S_WRITE = 128,   // Write on file/directory/symlink.
    S_APPEND = 256,   // Append-only file.
    S_IMMUTABLE = 512,   // Immutable file.
    MS_NOATIME = 1024,  // Do not update access times.
    MS_NODIRATIME = 2048,  // Do not update directory access times.
    MS_BIND = 4096,  // Bind directory at different place.
}; // End Enum MountFlags : ulong 

iocharset=name
Character set to use for converting from Unicode to ASCII. The default is to
do no conversion. Use iocharset=utf8 for UTF8 translations. This requires
CONFIG_NLS_UTF8 to be set in the kernel .config file.

函数返回值:

RETURN VALUES
If successful, mount() returns a value of zero. On failure, it returns -1 and sets errno to one of the following values:

EFAULT 
spec or dir is an invalid pointer.

EINVAL 
spec or dir contains an invalid character.

ENAMETOOLONG 
The length of the spec or dir parameter exceeds PATH_MAX or a path name component is longer than NAME_MAX.

ENOTDIR 
spec or dir contains an invalid character.
我在程序中使用的方法如下:

  if( mount(pTempDevName,pMyDisk[tTempEmptyOther].mountName,"vfat",0,"-o iocharset=utf8") )
    return; 

目前为止,使用命令行是能够成功显示中文名的,但是在程序中使用这个函数暂时未成功,仍在探索中...

修改成:

   if( mount(pTempDevName,pMyDisk[tTempEmptyOther].mountName,"vfat",0,"iocharset=utf8") )
    return; 

成功以utf8模式挂载,读取中文字符成功

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值