values are 14 and 30 for file system versions 1 and 2. Version 3 allows
only value 60. The default is 30.
.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
\fB\-i\fR, \fB\-\-inodes\fR \fInumber\fR
Specify the number of inodes for the filesystem.
.TP
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help text and exit.
+.SH ENVIRONMENT
+.IP LOCK_BLOCK_DEVICE=<mode>
+use exclusive BSD lock. The mode is "1" or "0". See \fB\-\-lock\fR for more details.
.SH EXIT STATUS
The exit status returned by
.B mkfs.minix
struct fs_control {
char *device_name; /* device on a Minix file system is created */
int device_fd; /* open file descriptor of the device */
+ char *lockmode; /* as specified by --lock */
unsigned long long fs_blocks; /* device block count for the file system */
int fs_used_blocks; /* used blocks on a device */
int fs_bad_blocks; /* number of bad blocks found from device */
fputs(_(" -i, --inodes <num> number of inodes for the filesystem\n"), out);
fputs(_(" -c, --check check the device for bad blocks\n"), out);
fputs(_(" -l, --badblocks <file> list of bad blocks from file\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(25));
printf(USAGE_MAN_TAIL("mkfs.minix(8)"));
int i;
struct stat statbuf;
char * listfile = NULL;
+ enum {
+ OPT_LOCK = CHAR_MAX + 1
+ };
static const struct option longopts[] = {
{"namelength", required_argument, NULL, 'n'},
{"inodes", required_argument, NULL, 'i'},
{"badblocks", required_argument, NULL, 'l'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
+ {"lock",optional_argument, NULL, OPT_LOCK},
{NULL, 0, NULL, 0}
};
case 'l':
listfile = optarg;
break;
+ case OPT_LOCK:
+ ctl.lockmode = "1";
+ if (optarg) {
+ if (*optarg == '=')
+ optarg++;
+ ctl.lockmode = optarg;
+ }
+ break;
case 'V':
print_version(MKFS_EX_OK);
case 'h':
ctl.device_fd = open_blkdev_or_file(&statbuf, ctl.device_name, O_RDWR);
if (ctl.device_fd < 0)
err(MKFS_EX_ERROR, _("cannot open %s"), ctl.device_name);
+ if (blkdev_lock(ctl.device_fd, ctl.device_name, ctl.lockmode) != 0)
+ exit(MKFS_EX_ERROR);
determine_device_blocks(&ctl, &statbuf);
setup_tables(&ctl);
if (ctl.check_blocks)