自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
废弃 SDCardFS
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
SDCardFS 在搭载 Android 11 或更高版本且运行内核版本 5.4 或更高版本的设备上已废弃。在此类设备上,VTS 测试不允许将已装载的文件系统列为 SDCardFS。搭载 Android 11 或更高版本但运行内核版本 4.19 或更低版本的设备可以继续使用 SDCardFS,但 Google 不提供额外支持。
在废弃之前,利用 SDCardFS 可以控制对模拟内部存储设备和外部 SD 卡的访问权限,使应用仅可访问与其相关的数据。此外,它还提供了一个不区分大小写的层,以及一些额外的存储跟踪功能。
SDCardFS 替代功能
SDCardFS 替代项使用多个 Linux 内核文件系统功能来实现类似结果。不区分大小写由文件系统直接处理;这样一来,在区分大小写的文件夹和不区分大小写的文件夹中查找内容所需的时间几乎相同,消除了 SDCardFS 中的大文件夹查询速度减慢的问题。SDCardFS 原来为快速收集设置的存储数据而执行的配额跟踪操作现在可使用项目配额从用户空间配置。在某些对性能敏感的情况下,目录会就地绑定装载。新的 FUSE 实现为直接访问文件系统提供了分区存储,这主要是为了支持对位置信息进行遮盖。
配置 SDCard 替代功能
如需在搭载 Android 11 或更高版本的设备上为没有 SDCardFS 的模拟存储空间启用项目配额和大写转换功能,请沿用 device.mk
文件中的 emulated_storage.mk
:
$(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk)
警告:请勿在搭载 Android 10 或更低版本的设备上执行此操作,因为文件系统原生不区分大小写与在此类设备上使用的文件级加密设置不兼容。在此类设备上有必要继续使用 SDCardFS。
废弃 SDCardFS 的原因
弃用 SDCardFS 有多方面的原因。
稳定性
SDCardFS 存在与大小写区分有关的几个竞态条件,以及一些关于内存不足情况的问题。在大型目录中,不区分大小写的查询可能会相当慢,因为查询必须遍历下层目录来寻找替代大小写。同时访问上层和下层文件系统也会导致问题。
上游对等性
SDCardFS 需要对 VFS 进行额外的修补,才能支持更改绑定装载选项。这类修补导致需要执行额外的操作才能接受上游对这些区域所做的更改。SDCardFS 的功能可由上游组件进行复制,从而解决这一痛点。
与 API 的功能对等性
在之前的 Android 版本中,分区存储限制了对特定类型元数据的访问。通过 SDCardFS 直接访问存储空间时,不支持这些分区存储功能。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# SDCardFS deprecation\n\nSDCardFS is deprecated on devices that launch with Android 11 or higher and run kernel version 5.4 or higher. On such\ndevices, [VTS\ntesting](https://android.googlesource.com/platform/test/vts-testcase/kernel/+/refs/heads/android11-dev/sdcardfs/)\ndoesn't allow mounted file systems listed as SDCardFS. Devices that launch with\nAndroid 11 or higher but run kernel version 4.19 or\nlower can continue to use SDCardFS, but Google doesn't provide additional\nsupport.\n\nBefore its deprecation, SDCardFS provided a way to control access to emulated\ninternal storage and external SD cards, allowing apps to access only the data\nrelevant to them. Additionally, it provided a layer of case insensitivity, as\nwell as some additional storage tracking.\n\nSDCardFS replacement functionality\n----------------------------------\n\nThe replacement for SDCardFS uses several Linux kernel filesystem features to\nachieve similar results. Case insensitivity is handled directly by the\nfilesystem; this results in lookup times nearly identical in case-sensitive and\ncase-insensitive folders, removing the large folder slowdown from SDCardFS. The\nquota tracking that SDCardFS was doing to quickly gather storage data for\nsettings is now configured from userspace using project quotas. In some\nperformance-sensitive contexts, directories are bind mounted in place. A new\nFUSE implementation provides scoped storage for direct filesystem access,\nprimarily to support redaction of location information.\n\nConfigure SDCard replacement functionality\n------------------------------------------\n\nTo enable project quotas and case folding for emulated storage without SDCardFS\non a device that launched with Android 11 or higher,\ninherit from `emulated_storage.mk` in the `device.mk` file: \n\n $(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk)\n\n**Warning:** Do *not* do this on devices\nthat launched with Android 10 or lower, since\nfilesystem native case-insensitivity is incompatible with the file-based\nencryption settings used on such devices. It is necessary to keep using SDCardFS\non such devices.\n\nReasons to deprecate SDCardFS\n-----------------------------\n\nThere are various reasons to deprecate SDCardFS.\n\n### Stability\n\nSDCardFS suffers from several race conditions concerning case sensitivity, as\nwell as some issues concerning low memory circumstances. Case-insensitive\nlookups can be rather slow in large directories because lookups have to walk the\nlower directory to find alternate cases. Accessing the upper and lower\nfilesystems at the same time can lead to issues as well.\n\n### Upstream parity\n\nSDCardFS requires additional patches to the VFS to support changing options on\nbind mounts. These patches cause additional work to accept upstream changes to\nthese areas. SDCardFS's features can be replicated by upstream components,\nremoving this pain point.\n\n### Feature parity with API\n\nIn the previous release of Android, scoped storage limited access to particular\ntypes of metadata. Direct storage access through SDCardFS doesn't support these\nscoped storage features."]]