.B swapon
by label.
.TP
+\fB\-\-lock\fR[=\fImode\fR]
+Use exclusive BSD lock for device or file it operates. The optional argument
+\fImode\fP can be \fByes\fR, \fBno\fR (or 1 and 0) or \fBnonblock\fR. If the \fImode\fR
+argument is omitted, it defaults to \fB"yes"\fR. This option overwrites
+environment variable \fB$LOCK_BLOCK_DEVICE\fR. The default is not to use any
+lock at all, but it's recommended to avoid collisions with udevd or other
+tools.
+.TP
.BR \-p , " \-\-pagesize " \fIsize\fR
Specify the page \fIsize\fR (in bytes) to use. This option is usually unnecessary;
.B mkswap
.SH ENVIRONMENT
.IP LIBBLKID_DEBUG=all
enables libblkid debug output.
+.IP LOCK_BLOCK_DEVICE=<mode>
+use exclusive BSD lock. The mode is "1" or "0". See \fB\-\-lock\fR for more details.
.SH NOTES
The maximum useful size of a swap area depends on the architecture and
void *signature_page;/* buffer with swap header */
char *devname; /* device or file name */
+ const char *lockmode; /* as specified by --lock */
struct stat devstat; /* stat() result */
int fd; /* swap file descriptor */
" -v, --swapversion NUM specify swap-space version number\n"
" -U, --uuid UUID specify the uuid to use\n"
));
+ fprintf(out,
+ _(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
printf(USAGE_HELP_OPTIONS(27));
printf(USAGE_MAN_TAIL("mkswap(8)"));
ctl->fd = open_blkdev_or_file(&ctl->devstat, ctl->devname, O_RDWR);
if (ctl->fd < 0)
err(EXIT_FAILURE, _("cannot open %s"), ctl->devname);
+
+ if (blkdev_lock(ctl->fd, ctl->devname, ctl->lockmode) != 0)
+ exit(EXIT_FAILURE);
+
if (ctl->check && S_ISREG(ctl->devstat.st_mode)) {
ctl->check = 0;
warnx(_("warning: checking bad blocks from swap file is not supported: %s"),
const char *opt_uuid = NULL;
uuid_t uuid_dat;
#endif
+ enum {
+ OPT_LOCK = CHAR_MAX + 1,
+ };
static const struct option longopts[] = {
{ "check", no_argument, NULL, 'c' },
{ "force", no_argument, NULL, 'f' },
{ "uuid", required_argument, NULL, 'U' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
+ { "lock", optional_argument, NULL, OPT_LOCK },
{ NULL, 0, NULL, 0 }
};
break;
case 'V':
print_version(EXIT_SUCCESS);
+ break;
+ case OPT_LOCK:
+ ctl.lockmode = "1";
+ if (optarg) {
+ if (*optarg == '=')
+ optarg++;
+ ctl.lockmode = optarg;
+ }
+ break;
case 'h':
usage();
default: