int user_pagesize; /* --pagesize */
int pagesize; /* final pagesize used for the header */
+ off_t offset; /* offset of the header in the target */
char *opt_label; /* LABEL as specified on command line */
unsigned char *uuid; /* UUID parsed by libbuuid */
fprintf(out,
_(" -e, --endianness=<value> specify the endianness to use "
"(%s, %s or %s)\n"), "native", "little", "big");
+ fputs(_(" -o, --offset OFFSET specify the offset in the device\n"), out);
fputs(_(" --verbose verbose output\n"), out);
fprintf(out,
err(EXIT_FAILURE, _("cannot open %s"), ctl->devname);
if (blkdev_get_size(fd, &size) < 0)
err(EXIT_FAILURE, _("cannot determine size of %s"), ctl->devname);
+ if ((unsigned long long) ctl->offset > size)
+ errx(EXIT_FAILURE, _("offset larger than file size"));
+ size -= ctl->offset;
size /= ctl->pagesize;
close(fd);
static void write_header_to_device(struct mkswap_control *ctl)
{
+ off_t offset;
+
assert(ctl);
assert(ctl->fd > -1);
assert(ctl->signature_page);
- if (lseek(ctl->fd, SIGNATURE_OFFSET, SEEK_SET) != SIGNATURE_OFFSET)
+ offset = SIGNATURE_OFFSET + ctl->offset;
+
+ if (lseek(ctl->fd, offset, SEEK_SET) != offset)
errx(EXIT_FAILURE, _("unable to rewind swap-device"));
if (write_all(ctl->fd, (char *) ctl->signature_page + SIGNATURE_OFFSET,
{ "swapversion", required_argument, NULL, 'v' },
{ "uuid", required_argument, NULL, 'U' },
{ "endianness", required_argument, NULL, 'e' },
+ { "offset", required_argument, NULL, 'o' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ "lock", optional_argument, NULL, OPT_LOCK },
textdomain(PACKAGE);
close_stdout_atexit();
- while((c = getopt_long(argc, argv, "cfp:qL:v:U:e:Vh", longopts, NULL)) != -1) {
+ while((c = getopt_long(argc, argv, "cfp:qL:v:U:e:o:Vh", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
_("invalid endianness %s is not supported"), optarg);
}
break;
+ case 'o':
+ ctl.offset = str2unum_or_err(optarg,
+ 10, _("Invalid offset"), SINT_MAX(off_t));
+ break;
case 'V':
print_version(EXIT_SUCCESS);
break;