btrfs-progs: fix many typos in documents

There are many trivial typos in Documentation/*.txt.
All of these use "exist status" to mean "exit status"
by mistake. I guess someone first made this mistake
and it has spread by copy-and-paste :-D

Signed-off-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Properly cast to avoid compiler warnings, fixes FTBFS on alpha and ia64

Bug-Debian: http://bugs.debian.org/539433
Bug-Debian: http://bugs.debian.org/583768
Authors:
 Luca Bruno <lucab@debian.org>
 Alexander Kurtz <kurtz.alex@googlemail.com>
 Daniel Baumann <daniel.baumann@progress-technologies.net>

Signed-off-by: Dimitri John Ledkov <xnox@debian.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: update manpage with new option -f for btrfstune

The new option -f will force to do dangerous changes.
e.g. clear the seeding flag.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
[more text from 3db4c0a3d35dd5f8 changelog]
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: fix typo in subvol list usage

Signed-off-by: David Disseldorp <ddiss@suse.de>
[moved to new asciidoc]
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Add human readable incompat flags output for btrfs-show-super

Add human readable incompat flags output for btrfs-show-super,
now no longer needs to calculate the hex flags by hand.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: make BUG*() be more verbose

Currently these macros just tie to assert(), which gives us line number and such
but no backtrace so no actual context.  This patch adds support for spitting out
a backtrace so we can see how we got to the given assert.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
[backtrace_symbols_fd]
Signed-off-by: Naohiro Aota <naota@elisp.net>
[minor fixups]
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: don't assert when we have an invalid mapping

Asserting is no fun, we may be able to recover from this error in certain cases
(like btrfs-image and btrfsck).  Just do what the kernel does and spit out an
error and return that there is only 1 copy.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: let btrfs-image actually work on a balanced fs

We use the read extent buffer infrastructure to read the super block when we are
creating a btrfs-image.  This works out fine most of the time except when the fs
has been balanced, then it fails to map the super block.  So we could fix
btrfs-image to read in the super in a special way, but thats more code.  So
instead just check in the eb reading code if we are reading the super and then
don't bother mapping the block, just read the actual offset.  This fixed some
poor guy who was trying to btrfs-image his fs that had been balanced.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: add root to dirty list when fixing bad keys

A user reported a WARN_ON() when trying to run btrfsck --repair on his fs with
bad key ordering.  This was because the root that was broken wasn't part of the
transaction yet.  We do this open coded thing in a few other places in fsck, so
just make it a helper function and make sure all the places that need to call it
do call it.  With this patch he was able to run repair without it dying.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Check the csum tree node before go through the csum tree

[BUG]
Some fsfuzzed btrfs image will cause btrfsck segfault.

[REPRODUCER]
Run btrfsck on a csum tree block corrupted image.

[REASON]
check_csums() function call btrfs_search_slot() on csum_tree but doesn't
check whether the csum_tree contains a valid extent_buffer, which causes
the segfault.

[FIX]
Check the csum_root->node before any search.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: check all slots in leaves

There's an off by one error in btrfs_check_leaf, we should be going to nritems -
1, not nritems - 2, we were missing problems with items in the very last slot.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs progs v3.16.2

Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Fix malloc size for superblock.

recover_prepare() in chunk-recover.c alloc memory which only contains
sizeof(struct btrfs_super_block). This will cause glibc malloc error
after superblock csum is calculated.

Use BTRFS_SUPER_INFO_SIZE to fix the bug.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Check superblock's checksum when reading dev super

Btrfs-progs will read the superblock without checking the checksum.
When all superblocks are corrupted, continuing will cause disaster.

So this patch will add checksum check for btrfs-progs when reading
superblocks.

Also fix a bug that btrfs_read_dev_super() only reads sizeof(struct
btrfs_super_block), corrent size should be BTRFS_SUPER_INFO_SIZE.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Add more meaningful return value for btrfs_read_dev_super() and corresponding error string.

Since btrfs_read_dev_super() now can distinguish non-btrfs fs and
corrupted superblock thanks for the newly introduced super csum check,
the return value and corresponding error string should also be updated
to print more meaningful errors for end users.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: fix compilation warning in function btrfs_read_dev_super

disk-io.c: In function ‘btrfs_read_dev_super’:
disk-io.c:1217: warning: ‘ret’ may be used uninitialized in this function

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Enhance the command btrfs filesystem df

Enhance the command "btrfs filesystem df" to show space usage information
for a mount point(s). It shows also an estimation of the space available,
on the basis of the current one used.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Add helpers functions to handle the printing of data in tabular format

This patch adds some functions to manage the printing of the data in
tabular format.

The function
	struct string_table *table_create(int columns, int rows)
creates an (empty) table.

The functions
	char *table_printf(struct string_table *tab, int column,
		int row, char *fmt, ...)
	char *table_vprintf(struct string_table *tab, int column,
		int row, char *fmt, va_list ap)
populate the table with text. To align the text to the left, the text
shall be prefixed with '<', otherwise the text shall be prefixed by a
'>'. If the first character is a '=', the the text is replace by a
sequence of '=' to fill the column width.

The function
	void table_free(struct string_table *)
frees all the data associated to the table.

The function
	void table_dump(struct string_table *tab)
prints the table on stdout.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Add command btrfs filesystem disk-usage

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: Add btrfs device disk-usage command

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>