首页 > 技术知识 > 正文

FAT32文件系统在linux下一直不友好,比如想在里面创建中文的路径,直接的创建的话在linux下能看到中文,移到Wwindows下就不行了,而且在linux下U盘默认挂载中文还是乱码,通过一阵摸索可以解决掉这个问题

首先开启内核的936字符集支持

File systems —> Native Language Support —> (utf8) Default NLS Option ///此括号内为utf8 <*> Simplified Chinese charset (CP936, GB2312) <*> NLS ISO 8859-1 (Latin 1; Western European Languages) <*> NLS UTF-8 DOS/FAT/NT Filesystems —> (936) Default codepage for FAT (utf8) Default iocharset for FAT

挂载U盘或SD

在挂载SD卡或者U盘的时候不要使用默认的配置,使用下面的命令来挂载就好了:

mount -t vfat /dev/sda1 /mnt -o codepage=936,iocharset=utf8

最后给出一个可以linux下创建多层的目录的函数类似于:

mkdir -p /mnt/dir1/dir2/dir4 static int do_mkdir(const char *path, mode&#95;t mode) { struct stat st; int status = 0; if (stat(path, &st) != 0) { if (mkdir(path, mode) != 0 && errno != EEXIST) status = -1; } else if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR; status = -1; } return(status); } int mkpath(const char *path, mode&#95;t mode) { char *pp; char *sp; int status; char *copypath = strdup(path); status = 0; pp = copypath; while (status == 0 && (sp = strchr(pp, /)) != 0) { if (sp != pp) { *sp = \0; status = do_mkdir(copypath, mode); *sp = /; } pp = sp + 1; } if (status == 0) status = do_mkdir(path, mode); free(copypath); return (status); }
<

猜你喜欢