]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.bfs: coding style fix
authorSami Kerola <kerolasa@iki.fi>
Mon, 11 Jul 2011 20:27:09 +0000 (22:27 +0200)
committerSami Kerola <kerolasa@iki.fi>
Mon, 11 Jul 2011 20:46:21 +0000 (22:46 +0200)
Sync with README.devel

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

index 2f5a6039fe9fa695d8168dc44d0595f100d7c0cc..3d87fd05b9be6da221ee2f67dfc73c09bbf85bd2 100644 (file)
@@ -1,23 +1,22 @@
 /*
  *  mkfs.bfs - Create SCO BFS filesystem - aeb, 1999-09-07
  *
- *  Usage: mkfs.bfs [-N nr-of-inodes] [-V volume-name] [-F fsname] device
  */
 
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <limits.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <time.h>
-#include <getopt.h>
+#include <unistd.h>
 
+#include "blkdev.h"
 #include "c.h"
 #include "nls.h"
-#include "blkdev.h"
 #include "strutils.h"
 #include "xalloc.h"
 
 
 /* superblock - 512 bytes */
 struct bfssb {
-        unsigned int s_magic;
-        unsigned int s_start;    /* byte offset of start of data */
-        unsigned int s_end;       /* sizeof(slice)-1 */
-
-        /* for recovery during compaction */
-        int s_from, s_to;         /* src and dest block of current transfer */
-        int s_backup_from, s_backup_to;
-
-        /* labels - may well contain garbage */
-        char s_fsname[6];
-        char s_volume[6];
-        char s_pad[472];
+       unsigned int s_magic;
+       unsigned int s_start;   /* byte offset of start of data */
+       unsigned int s_end;     /* sizeof(slice)-1 */
+
+       /* for recovery during compaction */
+       int s_from, s_to;       /* src and dest block of current transfer */
+       int s_backup_from, s_backup_to;
+
+       /* labels - may well contain garbage */
+       char s_fsname[6];
+       char s_volume[6];
+       char s_pad[472];
 };
 
 /* inode - 64 bytes */
 struct bfsi {
-        unsigned short i_ino;
-        unsigned char i_pad1[2];
-        unsigned long i_first_block;
-        unsigned long i_last_block;
-        unsigned long i_bytes_to_end;
-        unsigned long i_type;           /* 1: file, 2: the unique dir */
-        unsigned long i_mode;
-        unsigned long i_uid, i_gid;
-        unsigned long i_nlinks;
-        unsigned long i_atime, i_mtime, i_ctime;
-        unsigned char i_pad2[16];
+       unsigned short i_ino;
+       unsigned char i_pad1[2];
+       unsigned long i_first_block;
+       unsigned long i_last_block;
+       unsigned long i_bytes_to_end;
+       unsigned long i_type;   /* 1: file, 2: the unique dir */
+       unsigned long i_mode;
+       unsigned long i_uid, i_gid;
+       unsigned long i_nlinks;
+       unsigned long i_atime, i_mtime, i_ctime;
+       unsigned char i_pad2[16];
 };
 
 #define BFS_DIR_TYPE   2
@@ -90,8 +89,8 @@ static void __attribute__ ((__noreturn__)) print_version(void)
        exit(EXIT_SUCCESS);
 }
 
