当前位置: 代码迷 >> 综合 >> USB总线(1)——USB存储1(NTFS)
  详细解决方案

USB总线(1)——USB存储1(NTFS)

热度:31   发布时间:2024-01-10 21:37:39.0
参考链接:
https://blog.csdn.net/psvoldemort/article/details/7258205

USB存储涉及两个方面:
1、usb子系统需要配置usb存储驱动
2、U盘格式化的文件系统类型包含在内核支持的文件系统类型中
RK3399 Linux系统默认支持FAT32、ext2、ext4等文件系统类型,现在想要添加对ntfs格式U盘的支持。

usb存储驱动

kernel/drivers/usb/storage
Device Drivers  ---> [*] USB support  ---><*>     USB Mass Storage support   

文件系统类型配置

内核中添加ntfs配置

make menuconfigFile systems  ---><*> The Extended 4 (ext4) filesystemDOS/FAT/NT Filesystems  ---><*> NTFS file system support[ ]   NTFS debugging support[*]   NTFS write support

其他支持的文件系统类型

File systems  ---><*> The Extended 4 (ext4) filesystemDOS/FAT/NT Filesystems  --->

文件系统挂载

在内核里添加了ntfs的支持配置以后,/dev/sda1以ntfs格式挂载到了/media/sda1
默认挂载信息如下:

[root@rk3399:/]# cat /etc/mtab 
/dev/root / ext4 rw,relatime,data=ordered 0 0
devtmpfs /dev devtmpfs rw,relatime,size=1836696k,nr_inodes=459174,mode=755 0 0
proc /proc proc rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw,relatime,mode=777 0 0
tmpfs /tmp tmpfs rw,relatime 0 0
tmpfs /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0
sysfs /sys sysfs rw,relatime 0 0
debug /sys/kernel/debug debugfs rw,relatime 0 0
pstore /sys/fs/pstore pstore rw,relatime 0 0
/dev/mmcblk2p7 /media/mmcblk2p7 ext2 rw,relatime 0 0
/dev/mmcblk2p8 /media/mmcblk2p8 ext4 rw,relatime,data=ordered 0 0
/dev/mmcblk2p9 /media/mmcblk2p9 ext2 rw,relatime 0 0
/dev/mmcblk2p7 /oem ext2 rw,relatime 0 0
/dev/mmcblk2p9 /userdata ext2 rw,relatime 0 0
/dev/sda1 /media/sda1 ntfs ro,relatime,uid=0,gid=0,fmask=0177,dmask=077,nls=utf8,errors=continue,mft_zone_multiplier=1 0 0
none /sys/kernel/config configfs rw,relatime 0 0
adb /dev/usb-ffs/adb functionfs rw,relatime 0 0
/dev/mmcblk2p9 /usr/bin/bt_pcba_test ext2 rw,relatime 0 0

可以看到/dev/sda1被挂载为了ro权限,系统加载信息如下:

[   82.461477] FAT-fs (sda1): utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
[   82.589623] ntfs: volume version 3.1.
[   82.589962] ntfs: (device sda1): load_system_files(): Volume is dirty.  Mounting read-only.  Run chkdsk and mount in Windows.

报的信息让检查修复U盘,但是U盘是刚格式化好的,问题应该不是出在这(个人看法,如果有正确的方法,希望可以私信我)

添加mount.ntfs等工具

为了解决上一步遇到的权限问题,查看了一下buildroot中的配置选项,使能了BR2_PACKAGE_NTFS_3G编译选项

diff --git a/buildroot/configs/rockchip_rk3399_defconfig b/buildroot/configs/rockchip_rk3399_defconfig
index 5efae234f..5bd30fb73 100644
--- a/buildroot/configs/rockchip_rk3399_defconfig
+++ b/buildroot/configs/rockchip_rk3399_defconfig
@@ -1072,7 +1072,7 @@ BR2_PACKAGE_EXFAT_UTILS=y# BR2_PACKAGE_MTOOLS is not set# BR2_PACKAGE_NFS_UTILS is not set# BR2_PACKAGE_NILFS_UTILS is not set
-# BR2_PACKAGE_NTFS_3G is not set
+BR2_PACKAGE_NTFS_3G=y# BR2_PACKAGE_SP_OOPS_EXTRACT is not set# BR2_PACKAGE_SQUASHFS is not set# BR2_PACKAGE_SSHFS is not set

