Fix some compiler warnings emitted by gcc-4.8.0
[oweals/busybox.git] / util-linux / mkfs_reiser.c
index 7f37eb8455c622aaffd7f9a843f54bb9b5d71d33..b4efb9e9f4c22635a215f48102cdbfbf521fdc14 100644 (file)
@@ -4,19 +4,26 @@
  *
  * Busybox'ed (2009) by Vladimir Dronnikov <dronnikov@gmail.com>
  *
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
+
+//usage:#define mkfs_reiser_trivial_usage
+//usage:       "[-f] [-l LABEL] BLOCKDEV [4K-BLOCKS]"
+//usage:#define mkfs_reiser_full_usage "\n\n"
+//usage:       "Make a ReiserFS V3 filesystem\n"
+//usage:     "\n       -f      Force"
+//usage:     "\n       -l LBL  Volume label"
+
 #include "libbb.h"
 #include <linux/fs.h>
-#include "volume_id/volume_id_internal.h"
 
 char BUG_wrong_field_size(void);
 #define STORE_LE(field, value) \
 do { \
        if (sizeof(field) == 4) \
-               field = cpu_to_le32(value); \
+               field = SWAP_LE32(value); \
        else if (sizeof(field) == 2) \
-               field = cpu_to_le16(value); \
+               field = SWAP_LE16(value); \
        else if (sizeof(field) == 1) \
                field = (value); \
        else \
@@ -24,7 +31,7 @@ do { \
 } while (0)
 
 #define FETCH_LE32(field) \
-       (sizeof(field) == 4 ? cpu_to_le32(field) : BUG_wrong_field_size())
+       (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size())
 
 struct journal_params {
        uint32_t jp_journal_1st_block;      /* where does journal start from on its device */
@@ -169,29 +176,18 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
 
        // check the device is a block device
        fd = xopen(argv[0], O_WRONLY | O_EXCL);
-       fstat(fd, &st);
+       xfstat(fd, &st, argv[0]);
        if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_f))
-               bb_error_msg_and_die("not a block device");
+               bb_error_msg_and_die("%s: not a block device", argv[0]);
 
        // check if it is mounted
        // N.B. what if we format a file? find_mount_point will return false negative since
-       // it is loop block device which mounted!
+       // it is loop block device which is mounted!
        if (find_mount_point(argv[0], 0))
                bb_error_msg_and_die("can't format mounted filesystem");
 
        // open the device, get size in blocks
-       if (argv[1]) {
-               blocks = xatoull(argv[1]);
-               // seek past end fails on block devices but works on files
-               if (lseek(fd, blocks * blocksize - 1, SEEK_SET) != (off_t)-1) {
-                       xwrite(fd, "", 1); // file grows if needed
-               }
-               //else {
-               //      bb_error_msg("warning, block device is smaller");
-               //}
-       } else {
-               blocks = (uoff_t)xlseek(fd, 0, SEEK_END) / blocksize;
-       }
+       blocks = get_volume_size_in_bytes(fd, argv[1], blocksize, /*extend:*/ 1) / blocksize;
 
        // block number sanity check
        // we have a limit: skipped area, super block, journal and root block