Btrfs-progs: Fix compiler warnings on PPC64

The kernel uses unsigned long long for u64, but PPC64 uses unsigned
long by default. This results in compilation warnings such as:

print-tree.c:333: warning: format '%llu' expects type 'long long
unsigned int', but argument 4 has type 'u64'

To fix this, the macro __KERNEL__ needs to be defined before including
the file <asm/types.h>. This can be done by defining the macro in
"kerncompat.h" and making it the first included file in the relevant
header files; this fixes the compiler warnings on PPC64.

Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Wade Cline <clinew@linux.vnet.ibm.com>
version.sh: fix version when built from tarball

[from 0.20-rc1 tarball]

Before the patch:
  $ ./btrfs --version
  Btrfs Btrfs v0.19

After the patch:
  $ ./btrfs --version
  Btrfs v0.20-rc1

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
btrfs-progs: add -V description in print_usage

mkfs supports the option -V/--version.
Add its description to print_usage().

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
Btrfs-progs: fix unaligned accesses

There are some unaligned accesses in progs that cause malfunction or
crashes on ARM.
This patch fixes the ones we stumbled upon.

Signed-off-by: Arne Jansen <sensille@gmx.net>
btrfs-progs: Receive: preserve ownership for symlinks, by using 'lchown'

Signed-off-by: Alex Lyakas <alex.btrfs@zadarastorage.com>
btrfs-progs: do not send stream into a terminal

Signed-off-by: David Sterba <dsterba@suse.cz>
Move parse_size() to utils.[hc]

Move the function from cmds-filesystem.c and mkfs.c to utils.c

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
parse_size(): replace atoll() with strtoull()

Replace the function atoll with strtoull(); Check that the suffix for the
parse_size() input is of only one character.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
parse_size(): add new suffixes

Add new suffixes in parse_size() function. New suffixes are: T as
terabyte, P as petabyte, E as exabyte. Note these units are
multiply of 2 .

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
btrfs-progs: update usage description for debug-tree.c

There are more options than "-e" only.
Update the description for the usage.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
btrfs-progs: plug a memory leak reported by cppcheck

[src/btrfs/disk-io.c:462]: (error) Memory leak: log_root

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
btrfs-progs: check malloc() result

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
btrfs-progs: plug memory leaks in btrfs_scan_one_dir() reported by cppcheck.

[utils.c:983]: (error) Memory leak: fullpath

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
btrfs-progs: fix 32bit int/pointer cast warnings

This uses uintptr_t to cast pointers to u64 ioctl arguments to silence
some 32bit build warnings:

cmds-inspect.c: In function ‘__ino_to_path_fd’:
cmds-inspect.c:47:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
cmds-inspect.c: In function ‘cmd_logical_resolve’:
cmds-inspect.c:171:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Signed-off-by: Zach Brown <zab@redhat.com>
btrfs-progs: print the right mount checking info in restore.c

The mount status is checked against the arg <device> (argv[optind]),
not the <directory>. Correct the info printed on <device> mounted.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
btrfs-progs: Fix getopt on arm platforms

There, 'char' is unsigned, so once assigned '-1' from getopt, it gets
the value 255. Then, it compared to '-1' gives false.

Signed-off-by: Lluis Batlle i Rossell <viric@viric.name>
btrfs-progs: remove "device show" from btrfs man page

Remove "device show" from btrfs man page as it's not supported by the
btrfs utility.

Signed-off-by: Simon Xu <xu.simon@oracle.com>
btrfs-progs: remove '-h' from btrfs man page

Remove '-h' from btrfs man page as it's not supported by the btrfs utility.

Signed-off-by: Simon Xu <xu.simon@oracle.com>
btrfs-progs: ignore -a option in mkfs

Let mkfs accept '-a' option and not complain.  When a partition has non-zero
value in the fs_passno filed in /etc/fstab, the fsck is run but fails and boot
stops. As fsck does not break things currently, it's safe to ignore the option
and let the boot proceed.

Reference: https://bugzilla.novell.com/show_bug.cgi?id=655906

Signed-off-by: David Sterba <dsterba@suse.cz>
Ignore the error ENXIO and ENOMEDIUM during a devs scan

Ignore the error ENXIO (device don't exists) and ENOMEDIUM (
No medium found -> like a cd tray empty) in the function
btrfs_scan_one_dir.
This avoids spurios errors due to an empty CD or a block device node
without a device (which is frequent in a static /dev).

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>