编译后添加了如下三个工具

mount.ntfs
mount.lowntfs-3g
mount.ntfs-3g映射关系如下:
[root@rk3399:/]# ls /sbin/mount.* -al
lrwxrwxrwx 1 root root    16 May 15  2021 /sbin/mount.exfat -> mount.exfat-fuse
-rwxr-xr-x 1 root root 39544 Jul  9  2021 /sbin/mount.exfat-fuse
lrwxrwxrwx 1 root root    19 Jul  9  2021 /sbin/mount.lowntfs-3g -> /usr/bin/lowntfs-3g
lrwxrwxrwx 1 root root    13 Jul  9  2021 /sbin/mount.ntfs -> mount.ntfs-3g
lrwxrwxrwx 1 root root    16 Jul  9  2021 /sbin/mount.ntfs-3g -> /usr/bin/ntfs-3g

对应的库文件为

[root@rk3399:/]# ls -al /usr/lib/libntfs-3g.so.88*
lrwxrwxrwx 1 root root     20 Jul  9  2021 /usr/lib/libntfs-3g.so.88 -> libntfs-3g.so.88.0.0
-rwxr-xr-x 1 root root 238304 Jul  9  2021 /usr/lib/libntfs-3g.so.88.0.0

卸载掉默认的挂载路径之后,使用mount.ntfs重新挂载U盘设备,写权限就有了

[root@rk3399:/]# ls /media/ -al
total 50
drwxr-xr-x 14 root root 4096 Jan  1 00:00 .
drwxr-xr-x 26 root root 4096 Jan  1 00:01 ..
drwxr-xr-x  3 root root 1024 Jul  9  2021 mmcblk2p7
drwxr-xr-x 26 root root 4096 Jan  1 00:01 mmcblk2p8
drwxr-xr-x  6 root root 1024 Jan  1 00:00 mmcblk2p9
dr-x------  1 root root 4096 Jan  1 00:00 sda1
drwxr-xr-x  2 root root 4096 May 15  2021 usb0
drwxr-xr-x  2 root root 4096 May 15  2021 usb1
drwxr-xr-x  2 root root 4096 May 15  2021 usb2
drwxr-xr-x  2 root root 4096 May 15  2021 usb3
drwxr-xr-x  2 root root 4096 May 15  2021 usb4
drwxr-xr-x  2 root root 4096 May 15  2021 usb5
drwxr-xr-x  2 root root 4096 May 15  2021 usb6
drwxr-xr-x  2 root root 4096 May 15  2021 usb7[root@rk3399:/]# umount /media/sda1
[root@rk3399:/]# mount.ntfs /dev/sda1 /media/sda1[root@rk3399:/]# ls /media/ -al
total 50
drwxr-xr-x 14 root root 4096 Jan  1 00:00 .
drwxr-xr-x 26 root root 4096 Jan  1 00:01 ..
drwxr-xr-x  3 root root 1024 Jul  9  2021 mmcblk2p7
drwxr-xr-x 26 root root 4096 Jan  1 00:01 mmcblk2p8
drwxr-xr-x  6 root root 1024 Jan  1 00:00 mmcblk2p9
drwxrwxrwx  1 root root 4096 Jan  1 00:00 sda1
drwxr-xr-x  2 root root 4096 May 15  2021 usb0
drwxr-xr-x  2 root root 4096 May 15  2021 usb1
drwxr-xr-x  2 root root 4096 May 15  2021 usb2
drwxr-xr-x  2 root root 4096 May 15  2021 usb3
drwxr-xr-x  2 root root 4096 May 15  2021 usb4
drwxr-xr-x  2 root root 4096 May 15  2021 usb5
drwxr-xr-x  2 root root 4096 May 15  2021 usb6
drwxr-xr-x  2 root root 4096 May 15  2021 usb7
[root@rk3399:/]# cp /home/forlinx/audio/test.mp3 /media/sda1/
[root@rk3399:/]# sync
[root@rk3399:/]# ls /media/sda1/
'System Volume Information'   test.mp3

ntfs U盘自动挂载读写

TBC

(PS:下载中提供了ntfs-3g工具和库文件)