Android10 U盘支持EXFAT和NTFS

前言
大家知道目前安卓AOSP只支持FAT32,还不支持EXFAT和NTFS,这两种windows支持的格式使用上还是比较普遍的,所以安卓也能支持那就相当nice了,不然安卓就会提醒让格式化,这是很危险的,格式化后数据就丢失了,目前网上有很多资料可以实现安卓支持EXFAT/NTFS,特别是EXFAT,参照资料就能完美的支持,但是NTFS就没那么明确,我这里根据之前的经验做个总结,方便大家参考

系统信息:
Android10
kernel 4.19

第一步需要kernel支持EXFAT和NTFS
kernel中移植exfat-nofuse

源码:https://github.com/dorimanx/exfat-nofuse

将代码下载解压后,更名exfat放到kernel/fs下, 修改kernel下Kconfig、Makefile:

diff
-git a/kernel/fs/Kconfigb/kernel/fs/Kconfig
index b8d003f. .65ce644 100644
a/kernel/fs/Kconfig
+ b/kernel/fs/Kconfig
60 - 133,10 +133,11 ea endmenu
endif # BLOCK
if BLOCK
source "fs/fat/Kconfig"
source "fs/ntfs/Kconfig"
+source "fs/exfat/Kconfig
endmenu
endif # BLOCK
diff --git a/kernel/fs/Makefile b/kernel/fs/Makefile
index 5030ac9. .d6c02f2 100644
a/kernel/fs/Makefile
+ b/kernel/fs/Makefile
60 -80,6 +80,7 (@ obj -$(CONFIG_HUGETLBFS)+= hugetlbfs/
obj-(CONFIG_MINIX_FS)+= minix/
obj-(CONFIG_FAT_FS)+= fat/
+ obj-(CONFIG_EXFAT_FS)+= exfat/
+ obj-(CONFIG_NTFS_FS)+= ntfs/
obj-(CONFIG_BFS_FS)+= bfs/
obj-(CONFIG_IS09660_FS)+=isofs/

在kernel默认编译配置文件中打开NTFS和EXFAT配置:

@@ -927,3 +927,6 CONFIG_SCHED_STACK_END_CHECK=y
CONFIG_ENABLE_DEFAULT_TRACERS=y
CONFIG_BUG_ON_DATA_CORRUPTION=Y
CONFIG_LEDS_AM20108=y
+CONFIG_NTFS_FS=Y
+CONETG_NTES_BW=Y
+CONFIG_EXFAT_FS=Y

编译kernel,生产的image替换后,通过cat /proc/filesystems查看,有exfat和ntfs就可以了(图片来自网络)

移植fuse:
https://github.com/Shawnsongs/Android_P_external_exfat_ntfs-3g/tree/master/external-exfat-fuse

下载后改名exfat放到external中,编译生成mkfs.exfat和fsck.exfat

目前AOSP已经在system/vold/fs/Exfat.cpp支持EXFAT,所以当上一步kennel已经加载exfat,exfat应该已经可以使用了,如果还是不行就需要看下是不是selinux的问题,selinux的比较简单,只需要针对缺少的权限加上就可以了

但是ntfs的源码是没有的,这里我们可以参考EXFAT来模拟写一份

Ntfs.cpp

/** Copyright (C) 2018 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/#include <sys/mount.h>#include <android-base/logging.h>#include <android-base/stringprintf.h>#include <logwrap/logwrap.h>#include "Ntfs.h"#include "Utils.h"using android::base::StringPrintf;namespace android {namespace vold {namespace ntfs {static const char* kNtfsPath = "/system/bin/ntfs-3g";bool IsSupported() {return access(kNtfsPath, X_OK) == 0 &&IsFilesystemSupported("ntfs");}status_t Check(const std::string& source) {return 0;}status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,int permMask) {int mountFlags = MS_NODEV | MS_NOSUID | MS_DIRSYNC | MS_NOATIME | MS_NOEXEC;auto mountData = android::base::StringPrintf("uid=%d,gid=%d,fmask=%o,dmask=%o", ownerUid,ownerGid, permMask, permMask);if (mount(source.c_str(), target.c_str(), "ntfs", mountFlags, mountData.c_str()) == 0) {return 0;}PLOG(ERROR) << "Mount failed; attempting read-only";mountFlags |= MS_RDONLY;if (mount(source.c_str(), target.c_str(), "ntfs", mountFlags, mountData.c_str()) == 0) {return 0;}return -1;}status_t Format(const std::string& source) {return 0;}}  // namespace exfat}  // namespace vold}  // namespace android

Ntfs.h

  /** Copyright (C) 2018 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/#include <utils/Errors.h>#include <string>namespace android {namespace vold {namespace ntfs {bool IsSupported();status_t Check(const std::string& source);status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,int permMask);status_t Format(const std::string& source);}  // namespace ntfs}  // namespace vold}  // namespace android#endif

把这两个文件加入到Exfat.cpp同目录下,再修改/system/vold/model/PublicVolume.cpp跟exfat相同的地方加上ntfs,这里我们不支持格式化成ntfs了

status_t PublicVolume::doMount() {readMetadata();if (mFsType == "vfat" && vfat::IsSupported()) {if (vfat::Check(mDevPath)) {LOG(ERROR) << getId() << " failed filesystem check";return -EIO;}} else if (mFsType == "exfat" && exfat::IsSupported()) {if (exfat::Check(mDevPath)) {LOG(ERROR) << getId() << " failed filesystem check";return -EIO;}+} else if (mFsType == "ntfs" && exfat::IsSupported()) {+    if (exfat::Check(mDevPath)) {+        LOG(ERROR) << getId() << " failed filesystem check";+        return -EIO;+    }} ......if (mFsType == "vfat") {if (vfat::Mount(mDevPath, mRawPath, false, false, false, AID_MEDIA_RW, AID_MEDIA_RW, 0007,true)) {PLOG(ERROR) << getId() << " failed to mount " << mDevPath;return -EIO;}} else if (mFsType == "exfat") {if (exfat::Mount(mDevPath, mRawPath, AID_MEDIA_RW, AID_MEDIA_RW, 0007)) {PLOG(ERROR) << getId() << " failed to mount " << mDevPath;return -EIO;}+}else if (mFsType == "ntfs") {+    if (ntfs::Mount(mDevPath, mRawPath, AID_MEDIA_RW, AID_MEDIA_RW, 0007)) {+        PLOG(ERROR) << getId() << " failed to mount " << mDevPath;+        return -EIO;+    }}

ntfs-3g网上可以下载到bin档可以直接使用,并且ntfs支持会有selinux问题,这块需要针对性修改,到此,EXFAT和NTFS就已经支持了,如有问题,可以联系我大家讨论。

Android10 U盘支持EXFAT和NTFS相关推荐

  1. Linux kernel 编译 exfat.ko ntfs.ko 来支持exFat 和 NTFS 分区

    项目需求想让设备支持 exFat 和 NTFS 的文件格式. 默认的内核是不支持的,因为内核要限定1.5M之内, 所以很多东西都裁剪掉了. 而且不是所有项目都有这个需求,所以就需要编译为 ko ,按需 ...

  2. linux exfat设置权限,Linux支持exFAT和NTFS

    Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最好格式化为exFAT,NTFS对U盘 ...

  3. linux系统支持ntfs吗,Linux支持exFAT和NTFS

    Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最好格式化为exFAT,NTFS对U盘 ...

  4. Linux支持exFAT和NTFS

    Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最好格式化为exFAT,NTFS对U盘 ...

  5. exfat硬盘格式Linux是否支持,Linux支持exFAT和NTFS

    Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最好格式化为exFAT,NTFS对U盘 ...

  6. android 格式化为exfat,Android 4.2是否支持exfat格式U盘?如何使Android支持exfat

    Android 4.2是否支持exfat格式的U盘? 问: 我想将大于4G的视频放入USB闪存驱动器,然后如何使Android支持exfat通过otg电缆连接到手机,但是Android无法识别exfa ...

  7. Petalinux配置exFAT与NTFS文件系统

    Petalinux默认工程支持Ext3/4.FAT32文件系统,不支持exFAT与NTFS文件系统,在使用中会带来诸多不便.通过本文介绍就可以让我们的系统在不安装第三方软件下直接支持exFAT与NTF ...

  8. U盘格式选择 FAT32、exFAT、NTFS

    先说结论 首推 exFAT,无最大文件限制,而且在windows.linux.mac.ios下都可以使用 NTFS 无最大文件限制,不过只能在windows下读取数据,这种文件系统更适合于硬盘 FAT ...

  9. Android9.0支持exFat格式u盘识别

    前言 前几天因工作需要在Android9.0上增加exfat格式u盘识别,查找相关资料之后只找到了Android4.4以及Android7.0的教程.fuse和no-fuse两种实现方法选其一即可,实 ...

最新文章

  1. html ajax put请求,javascript – PUT Ajax请求
  2. 谈谈让你纠结的年终奖
  3. [Silverlight动画]转向行为 - 转向机车
  4. VS直接调试可执行文件main函数.exe输入参数argc(项目--> 属性--> 调试--> 命令参数)
  5. 元气骑士里的超级计算机,元气骑士:本以为“素颜相机”够火,直到看到它,一秒笑出猪叫声...
  6. B.The Tortoise and the Hare 长春
  7. Java:File.separator作用相当于 ‘ \ ‘
  8. 子类实现父类接口时注解为啥报错_Java中的注解使用:全面性的总结一下
  9. mysql数据库比较,各数据库不同之处
  10. php-有时候你会疑惑的小问题
  11. [BZOJ4484][JSOI2015]最小表示(拓扑排序+bitset)
  12. 【论文】本周论文推荐(11.23-11.29)
  13. 【广义S变换】一维广义S变换对非平稳信号处理的matlab仿真
  14. 【抓包】Xposed+JustTrustMe关闭SSL证书验证
  15. 全国省市json文件,省市区json文件
  16. 智慧城市解决方案(智慧城市系统及相关技术)
  17. Python基础(8)字符串及常用操作
  18. hsql导入mysql_关于HSQLDB访问已有数据库文件的操作说明
  19. 苹果内购IAP记录-2 StoreKit新版
  20. win7一直安装并更新计算机,win7系统更新时一直正在等待安装重启不更新的恢复方案...

热门文章

  1. Halcon图像处理软件下载
  2. 智勇三国需求规格说结书1.0.0
  3. iOS 城市定位 英文
  4. 对网站优化中木桶原理的几点思考
  5. Java SPI机制原理和使用场景
  6. 中国核电领域企业和基地
  7. 凹语言™——名字的由来和寓意
  8. Python错误 TypeError: ‘NoneType‘ object is not subscriptable解决方案汇总
  9. 财务数据分析sql python_我是如何从会计转行到数据分析
  10. 【CSS 文本属性(Text)】