Conversation
Port the mmap fallback implementation from MetaCubeX/bbolt (commit d4ec34a) to support file systems that do not provide mmap, such as jffs2 on Asus Merlin routers. When mmap fails with ENOSYS/ENODEV/EOPNOTSUPP/ENOTSUP/EINVAL, bbolt now transparently falls back to a heap-backed buffer that mirrors the data file, instead of returning a fatal error. All read/write semantics remain identical; the fallback is automatic and requires no API changes for callers. Fixes SagerNet/sing-box#4251
Author
|
@nekohasekai New PR. Now ports non-mmap fallback to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebase of #1 onto
main(the previous PR targeted the legacymasterbranch).Resolves SagerNet/sing-box#4251.
jffs2(Asus Merlin/jffs, some OpenWrt MTD partitions) rejectsmmap(PROT_READ, MAP_SHARED)onO_RDWRfiles withEINVAL, sobbolt.Open()fails and sing-box dies at startup:initialize cache-file: invalid argument.This ports MetaCubeX/bbolt@d4ec34a verbatim (only the module import path rewritten). When mmap fails with
ENOSYS/ENODEV/EOPNOTSUPP/ENOTSUP/EINVAL, the data file is mirrored into a heap buffer instead; read/write semantics and the public API are unchanged. Mihomo shipped the same patch for the identical bug (MetaCubeX/mihomo#2922).Verified on a simulated jffs2 mount (
mtdram): unpatchedmainreproduces the fatal error, with this patch sing-box starts and selector state persists across restarts.go test .passes, including the portedTestMmapFallbackReadWrite.