Watch
1
0
Fork
You've already forked bcachefs-tools
0
mirror of https://evilpiepirate.org/git/bcachefs-tools.git synced 2026-09-10 02:10:35 -04:00
No description
  • C 76.5%
  • Rust 19.3%
  • C++ 2%
  • Shell 0.8%
  • Makefile 0.7%
  • Other 0.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Kent Overstreet b87c2a19b8 ioctl: get the opcodes from the C compiler
bcachefs's ioctl numbers were computed in Rust, by the generated inventory:

	const fn opcode(dir: u32, nr: u32, size: usize) -> u32 {
		(dir << 30) | ((size as u32) << 16) | (0xbc << 8) | nr
	}

That is asm-generic's _IOC layout, written down. It is correct on x86, arm
and the other asm-generic architectures and wrong everywhere else, so
logan2611's ppc64le sees a filesystem that mounts and then answers ENOTTY
to most ioctls, with the few whose fields happen to line up working by
coincidence (#904, a regression since 1.36).

There is no version of this that can be written down. The kernel has three
separate _IOC() definitions; the size and direction fields have different
widths; _IOC_NONE/READ/WRITE take different values, and parisc's read and
write are the other way round from asm-generic's; sparc deliberately
overlaps the direction and size fields. Even a version parameterised on the
target's _IOC_*SHIFT constants would still be a restatement, and still wrong
on sparc.

So don't restate it. rust_shims.h already had the answer for the block
device ioctls, along with a comment explaining exactly this trap - "an
open-coded 0x127E for BLKROTATIONAL is correct on exactly the architectures
whose _IOC layout you had in mind" - so bind bcachefs's the same way, one
const per ioctl, evaluated by the C compiler against the target's own
<asm/ioctl.h>. Rust gets an integer.

The inventory moves to bch_bindgen with them, since those constants only
exist in this crate's bindings and the fs crate can't see them; nothing in
the kernel build ever used it - the kernel implements ioctls rather than
calling them - so this also stops the DKMS build generating a file it
throws away. The parse that remains reads only the argument type, which is
the one part C can't hand us: bindgen binds values, not types.

The direction bits go with the opcode, and with them the two call-shape
asserts in ioctl_w/ioctl_rw, which compared against literal 1 and 2 - a
third copy of asm-generic's layout, and wrong on the same architectures.

Verified: all 43 opcodes compared against a C program that prints the
macros - no missing bindings, no mismatches - and BCH_IOCTL_QUERY_UUID is
still 0x8010bc01 on x86_64, so nothing changes here.

One trap worth knowing about: bch_bindgen's allowlist_var didn't match the
new names, and bindgen dropped all 43 silently. It surfaced as "cannot find
value in module c", pointing at the use sites rather than the cause.

Reported-by: logan2611
Closes: https://github.com/koverstreet/bcachefs-tools/issues/904

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
Claude-Session: https://claude.ai/code/session_018SHaMsugAT1rz3YcUvvSyn
2026-09-09 14:56:06 -05:00
.github kill deb github workflows 2026-06-09 18:58:09 -04:00
arch/etc initcpio: sd-bcachefs needs the mount helper 2026-09-06 10:56:22 -05:00
bcachefs-shim time_stats: convert the pcpu buffer to local_lock for PREEMPT_RT 2026-07-29 17:21:05 -05:00
bcachefs-shim-macros rust conversion: async executor: WaitGroup and block_on 2026-06-23 16:27:56 -05:00
bch_bindgen ioctl: get the opcodes from the C compiler 2026-09-09 14:56:06 -05:00
c_src ioctl: get the opcodes from the C compiler 2026-09-09 14:56:06 -05:00
ccan treewide, docs: fix typos 2024-05-29 09:22:09 +05:30
debian packaging: install the systemd mount generator 2026-08-29 15:14:31 -05:00
dkms build: export only the DKMS build vars that are set 2026-08-08 14:44:46 -05:00
doc doc: options on snapshotted files 2026-08-31 13:52:02 -05:00
Documentation docs: document bcachefs limits 2026-07-01 21:51:15 -05:00
fs ioctl: get the opcodes from the C compiler 2026-09-09 14:56:06 -05:00
include treewide: system_unbound_wq -> system_dfl_wq 2026-09-04 07:17:37 -05:00
initramfs initramfs: install the mount timeout generator into the initrd 2026-08-30 14:46:19 -05:00
linux tools: a short read is not worth saying, twice over 2026-08-21 22:32:27 -05:00
package-ci package-ci: re-render the status page every poll 2026-08-11 12:41:18 -05:00
raid raid/cpu: Use memcpy() instead of type punning 2024-07-12 14:02:14 -04:00
scripts scripts: add install-to-kernel.sh 2026-06-29 20:34:04 -05:00
signing debian: enroll module-signing CA for Secure Boot 2026-06-28 14:48:57 -05:00
src ioctl: get the opcodes from the C compiler 2026-09-09 14:56:06 -05:00
udev udev: hand a late-arriving member to the filesystem that's missing it 2026-08-20 18:55:57 -05:00
verus-proofs rust conversion: Move bindings into kernel module 2026-06-23 13:40:57 -05:00
.editorconfig chore(editorconfig): extend for sh scripts 2024-06-18 20:56:06 +02:00
.gitignore udev: hand a late-arriving member to the filesystem that's missing it 2026-08-20 18:55:57 -05:00
bcachefs Add bcachefs command compatibility symlink 2024-01-29 14:29:35 +01:00
bcachefs-kmp.spec-preambule Spec: Implement KMP package for OpenSUSE Tumbleweed 2025-11-19 02:19:24 +03:00
bcachefs-tools.spec packaging: install the systemd mount generator 2026-08-29 15:14:31 -05:00
bcachefs-wait-devices@.service.in wait: rename to wait-devices 2026-04-28 10:40:11 -04:00
bcachefs.8 doc: align replica options manual 2026-08-06 15:57:36 -05:00
build.rs util: prt_addr_symbol() for userspace bch2_prt_backtrace 2026-05-02 20:56:40 -04:00
Cargo.lock v1.39.5 2026-09-07 14:00:35 -05:00
Cargo.toml v1.39.5 2026-09-07 14:00:35 -05:00
Changelog.mdwn v1.39.5 2026-09-07 14:00:35 -05:00
CLAUDE.md doc: .claude/ is working notes, not repository documentation 2026-08-02 19:42:46 -05:00
COPYING bcache-tools are GPL 2013-07-17 13:13:31 -07:00
crane-build.nix nix: set the systemd generator dir, so the flake builds again 2026-08-24 17:48:07 -05:00
default.nix style(nix): run nix fmt 2024-05-22 22:35:05 +02:00
flake.lock flake.lock: Update 2026-06-26 23:22:13 -05:00
flake.nix nix: make the doc target actually build the document 2026-07-29 17:46:15 -05:00
INSTALL.md INSTALL.md: bindgen is a build dependency 2026-08-24 17:48:07 -05:00
make-release-tarball.sh make-release-tarball.sh: exit trap 2026-07-03 10:28:35 -05:00
Makefile Makefile: a bindgen-test target 2026-09-08 05:34:42 -05:00
Makefile.compiler Update bcachefs sources to a8d89eb264e0 bcachefs: Allow CONFIG_UNICODE=m 2025-06-09 17:39:57 -04:00
module-build.nix module-build.nix: add RUST_LIB_SRC 2026-06-24 19:57:14 -05:00
mount.bcachefs.sh mount.bcachefs.sh: add per-device timeout to UUID scan 2026-02-20 11:33:41 -05:00
nixos-test.nix nix: pin nixos-test VM to linuxPackages_latest 2026-06-09 18:58:09 -04:00
overlay.nix nix: Use an overlay 2025-09-28 15:31:26 -04:00
README.md docs: clarify official source and support channels 2026-07-01 17:36:12 -05:00
rustfmt.toml Format with rustfmt 2024-05-26 20:38:08 -04:00

bcachefs-tools

Userspace tools and docs for bcachefs

Bcachefs is an advanced new filesystem for Linux, with an emphasis on reliability and robustness and the complete set of features one would expect from a modern filesystem.

This is the official development repository for bcachefs — the userspace tools, the documentation, and the filesystem source itself. bcachefs is maintained out of mainline and ships as a DKMS kernel module built from this tree. To build it into a kernel source tree instead (CONFIG_BCACHEFS_FS), run scripts/install-to-kernel.sh, which copies fs/ into <kernel>/fs/bcachefs/ and wires it into the kernel build.

This repo primarily consists of the following:

  • bcachefs tool, the reason this repo exists.
  • {mkfs,mount,fsck}.bcachefs utils, which is just wrappers calling the corresponding subcommands in the main tool
  • docs in the form of man-pages and a user manual

Please refer to the main site for getting started An in-depth user manual is (also) found on the official website

Version semantics

The tools relies on an expected disk format structure which is reflected by your current kernel version. Disk format can be upgraded or downgraded automatically by the kernel, if needed.

  • Any patch-level change means no disk format change
  • Any minor-level change means a potential disk format change which is not breaking
  • Any major-level change means breaking changes

Build and install

Refer to INSTALL.md

Bug reports and contributions

  • GitHub issues for bug reports and focused feature requests
  • GitHub Discussions for support questions and general usage discussion
  • The official mailing list, linux-bcachefs@vger.kernel.org
  • IRC: #bcache on OFTC (irc.oftc.net). Note that IRC messages can be easily missed.