The keyctl_search() C function returns a long, which is already
reflected in the KeyHandle._id type. The search_keyring() helper
function currently returns a Result<i64>, which breaks 32-bit builds for
e.g. armv7l:
error[E0308]: mismatched types
--> src/key.rs:121:16
|
121 | Ok(key_id)
| -- ^^^^^^ expected `i64`, found `i32`
| |
| arguments to this enum variant are incorrect
...
error[E0308]: mismatched types
--> src/key.rs:135:24
|
135 | _id: id,
| ^^ expected `i32`, found `i64`
Fix this by changing search_keyring() to return a Result<c_long>.
Fixes: f72ded6a ("fix(key): search for key in all relevant keyrings")
Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Previously, using `bcachefs unlock -k session` would still cause mount
to ask for a passphrase.
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
To match the behavior of the C code and because there may be newlines
under some conditions.
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
`Path::parent()` returns `Some("")` for relative paths with a single
component. The simplest fix is to just canonicalize the paths first.
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
It's kind of stupid to use this macro if we have to deref the parameter
first. I was too enthusiastic about using this macro instead of `as`
because it's nicer to read (imo).
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
This was a stupid mistake by me, "fixing" more than what clippy told me
to. `p` is already a reference and we should not use the addr of it.
Fixes: 96a3462 ("refactor: casting-related `clippy::pedantic` fixes")
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
Prefer using `ptr::addr_of!()` and `pointer::cast()` instead of raw `as`
where clippy complains and other type casting lints.
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
`bch2_sb_is_encrypted_and_locked()` simply does not check if the fs is
locked. The name is misleading.
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
let's always first check if there is already a key in the keyring
available before we try to get the key from some more involved means.
Fixes: #261
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Only bkeys of the specified type will be printed.
Also, this reworks the error type in bch_bindgen to be able to
represent other kinds of error than just "invalid btree id".
Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
If the user passes a single device node during the mount and
we have no information for it in the udev db, we read up the
super block. When we do this, if the FS only has 1 block device
we will simply go ahead and do the mount instead of walking
all the block devices and reading up super blocks looking for
devices with a matching FS UUID.
Signed-off-by: Tony Asleson <tasleson@redhat.com>
Introduce an env. variable for users that have a broken blkid which
renders the udev db as incomplete. Only checks for the existence
of the variable, not its value.
Signed-off-by: Tony Asleson <tasleson@redhat.com>
If the udev database contains information about bcachefs, utilize it.
Otherwise, resort to traversing block devices and checking for
bcachefs super blocks.
V2: Reduce number of places we call read_super_slient in interators
Signed-off-by: Tony Asleson <tasleson@redhat.com>
It is more idiomatic to use `commands::mount` than
`commands::cmd_mount`.
No functionality changes intended by this patch.
Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
If we pass a symlink for a single device node we fail to locate the
device node. Canonicalize the device node before we try to read up
the superblock.
This allows the following to work.
# bcachefs mount /dev/mapper/vg-thinvolume /mnt/lv_thin
Signed-off-by: Tony Asleson <tasleson@redhat.com>
Instead of requiring the user to supply all the device nodes for a
multi-device FS, allow them to specifiy 1 of them. We then fetch
the UUID for the FS and then find all the disks on the system that
match this UUID.
This allows me to bring up a bcachefs FS in /etc/fstab by using a
UUID. This works because it appears the mount command looks up
the UUID, finds an entry in /dev/disk/by-uuid and then passes that
found device node to mount.bcachefs which fails with
`insufficient_devices_to_start` as bcachefs is expecting a list of
devices with a ":" between them. This behavior is preserved if a
user specifies a list of all the needed device nodes to bring up
the FS.
Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
- Add key_file option to Cli
- Rework decryption flow logic to first attempt key_file
- Read password from file and pass to decrypt_master_key
Explicity specify '-k' for key_location
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
The second argument to ioctl() can be defined as a different type by
different libc implementations, and can be a different size on different
architectures depending on what type it is defined as. For example,
glibc defines it as `unsigned long` which may have a different size on
32-bit vs. 64-bit architectures, and musl libc defines it as `int`.
The Rust libc crate exposes a type `libc::Ioctl` which is defined as the
appropriate integer type for the given libc implementation. Using this
type for the request argument to `libc::ioctl()` ensures code will
compile correctly regardless of architecture and libc implementation.
Also, because ioctl request numbers are defined to be 32 bits
(regardless of the fact that `unsigned long` might sometimes take 64
bits on some architectures), this patch changes the Rust representation
of the bcachefs ioctl numbers to u32 instead of u64.
Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>