bc: convert to "G trick" - this returns bc to zero bss increase
[oweals/busybox.git] / util-linux / mkfs_reiser.c
index eb2c94d0230fa7ee1db910f18da05623381c4fa4..b4c8dda6ff40aaecf7da9cc1a7337fadec2b5f26 100644 (file)
@@ -4,27 +4,29 @@
  *
  * 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.
  */
+//config:config MKFS_REISER
+//config:      bool "mkfs_reiser"
+//config:      default n
+//config:      select PLATFORM_LINUX
+//config:      help
+//config:      Utility to create ReiserFS filesystems.
+//config:      Note: this applet needs a lot of testing and polishing.
+
+//applet:IF_MKFS_REISER(APPLET_ODDNAME(mkfs.reiser, mkfs_reiser, BB_DIR_SBIN, BB_SUID_DROP, mkfs_reiser))
+
+//kbuild:lib-$(CONFIG_MKFS_REISER) += mkfs_reiser.o
+
+//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); \
-       else if (sizeof(field) == 2) \
-               field = cpu_to_le16(value); \
-       else if (sizeof(field) == 1) \
-               field = (value); \
-       else \
-               BUG_wrong_field_size(); \
-} while (0)
-
-#define FETCH_LE32(field) \
-       (sizeof(field) == 4 ? cpu_to_le32(field) : BUG_wrong_field_size())
 
 struct journal_params {
        uint32_t jp_journal_1st_block;      /* where does journal start from on its device */
@@ -59,7 +61,7 @@ struct reiserfs_super_block {
 
        char s_magic[10];               /* 52 "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */
        uint16_t sb_fs_state;           /* 62 it is set to used by fsck to mark which phase of rebuilding is done (used for fsck debugging) */
-       uint32_t sb_hash_function_code; /* 64 code of fuction which was/is/will be used to sort names in a directory. See codes in above */
+       uint32_t sb_hash_function_code; /* 64 code of function which was/is/will be used to sort names in a directory. See codes in above */
        uint16_t sb_tree_height;        /* 68 height of filesytem tree. Tree consisting of only one root block has 2 here */
        uint16_t sb_bmap_nr;            /* 70 amount of bitmap blocks needed to address each block of file system */
        uint16_t sb_version;            /* 72 this field is only reliable on filesystem with non-standard journal */
@@ -162,16 +164,15 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
 
        // using global "option_mask32" instead of local "opts":
        // we are register starved here
-       opt_complementary = "-1:b+";
-       /*opts =*/ getopt32(argv, "b:j:s:o:t:B:h:u:l:fqd",
+       /*opts =*/ getopt32(argv, "^" "b:+j:s:o:t:B:h:u:l:fqd" "\0" "-1",
                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &label);
        argv += optind; // argv[0] -- device
 
        // 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
@@ -217,8 +218,8 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
        jp = &sb->sb_journal;
        STORE_LE(jp->jp_journal_1st_block, REISERFS_DISK_OFFSET_IN_BYTES / blocksize + 1/*sb*/ + 1/*bmp#0*/);
        timestamp = time(NULL);
-       srandom(timestamp);
-       STORE_LE(jp->jp_journal_magic, random());
+       srand(timestamp);
+       STORE_LE(jp->jp_journal_magic, rand());
        STORE_LE(jp->jp_journal_size, journal_blocks);
        STORE_LE(jp->jp_journal_trans_max, JOURNAL_TRANS_MAX);
        STORE_LE(jp->jp_journal_max_batch, JOURNAL_MAX_BATCH);