]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.minix: add --lock and LOCK_BLOCK_DEVICE
authorKarel Zak <kzak@redhat.com>
Wed, 14 Oct 2020 09:33:13 +0000 (11:33 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Oct 2020 09:33:13 +0000 (11:33 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkfs.minix.8
disk-utils/mkfs.minix.c

index a33d844aa5ce38dd9d0cc543d0452f7389930a33..476fa8cd613ca5c224775ecbea771aa7390270d4 100644 (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
index d6f5756a6c8a26ac21b0f558835aa35b4fb60fd6..1710616bdf08b586fdbf8f65ce93aa54d69961f9 100644 (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)