简体   繁体   中英

Programmatically mounting a FAT32 filesystem with UTF8

How can I mount a FAT/FAT32 device using "mount()" function (from "mount.h", see "man 2 mount") in a way that it will be mounted UTF8?

This is the relevant code I use to mount it 'til now:

mount_result = mount(device_node, device_mount_point, fstype, MS_NOATIME, "");

Thanks, Nicola

From the manpage :

The data argument is interpreted by the different file systems. Typically it is a string of comma-separated options understood by this file system.

And from the manpage of mount(8) , "Mount options for vfat":

utf8 : UTF8 is the filesystem safe 8-bit encoding of Unicode that is used by the console. It can be be enabled for the filesystem with this option. If 'uni_xlate' gets set, UTF8 gets disabled.

Therefore, this should give you the desired behavior:

mount_result = mount(device_node, device_mount_point, fstype, MS_NOATIME, "utf8");

The last argument to the mount command is a string interpreted by the file system driver in the kernel. It is the same you would pass to the mount shell command. For UTF8 I believe the string should be:

mount_result = mount(device_node, device_mount_point, fstype, MS_NOATIME, "iocharset=utf8");

我认为您可能需要尝试“ utf8 = 1”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM