Commit graph

24 commits

Author SHA1 Message Date
David Sterba b13230f84f btrfs-progs: sb-mod: fix build after removing log_root_transid
Commit 963188943f ("btrfs-progs: make
btrfs_super_block::log_root_transid deprecated") deprecated
log_root_transid and broke build of sb-mod. As an unused member of sb we
don't need to edit it, so remove it from the list.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-21 15:51:07 +02:00
David Sterba 5c663502bf btrfs-progs: build: use plain fcntl.h instead of sys/fcntl.h
The CI build on musl warns:

    [CC]     cmds/balance.o
In file included from cmds/inspect.c:19:
/usr/include/sys/fcntl.h:1:2: warning: #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> [-Wcpp]
    1 | #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h>
      |  ^~~~~~~

On glibc the header directly includes fcntl.h.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 19:49:30 +01:00
David Sterba 384bc17f63 btrfs-progs: reorder includes in standalone tools
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 91c91c1632 btrfs-progs: sb-mod: improve help
Print the list of supported members to change and explain what the tool
does.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:30 +02:00
David Sterba f7e4860e9f btrfs-progs: sb-mod: don't fixup checksum for read-only ops
On images with some damage and mismatching checksum the read operations
will fixup the checksum. This may not be desired and does not make much
sense for read anyway.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:28 +02:00
Johannes Thumshirn 94b60b67a9 btrfs-progs: pass in fs_info to btrfs_csum_data
For passing authentication keys to the checksumming functions we need a
container for the key.

Pass in a btrfs_fs_info to btrfs_csum_data() so we can use the fs_info
as a container for the authentication key.

Note this is not always possible for all callers of btrfs_csum_data() so
we're just passing in NULL for now

Functions calling btrfs_csum_data() with a NULL fs_info argument are
currently not supported in the context of an authenticated file system.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba 35614d8a64 btrfs-progs: sb-mod: add syntax to the help text
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-20 15:49:07 +02:00
David Sterba bd017ce732 btrfs-progs: sb-mod: add remaining dev_item members
Add helpers and all remaining members of the device item embedded in the
superblock. No UUID types.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-20 15:49:07 +02:00
David Sterba 8de6816b47 btrfs-progs: sb-mod: add dev_item prefix for sb::device members
For parity with output of 'btrfs inspect dump-super', add the
"dev_item." prefix to the devid member. This allows adding more
members without conflicts (like it would be for device total_bytes).

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-20 15:49:07 +02:00
Anand Jain c875145cb3 btrfs-progs: sb-mod: add devid to the modifiable list
We need this patch to create a crafted image with bogus devid.

For example:
./btrfs-sb-mod devid =0

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-20 15:49:07 +02:00
David Sterba 772f0da6df btrfs-progs: move disk-io.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
Johannes Thumshirn c04bcdcacc btrfs-progs: move crc32c implementation to crypto/
With the introduction of xxhash64 to btrfs-progs we created a crypto/
directory for all the hashes used in btrfs (although no
cryptographically secure hash is there yet).

Move the crc32c implementation from kernel-lib/ to crypto/ as well so we
have all hashes consolidated.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:02 +01:00
Johannes Thumshirn a7e2f17a84 btrfs-progs: unbreak btrfs-sb-mod compilation
Fix compiler warnings and errors in btrfs-sb-mod due to incorrect
conversion with the checksum updates.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:31:19 +02:00
Johannes Thumshirn ed33908b44 btrfs-progs: update checksumming api
Update the checksumming API to be able to cope with more checksum types
than just CRC32C. The finalization call is merged into btrfs_csum_data.

There are some fixme's and asserts added that need to be resolved.

Co-developed-by: David Sterba <dsterba@suse.com>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:34 +02:00
Johannes Thumshirn 926e9c8e14 btrfs-progs: sb-mod: simplify update_block_csum()
update_block_csum() in btrfs-sb-mod.c is always called with the 'is_sb'
argument set to 1.

Get rid of the special case for is_sb == 0.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:31 +02:00
Johannes Thumshirn 7b4f1035a6 btrfs-progs: pass checksum type to btrfs_csum_data()/btrfs_csum_final()
In preparation to supporting new checksum algorithm pass the checksum type
to btrfs_csum_data/btrfs_csum_final, this allows us to encapsulate any
differences in processing into the respective functions

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:28 +02:00
Johannes Thumshirn de68086e35 btrfs-progs: don't assume checksums are always 4 bytes
Pass pointer to a generic buffer instead of fixed size that crc32c
currently uses.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:25 +02:00
David Sterba 7797f03924 btrfs-progs: sb-mod: add remaining superblock integer items
Add support for changing all integer items in the superblock. Sort them
in the order of defintion in the structure.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba 5ab79b808a btrfs-progs: sb-mod: add remaining integer value types
The field type bit width is now only used to describe the members, but
let's add all of the integer ones.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba 94fced6353 btrfs-progs: build: drop kernel-lib from -I and update paths
Include the files by full path to avoid any confusion in case of
potentially duplicate names.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba e3ada5752c btrfs-progs: sb-mod: add compat bit to the recognized fields
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-11 15:37:36 +02:00
David Sterba 22d39a9e0f btrfs-progs: sb-mod: add csum_type
Let SET and GET work on superblock::csum_type.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-11 15:37:36 +02:00
David Sterba b5e0ca64a4 btrfs-progs: sb-mod: add preliminary support for non-u64 types
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-11 15:37:36 +02:00
David Sterba d04d25fb14 btrfs-progs: add tool to edit super blocks
$ make btrfs-sb-mod
$ ./btrfs-sb-mod image field1 operation1 ...

Fields (only u64 supported for now):
 * total_bytes
 * root
 * generation
 * chunk_root
 * chunk_root_generation
 * cache_generation
 * uuid_tree_generation

Operations:
 * read value		?0
 * set value		=NUMBER
 * add to		+NUMBER
 * subtract from value	-NUMBER
 * xor with value	^NUMBER
 * byteswap (u64)	@0

Use with care!

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00