本文转自:http://blog.csdn.net/ypist/article/details/8181766
当我们在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.