it defaults to \fBauto\fR. The colors can be disabled, for the current built-in default
see \fB\-\-help\fR output. See also the COLORS section.
.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 \-V , " \-\-version"
Display version information and exit.
.TP
enables libsmartcols debug output.
.IP LIBSMARTCOLS_DEBUG_PADDING=on
use visible padding characters. Requires enabled LIBSMARTCOLS_DEBUG.
+.IP LOCK_BLOCK_DEVICE=<mode>
+use exclusive BSD lock. The mode is "1" or "0". See \fB\-\-lock\fR for more details.
.SH AUTHORS
Karel Zak <kzak@redhat.com>
#include "colors.h"
#include "debug.h"
#include "list.h"
+#include "blkdev.h"
static const char *default_disks[] = {
#ifdef __GNU__
else
ui_center(2, _("Label: %s"), fdisk_label_get_name(lb));
free(strsz);
+ free(id);
ui_draw_table(cf);
ui_draw_menu(cf);
fprintf(out,
" %s\n", USAGE_COLORS_DEFAULT);
fputs(_(" -z, --zero start with zeroed partition table\n"), out);
+ fprintf(out,
+ _(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
fputs(USAGE_SEPARATOR, out);
printf(USAGE_HELP_OPTIONS(26));
int main(int argc, char *argv[])
{
- const char *diskpath = NULL;
+ const char *diskpath = NULL, *lockmode = NULL;
int rc, c, colormode = UL_COLORMODE_UNDEF;
struct cfdisk _cf = { .lines_idx = 0 },
*cf = &_cf;
-
+ enum {
+ OPT_LOCK = CHAR_MAX + 1
+ };
static const struct option longopts[] = {
{ "color", optional_argument, NULL, 'L' },
+ { "lock", optional_argument, NULL, OPT_LOCK },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "zero", no_argument, NULL, 'z' },
case 'z':
cf->zero_start = 1;
break;
+ case OPT_LOCK:
+ lockmode = "1";
+ if (optarg) {
+ if (*optarg == '=')
+ optarg++;
+ lockmode = optarg;
+ }
+ break;
default:
errtryhelp(EXIT_FAILURE);
}
err(EXIT_FAILURE, _("cannot open %s"), diskpath);
if (!fdisk_is_readonly(cf->cxt)) {
+ if (blkdev_lock(fdisk_get_devfd(cf->cxt), diskpath, lockmode) != 0)
+ return EXIT_FAILURE;
+
cf->device_is_used = fdisk_device_is_used(cf->cxt);
fdisk_get_partitions(cf->cxt, &cf->original_layout);
}