#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;
# 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;
* 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;
}
}
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 */
}
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)
}
static void
-check_blocks(void) {
+check_blocks(void)
+{
unsigned int current_page;
int do_seek = 1;
char *buffer;
/* 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;
* (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;
}
int
-main(int argc, char ** argv) {
+main(int argc, char **argv) {
struct stat statbuf;
struct swap_header_v1_2 *hdr;
int c;
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;
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' },
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) {
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"),
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);
if (DEV < 0) {
perror(device_name);
- exit(1);
+ exit(EXIT_FAILURE);
}
/* Want a block device. Probably not /dev/hda or /dev/hdb. */
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()"));
freecon(oldcontext);
}
#endif
- return 0;
+ return EXIT_SUCCESS;
}