]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - disk-utils/mkswap.c
build-sys: include <uuid.h> rather than <uuid/uuid.h>
[thirdparty/util-linux.git] / disk-utils / mkswap.c
index 2e11f74efca7b6c48d9551bfe41fc86166d79d29..5ddde900128f5073735096ef36a880b789d9aadb 100644 (file)
 #include "xalloc.h"
 
 #ifdef HAVE_LIBUUID
-# ifdef HAVE_UUID_UUID_H
-#  include <uuid/uuid.h>
-# else
-#  include <uuid.h>
-# endif
+# include <uuid.h>
 #endif
 
 #ifdef HAVE_LIBBLKID_INTERNAL
 # include <blkid.h>
 #endif
 
-static char * device_name = NULL;
+static char *device_name = NULL;
 static int DEV = -1;
 static unsigned long long PAGES = 0;
 static unsigned long badpages = 0;
@@ -84,14 +80,17 @@ static int check = 0;
 #  define is_be64() 1
 # else /* sparc32 */
 static int
-is_sparc64(void) {
+is_sparc64(void)
+{
        struct utsname un;
        static int sparc64 = -1;
 
-       if (sparc64 != -1) return sparc64;
+       if (sparc64 != -1)
+               return sparc64;
        sparc64 = 0;
 
-       if (uname(&un) < 0) return 0;
+       if (uname(&un) < 0)
+               return 0;
        if (! strcmp(un.machine, "sparc64")) {
                sparc64 = 1;
                return 1;
@@ -144,20 +143,21 @@ is_sparc64(void) {
  * What to do? Let us allow the user to specify the pagesize explicitly.
  *
  */
-static int user_pagesize;
+static long user_pagesize;
 static int pagesize;
 static unsigned long *signature_page = NULL;
 
 static void
-init_signature_page(void) {
+init_signature_page(void)
+{
 
        int kernel_pagesize = pagesize = getpagesize();
 
        if (user_pagesize) {
-               if ((user_pagesize & (user_pagesize-1)) ||
-                   user_pagesize < sizeof(struct swap_header_v1_2) + 10)
+               if ((user_pagesize & (user_pagesize - 1)) ||
+                   user_pagesize < (long) sizeof(struct swap_header_v1_2) + 10)
                        errx(EXIT_FAILURE,
-                               _("Bad user-specified page size %d"),
+                               _("Bad user-specified page size %lu"),
                                user_pagesize);
                pagesize = user_pagesize;
        }
@@ -171,14 +171,16 @@ init_signature_page(void) {
 }
 
 static void
-write_signature(char *sig) {
+write_signature(char *sig)
+{
        char *sp = (char *) signature_page;
 
-       strncpy(sp+pagesize-10, sig, 10);
+       strncpy(sp + pagesize - 10, sig, 10);
 }
 
 static void
-write_uuid_and_label(unsigned char *uuid, char *volume_name) {
+write_uuid_and_label(unsigned char *uuid, char *volume_name)
+{
        struct swap_header_v1_2 *h;
 
        /* Sanity check */
@@ -292,7 +294,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
 }
 
 static void
-page_bad(int page) {
+page_bad(int page)
+{
        struct swap_header_v1_2 *p = (struct swap_header_v1_2 *) signature_page;
 
        if (badpages == MAX_BADPAGES)
@@ -302,7 +305,8 @@ page_bad(int page) {
 }
 
 static void
-check_blocks(void) {
+check_blocks(void)
+{
        unsigned int current_page;
        int do_seek = 1;
        char *buffer;
@@ -326,14 +330,15 @@ check_blocks(void) {
 
 /* return size in pages */
 static unsigned long long
-get_size(const char  *file) {
-       int     fd;
+get_size(const char *file)
+{
+       int fd;
        unsigned long long size;
 
        fd = open(file, O_RDONLY);
        if (fd < 0) {
                perror(file);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
        if (blkdev_get_size(fd, &size) == 0)
                size /= pagesize;
@@ -349,9 +354,10 @@ get_size(const char  *file) {
  * (C) 2006 Karel Zak -- port to mkswap
  */
 static int
-check_mount(void) {
-       FILE * f;
-       struct mntent * mnt;
+check_mount(void)
+{
+       FILE *f;
+       struct mntent *mnt;
 
        if ((f = setmntent (_PATH_MOUNTED, "r")) == NULL)
                return 0;
@@ -430,7 +436,7 @@ zap_bootbits(int fd, const char *devname, int force, int is_blkdev)
 }
 
 int
-main(int argc, char ** argv) {
+main(int argc, char **argv) {
        struct stat statbuf;
        struct swap_header_v1_2 *hdr;
        int c;
@@ -439,7 +445,7 @@ main(int argc, char ** argv) {
        unsigned long long sz;
        off_t offset;
        int force = 0;
-       int version = 1;
+       long version = 1;
        char *block_count = 0;
        char *opt_label = NULL;
        unsigned char *uuid = NULL;
@@ -447,7 +453,7 @@ main(int argc, char ** argv) {
        const char *opt_uuid = NULL;
        uuid_t uuid_dat;
 #endif
-       struct option longopts[] = {
+       static const struct option longopts[] = {
                { "check",       no_argument,       0, 'c' },
                { "force",       no_argument,       0, 'f' },
                { "pagesize",    required_argument, 0, 'p' },
@@ -507,11 +513,10 @@ main(int argc, char ** argv) {
                usage(stderr);
        }
 
-       if (version != 1) {
+       if (version != 1)
                errx(EXIT_FAILURE,
-                       _("does not support swapspace version %d."),
+                       _("does not support swapspace version %lu."),
                        version);
-       }
 
 #ifdef HAVE_LIBUUID
        if(opt_uuid) {
@@ -539,9 +544,9 @@ main(int argc, char ** argv) {
                PAGES = blks / (pagesize / 1024);
        }
        sz = get_size(device_name);
-       if (!PAGES) {
+       if (!PAGES)
                PAGES = sz;
-       else if (PAGES > sz && !force) {
+       else if (PAGES > sz && !force) {
                errx(EXIT_FAILURE,
                        _("error: "
                          "size %llu KiB is larger than device size %llu KiB"),
@@ -571,7 +576,7 @@ main(int argc, char ** argv) {
 
        if (stat(device_name, &statbuf) < 0) {
                perror(device_name);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
        if (S_ISBLK(statbuf.st_mode))
                DEV = open(device_name, O_RDWR | O_EXCL);
@@ -580,7 +585,7 @@ main(int argc, char ** argv) {
 
        if (DEV < 0) {
                perror(device_name);
-               exit(1);
+               exit(EXIT_FAILURE);
        }
 
        /* Want a block device. Probably not /dev/hda or /dev/hdb. */
@@ -642,7 +647,7 @@ main(int argc, char ** argv) {
                if (fgetfilecon(DEV, &oldcontext) < 0) {
                        if (errno != ENODATA)
                                err(EXIT_FAILURE,
-                                       _("%s: %s: unable to obtain selinux file label: %s"),
+                                       _("%s: unable to obtain selinux file label"),
                                        device_name);
                        if (matchpathcon(device_name, statbuf.st_mode, &oldcontext))
                                errx(EXIT_FAILURE, _("unable to matchpathcon()"));
@@ -663,5 +668,5 @@ main(int argc, char ** argv) {
                freecon(oldcontext);
        }
 #endif
-       return 0;
+       return EXIT_SUCCESS;
 }