当我们在Linux系统的板子上挂载U盘时,会出现,原本在windows上显示正常的文件名,在Linux下全部显示为问号?.
如果需要显示出中文,需要使用uft8模式挂载U盘。
解决中文字符显示问号的方法:
mount /dev/sdb4 /mnt/ho1 -o iocharset=utf8
然而,在程序中,使用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模式挂载,读取中文字符成功,哦耶...