mkfs.minix: add --lock and LOCK_BLOCK_DEVICE

Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2020-10-14 11:33:13 +02:00
parent 91f80d9a2a
commit e57cbfe0aa
2 changed files with 28 additions and 0 deletions

View File

@ -46,6 +46,14 @@ Specify the maximum length of filenames. Currently, the only allowable
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
@ -70,6 +78,9 @@ with other options.
.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

View File

@ -105,6 +105,7 @@ static char *inode_buffer = NULL;
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 */
@ -144,6 +145,8 @@ static void __attribute__((__noreturn__)) usage(void)
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)"));
@ -745,6 +748,9 @@ int main(int argc, char ** argv)
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'},
@ -752,6 +758,7 @@ int main(int argc, char ** argv)
{"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}
};
@ -791,6 +798,14 @@ int main(int argc, char ** argv)
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':
@ -821,6 +836,8 @@ int main(int argc, char ** argv)
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)