-int
-main(int argc, char *argv[]) {
+int main(int argc, char **argv)
+{
        char *device, *volume, *fsname;
        long inodes;
        unsigned long long total_blocks, ino_bytes, ino_blocks, data_blocks;
@@ -149,9 +148,9 @@ main(int argc, char *argv[]) {
                        verbose = 1;
                        break;
 
-                       /* when called via mkfs we may get options c,l,v */
                case 'c':
                case 'l':
+                       /* when called via mkfs we may get options c,l,v */
                        break;
 
                case VERSION_OPTION:
@@ -168,18 +167,19 @@ main(int argc, char *argv[]) {
 
        device = argv[optind++];
 
-       if (stat(device, &statbuf) == -1)
+       if (stat(device, &statbuf) < 0)
                err(EXIT_FAILURE, _("cannot stat device %s"), device);
 
        if (!S_ISBLK(statbuf.st_mode))
                errx(EXIT_FAILURE, _("%s is not a block special device"), device);
 
        fd = open(device, O_RDWR | O_EXCL);
-       if (fd == -1)
+       if (fd < 0)
                err(EXIT_FAILURE, _("cannot open %s"), device);
 
-       if (optind == argc-1)
-               user_specified_total_blocks = strtoll_or_err(argv[optind], _("invalid block-count"));
+       if (optind == argc - 1)
+               user_specified_total_blocks =
+                       strtoll_or_err(argv[optind], _("invalid block-count"));
        else if (optind != argc)
                usage(stderr);
 
@@ -189,21 +189,22 @@ main(int argc, char *argv[]) {
                total_blocks = user_specified_total_blocks;
        } else if (user_specified_total_blocks) {
                if (user_specified_total_blocks > total_blocks)
-                       errx(EXIT_FAILURE, _("blocks argument too large, max is %llu"),
-                             total_blocks);
+                       errx(EXIT_FAILURE,
+                            _("blocks argument too large, max is %llu"),
+                            total_blocks);
                total_blocks = user_specified_total_blocks;
        }
 
        if (!inodes) {
                /* pick some reasonable default */
-               inodes = 8*(total_blocks/800);
+               inodes = 8 * (total_blocks / 800);
                if (inodes < 48)
                        inodes = 48;
-               if (inodes > 512)
+               if (512 < inodes)
                        inodes = 512;
        } else {
                /* believe the user */
-               if (inodes > 512)
+               if (512 < inodes)
                        errx(EXIT_FAILURE, _("too many inodes - max is 512"));
        }
 
@@ -213,8 +214,9 @@ main(int argc, char *argv[]) {
 
        /* mimic the behaviour of SCO's mkfs - maybe this limit is needed */
        if (data_blocks < 32)
-               errx(EXIT_FAILURE, _("not enough space, need at least %llu blocks"),
-                     ino_blocks + 33);
+               errx(EXIT_FAILURE,
+                    _("not enough space, need at least %llu blocks"),
+                    ino_blocks + 33);
 
        memset(&sb, 0, sizeof(sb));
        sb.s_magic = BFS_SUPER_MAGIC;
@@ -229,7 +231,7 @@ main(int argc, char *argv[]) {
                fprintf(stderr, _("Volume: <%-6s>\n"), volume);
                fprintf(stderr, _("FSname: <%-6s>\n"), fsname);
                fprintf(stderr, _("BlockSize: %d\n"), BFS_BLOCKSIZE);
-               if (ino_blocks==1)
+               if (ino_blocks == 1)
                        fprintf(stderr, _("Inodes: %lu (in 1 block)\n"),
                                inodes);
                else
@@ -237,7 +239,7 @@ main(int argc, char *argv[]) {
                                inodes, ino_blocks);
                fprintf(stderr, _("Blocks: %lld\n"), total_blocks);
                fprintf(stderr, _("Inode end: %d, Data end: %d\n"),
-                       sb.s_start-1, sb.s_end);
+                       sb.s_start - 1, sb.s_end);
        }
 
        if (write(fd, &sb, sizeof(sb)) != sizeof(sb))
@@ -247,11 +249,11 @@ main(int argc, char *argv[]) {
        ri.i_ino = BFS_ROOT_INO;
        ri.i_first_block = 1 + ino_blocks;
        ri.i_last_block = ri.i_first_block +
-               (inodes * sizeof(de) - 1) / BFS_BLOCKSIZE;
+           (inodes * sizeof(de) - 1) / BFS_BLOCKSIZE;
        ri.i_bytes_to_end = ri.i_first_block * BFS_BLOCKSIZE
-               + 2 * sizeof(struct bfsde) - 1;
+           + 2 * sizeof(struct bfsde) - 1;
        ri.i_type = BFS_DIR_TYPE;
-       ri.i_mode = S_IFDIR | 0755;     /* or just 0755 */
+       ri.i_mode = S_IFDIR | 0755;     /* or just 0755 */
        ri.i_uid = 0;
        ri.i_gid = 1;                   /* random */
        ri.i_nlinks = 2;
@@ -264,11 +266,11 @@ main(int argc, char *argv[]) {
                errx(EXIT_FAILURE, _("error writing root inode"));
 
        memset(&ri, 0, sizeof(ri));
-       for (i=1; i<inodes; i++)
+       for (i = 1; i < inodes; i++)
                if (write(fd, &ri, sizeof(ri)) != sizeof(ri))
                        errx(EXIT_FAILURE, _("error writing inode"));
 
-       if (lseek(fd, (1 + ino_blocks)*BFS_BLOCKSIZE, SEEK_SET) == -1)
+       if (lseek(fd, (1 + ino_blocks) * BFS_BLOCKSIZE, SEEK_SET) == -1)
                errx(EXIT_FAILURE, _("seek error"));
 
        memset(&de, 0, sizeof(de));
@@ -281,7 +283,7 @@ main(int argc, char *argv[]) {
        if (write(fd, &de, sizeof(de)) != sizeof(de))
                errx(EXIT_FAILURE, _("error writing .. entry"));
 
-       if (close(fd) == -1)
+       if (close(fd) < 0)
                err(EXIT_FAILURE, _("error closing %s"), device);
 
        return EXIT_SUCCESS;