Commit Graph

27 Commits (1ebfc031cb0b2fa4eef464003377d9860410f424)

Author SHA1 Message Date
David Sterba 4ac63ccbd8 btrfs-progs: help: don't print usage on wrong argument counts
The error message about the unsatisfied argument count is scrolled away
by the full usage string dump. This is not considered a good usability
practice.

This commit switches all direct usage -> return patterns, where the
argument check has no other constraint, eg. dependency on an option.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-03-05 12:57:56 +01:00
David Sterba 4ac44631a4 btrfs-progs: help: use unknown command option helper
Update handling of unknown option in all commands. This will not print
only the unknown option and short pointer to help. Dumping the whole
help was a bad idea that stuck for too long.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-03-05 12:57:55 +01:00
Nikolay Borisov 2e84a13a10 btrfs-progs: Use a single tab for 'leafsize (deprecated)' row
Since this row is longer than the rest it's enough to use a single tab
character to delimig the value from caption. Without this patch
output looked like:

nodesize		16384
leafsize (deprecated)		16384

With it:

nodesize		16384
leafsize (deprecated)	16384

No functional changes just making the output a bit neater.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-02-25 18:08:25 +01:00
Nikolay Borisov c4aadd9af2 btrfs-progs: Add support for metadata_uuid field
Add support for a new metadata_uuid field. This is just a preparatory
commit which switches all users of the fsid field for metdata comparison
purposes to utilize the new field. This more or less mirrors the
kernel patch, additionally:

 * Update 'btrfs inspect-internal dump-super' to account for the new
 field. This involes introducing the 'metadata_uuid' line to the
 output and updating the logic for comparing the fs uuid to the
 dev_item uuid.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-12-06 12:51:36 +01:00
Misono, Tomohiro c074434fb5 btrfs-progs: remove BTRFS_CRC32_SIZE definition
The kernel code no longer has BTRFS_CRC32_SIZE and only uses
btrfs_csum_sizes[]. So, update the progs code as well.

Suggested-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
Qu Wenruo 14bf2b546d btrfs-progs: dump-super: Don't verify csum if csum type or size is unknown
Reported-by: Ken Swenson <flat@imo.uto.moe>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
Rosen Penev e4df433b8a btrfs-progs: treewide: Replace strerror(errno) with %m.
As btrfs is specific to Linux, %m can be used instead of strerror(errno)
in format strings. This has some size reduction benefits for embedded
systems.

glibc, musl, and uclibc-ng all support %m as a modifier to printf.
A quick glance at the BIONIC libc source indicates that it has
support for %m as well. BSDs and Windows do not but I do believe
them to be beyond the scope of btrfs-progs.

Compiled sizes on Ubuntu 16.04:

Before:
3916512 btrfs
233688  libbtrfs.so.0.1
4899    bcp
2367672 btrfs-convert
2208488 btrfs-corrupt-block
13302   btrfs-debugfs
2152160 btrfs-debug-tree
2136024 btrfs-find-root
2287592 btrfs-image
2144600 btrfs-map-logical
2130760 btrfs-select-super
2152608 btrfstune
2131760 btrfs-zero-log
2277752 mkfs.btrfs
9166    show-blocks

After:
3908744 btrfs
233256  libbtrfs.so.0.1
4899    bcp
2366560 btrfs-convert
2207432 btrfs-corrupt-block
13302   btrfs-debugfs
2151104 btrfs-debug-tree
2134968 btrfs-find-root
2281864 btrfs-image
2143536 btrfs-map-logical
2129704 btrfs-select-super
2151552 btrfstune
2130696 btrfs-zero-log
2276272 mkfs.btrfs
9166    show-blocks

