IceWhaleTech / CasaOS

CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.
https://casaos.io
Apache License 2.0
25.31k stars 1.37k forks source link

armbian 中通过 cifs 挂载 smb 默认不使用 utf-8 导致中文乱码 (armbian - Chinese characters garbled due to lack of utf-8 encoding when mounting smb via cifs) [Bug] #1850

Open whwh13 opened 4 months ago

whwh13 commented 4 months ago

armbian 中通过 cifs 挂载 smb 默认不使用 utf-8 导致中文乱码

armbian - Chinese characters garbled due to lack of utf-8 encoding when mounting smb via cifs

问题

Issue

在 armbian(armv7) 中使用 mount - t cifs 默认不使用 utf-8 编码,这导致客户端使用中文时会出现乱码 这可能是一个 BUG,在debian(x64)中并未出现这个情况。 下图展示了通过 mount - t cifs 挂载 smb 是否添加参数 iocharset=utf8 的区别

In armbian (armv7), when using mount -t cifs, utf-8 encoding is not used by default, resulting in garbled characters when Chinese characters are used by the client. This might be a BUG as it is not observed in debian (x64). The following image shows the difference between mounting smb using mount -t cifs with and without the iocharset=utf8 parameter:

Snipaste_2024-05-29_14-17-31

解决方案

Solution

本人无项目开发经验,但是在 chatgpt 的帮助下,注意到可以通过修改代码库中[CasaOS]/service/connections.go的第60-71行

I have no experience in project development, but with the help of chatgpt, I noticed that modifying lines 60-71 in the codebase [CasaOS]/service/connections.go can address this issue:

func (s *connectionsStruct) MountSmaba(username, host, directory, port, mountPoint, password string) error {
    err := unix.Mount(
        fmt.Sprintf("//%s/%s", host, directory),
        mountPoint,
        "cifs",
        unix.MS_NOATIME|unix.MS_NODEV|unix.MS_NOSUID,
        fmt.Sprintf("username=%s,password=%s", username, password),
    )
    return err
    //str := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;MountCIFS " + username + " " + host + " " + directory + " " + port + " " + mountPoint + " " + password)
    //return str
}

其中的 fmt.Sprintf("username=%s,password=%s", username, password) 修改为 fmt.Sprintf("username=%s,password=%s,iocharset=utf8", username, password)解决。

Modify fmt.Sprintf("username=%s,password=%s", username, password) to fmt.Sprintf("username=%s,password=%s,iocharset=utf8", username, password) to resolve the issue.

解决方案可行性

Feasibility of Solution

个人认为该解决方案是可行的,因为大多数的系统是支持 utf-8 的而且大多数操作系统的 cifs 默认编码采用的是 utf-8,修改该部分代码不会导致其他人的使用出现问题

I believe this solution is feasible because most systems support utf-8, and most operating systems use utf-8 as the default encoding for cifs. Modifying this part of the code should not cause issues for other users.

 [Armbian-unofficial 24.5.0-trunk Bullseye \l Bit:32 Mem:988M Core:4 Linux onecloud 6.6.32-current-meson #1 SMP Sat May 25 14:22:56 UTC 2024 armv7l GNU/Linux]
CorrectRoadH commented 3 months ago

🤔我在Mac和Ubuntu中用cifs试了一下,复现不了。目前没有armdebian的环境