]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.minix: refactor root block content creation
authorSami Kerola <kerolasa@iki.fi>
Wed, 24 Jun 2015 08:15:15 +0000 (09:15 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 30 Jul 2015 09:39:15 +0000 (11:39 +0200)
This does not belong to main() function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/mkfs.minix.c

index c2ab6644c686b92d222ed672353c3093e6230ad7..16305b23fcdd361d8ee48a7c924fa5cb7f5859d8 100644 (file)
@@ -390,6 +390,27 @@ static void make_root_inode_v2_v3 (struct fs_control *ctl) {
 
 static void make_root_inode(struct fs_control *ctl)
 {
+       char *tmp = root_block;
+
+       if (fs_version == 3) {
+               *(uint32_t *) tmp = 1;
+               strcpy(tmp + 4, ".");
+               tmp += ctl->fs_dirsize;
+               *(uint32_t *) tmp = 1;
+               strcpy(tmp + 4, "..");
+               tmp += ctl->fs_dirsize;
+               *(uint32_t *) tmp = 2;
+               strcpy(tmp + 4, ".badblocks");
+       } else {
+               *(uint16_t *) tmp = 1;
+               strcpy(tmp + 2, ".");
+               tmp += ctl->fs_dirsize;
+               *(uint16_t *) tmp = 1;
+               strcpy(tmp + 2, "..");
+               tmp += ctl->fs_dirsize;
+               *(uint16_t *) tmp = 2;
+               strcpy(tmp + 2, ".badblocks");
+       }
        if (fs_version < 2) {
                make_root_inode_v1(ctl);
                return;
@@ -718,7 +739,6 @@ int main(int argc, char ** argv)
                0
        };
        int i;
-       char * tmp;
        struct stat statbuf;
        char * listfile = NULL;
        static const struct option longopts[] = {
@@ -789,26 +809,6 @@ int main(int argc, char ** argv)
        if (is_mounted(ctl.device_name))
                errx(MKFS_EX_ERROR, _("%s is mounted; will not make a filesystem here!"),
                        ctl.device_name);
-       tmp = root_block;
-       if (fs_version == 3) {
-               *(uint32_t *)tmp = 1;
-               strcpy(tmp+4,".");
-               tmp += ctl.fs_dirsize;
-               *(uint32_t *)tmp = 1;
-               strcpy(tmp+4,"..");
-               tmp += ctl.fs_dirsize;
-               *(uint32_t *)tmp = 2;
-               strcpy(tmp+4, ".badblocks");
-       } else {
-               *(uint16_t *)tmp = 1;
-               strcpy(tmp+2,".");
-               tmp += ctl.fs_dirsize;
-               *(uint16_t *)tmp = 1;
-               strcpy(tmp+2,"..");
-               tmp += ctl.fs_dirsize;
-               *(uint16_t *)tmp = 2;
-               strcpy(tmp+2, ".badblocks");
-       }
        if (stat(ctl.device_name, &statbuf) < 0)
                err(MKFS_EX_ERROR, _("stat of %s failed"), ctl.device_name);
        if (S_ISBLK(statbuf.st_mode))