Total savings: 23928 (24 kilo)bytes

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:03 +01:00
Nick Terrell 717a8b1e5d btrfs-progs: Add zstd support
Adds zstd support to the btrfs program. An optional dependency on libzstd
>= 1.0.0 is added. Autoconf accepts `--enable-zstd' or `--disable-zstd' and
defaults to detecting if libzstd is present using `pkg-config'.

The patch is also available in my fork of btrfs-progs [1], which passes
Travis-CI with the new tests. The prebuilt binary is available there.

I haven't updated Android.mk.

[1] https://github.com/terrelln/btrfs-progs/tree/devel

Signed-off-by: Nick Terrell <terrelln@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-25 15:17:13 +02:00
David Sterba 1224f7343e btrfs-progs: print-tree: rename item callbacks to match the key name
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Misono, Tomohiro c12d0431a6 btrfs-progs: dump-super: add missing long option bytenr to getopt
This fixes "btrfs inspect-internal dump-super --bytenr"

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-08-24 19:16:07 +02:00
David Sterba a67efe4362 btrfs-progs: move command definitions to commands.h
There are some trivial helpers, we can group the command declarations in
one place.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-08-24 19:08:24 +02:00
Qu Wenruo 3c7a04e592 btrfs-progs: Remove deprecated leafsize usage
Leafsize is deprecated for a long time, and kernel has already updated
ctree.h to rename sb->leafsize to sb->__unused_leafsize.

This patch will remove normal users of leafsize:
1) Remove leafsize member from btrfs_root structure
   Now only root->nodesize and root->sectorisze.
   No longer root->leafsize.

2) Remove @leafsize parameter from btrfs_setup_root() function
   Since no root->leafsize, no need for @leafsize parameter.

The remaining user of leafsize will be:
1) btrfs inspect-internal dump-super
   Reformat the "leafsize" output to "leafsize (deprecated)" and
   use le32_to_cpu() to do the cast manually.

2) mkfs
   We still need to set sb->__unused_leafsize to nodesize.
   Do the manual cast too.

3) convert
   Same as mkfs, these two superblock setup should be merged later

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
2017-07-03 13:35:10 +02:00
Lu Fengqi da76d52947 btrfs-progs: print-tree: add validation to print_chunk
In print_chunk, validate the value of uuid_offset when read the dev_uuid of
stripe.

Was triggered by misc-test/015-dump-super-garbage running indefinetelly.

Issue: #37
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-04-20 13:35:39 +02:00
Lu Fengqi d5213118a5 btrfs-progs: dump-super: check array_size in print_sys_chunk_array
Without validation of array_size, the dump-super may lead to a bad
memory access.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-04-20 13:29:13 +02:00
David Sterba 6e1510e0fe btrfs-progs: remove unused argument from btrfs_csum_data
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:47 +01:00
David Sterba 1c880f34f1 btrfs-progs: move help defines to own header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
Omar Sandoval 9e02fbfcd3 btrfs-progs: format FREE_SPACE_TREE{,_VALID} nicely in dump-super
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-23 11:07:05 +01:00
David Sterba 942dc5f29d btrfs-progs: dump-super: print chunks after validation
The fuzz test 005-simple-dump-super hits a crash, because we print the
chunks too early.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
Domagoj Tršan ff9ee51677 btrfs-progs: change btrfs_csum_final result param type to u8
Signed-off-by: Domagoj Tršan <domagoj.trsan@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:35:50 +02:00
David Sterba 689b6249f3 btrfs-progs: dump-super: switch to common message helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:33:15 +02:00
David Sterba a5bd848719 btrfs-progs: dump-super: changes in options to specify superblocks
Some tools (check, select-super, dump-super) can use the alternate
superblocks, but the options are not consistent. To make it less
confusing, change the meaning of option -s in 'dump-super' to specify
the superblock copy, instead of taking the offset.

Though this is a change in UI, the old usage is detected and the result
would be the same, no breakage in existing scripts.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:46:33 +02:00
David Sterba ee7bb45ddc btrfs-progs: dump-super: detect invalid checksum type
The helper btrfs_super_csum_size unconditionally bugs on a bogus value,
the dump-super is supposed to dump even corrupted superblocks so this
must not happen here. Group the checsum values in the output and be more
robust agains garbage values.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:05:38 +02:00
David Sterba df96f8244d btrfs-progs: drop permission arg from non-creating open
The permissions do not make sense without O_CREATE mode.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:05:35 +02:00
David Sterba 17c7df6fed btrfs-progs: dump-super: add more long options
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-15 16:41:06 +01:00
David Sterba a54ef26e51 btrfs-progs: dump-super: switch to getopt_long
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-15 16:32:39 +01:00
David Sterba d66d44eacb btrfs-progs: switch more error messages to common helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
Alexander Fougner eaa93e3b02 btrfs-progs: introduce inspect-internal dump-super
The long-term plan is to merge the features of standalone tools
into the btrfs binary, reducing the number of shipped binaries.

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00