Skip to content

Add non-mmap fallback for unsupported file systems (jffs2) - #2

Open
abcfy2 wants to merge 1 commit into
SagerNet:mainfrom
abcfy2:feat/mmap-fallback
Open

abcfy2 wants to merge 1 commit into
SagerNet:mainfrom
abcfy2:feat/mmap-fallback

Conversation

@abcfy2

@abcfy2 abcfy2 commented Aug 27, 2026

Copy link
Copy Markdown

Rebase of #1 onto main (the previous PR targeted the legacy master branch).

Resolves SagerNet/sing-box#4251.

jffs2 (Asus Merlin /jffs, some OpenWrt MTD partitions) rejects mmap(PROT_READ, MAP_SHARED) on O_RDWR files with EINVAL, so bbolt.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): unpatched main reproduces the fatal error, with this patch sing-box starts and selector state persists across restarts. go test . passes, including the ported TestMmapFallbackReadWrite.

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
@abcfy2

abcfy2 commented Aug 27, 2026

Copy link
Copy Markdown
Author

@nekohasekai New PR. Now ports non-mmap fallback to main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant