]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.bfs: Support BSD lock
authorplus <plus@localhost.localdomain>
Thu, 13 Oct 2022 08:37:20 +0000 (16:37 +0800)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Oct 2022 07:36:56 +0000 (09:36 +0200)
Addresses: #1842 #921
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkfs.bfs.8.adoc
disk-utils/mkfs.bfs.c

index 6b04b105f0e1b477e087464c96edbd8bd5a6e7be..198d61f5efaf5cc2ba3262462520d0ac7ad302e3 100644 (file)
@@ -35,6 +35,9 @@ Specify the volume _label_. I have no idea if/where this is used.
 *-F*, *--fname* _name_::
 Specify the filesystem _name_. I have no idea if/where this is used.
 
+*--lock*[=_mode_]::
+Use exclusive BSD lock for device or file it operates. The optional argument _mode_ can be *yes*, *no* (or 1 and 0) or *nonblock*. If the _mode_ argument is omitted, it defaults to *yes*. This option overwrites environment variable *$LOCK_BLOCK_DEVICE*. The default is not to use any lock at all, but it's recommended to avoid collisions with *systemd-udevd*(8) or other tools.
+
 *-v*, *--verbose*::
 Explain what is being done.
 
index 54d261b293d5de7dd75e79bc0130fafe61c3cebd..541aa0315c8ad0f3a910403b94f4f7297f543068 100644 (file)
@@ -22,6 +22,7 @@
 #include "strutils.h"
 #include "xalloc.h"
 #include "bitops.h"
+#include "exitcodes.h"
 
 #define BFS_ROOT_INO           2
 #define BFS_NAMELEN            14
@@ -84,6 +85,7 @@ static void __attribute__((__noreturn__)) usage(void)
                       " -v, --verbose       explain what is being done\n"
                       " -c                  this option is silently ignored\n"
                       " -l                  this option is silently ignored\n"
+                      " --lock=[=<mode>]    use exclusive device lock (yes, no or nonblock)\n"
                       ));
        printf(USAGE_HELP_OPTIONS(21));
 
@@ -94,6 +96,7 @@ static void __attribute__((__noreturn__)) usage(void)
 int main(int argc, char **argv)
 {
        char *device, *volume, *fsname;
+       char *lockmode = 0;
        long inodes;
        unsigned long long total_blocks, ino_bytes, ino_blocks, data_blocks;
        unsigned long long user_specified_total_blocks = 0;
@@ -107,7 +110,10 @@ int main(int argc, char **argv)
        time_t now;
        int c, i, len;
 
-       enum { VERSION_OPTION = CHAR_MAX + 1 };
+       enum {
+           VERSION_OPTION = CHAR_MAX + 1,
+           OPT_LOCK
+       };
        static const struct option longopts[] = {
                {"inodes", required_argument, NULL, 'N'},
                {"vname", required_argument, NULL, 'V'},
@@ -115,6 +121,7 @@ int main(int argc, char **argv)
                {"verbose", no_argument, NULL, 'v'},
                {"version", no_argument, NULL, VERSION_OPTION},
                {"help", no_argument, NULL, 'h'},
+               {"lock", optional_argument, NULL, OPT_LOCK},
                {NULL, 0, NULL, 0}
        };
 
@@ -162,6 +169,15 @@ int main(int argc, char **argv)
                        /* when called via mkfs we may get options c,l,v */
                        break;
 
+                case OPT_LOCK:
+                       lockmode = "1";
+                       if (optarg) {
+                               if (*optarg == '=')
+                                       optarg++;
+                               lockmode = optarg;
+                       }
+                       break;
+
                case VERSION_OPTION:
                        print_version(EXIT_SUCCESS);
                case 'h':
@@ -185,6 +201,9 @@ int main(int argc, char **argv)
        if (fd < 0)
                err(EXIT_FAILURE, _("cannot open %s"), device);
 
+       if (blkdev_lock(fd, device, lockmode) != 0)
+               exit(MKFS_EX_ERROR);
+
        if (optind == argc - 1)
                user_specified_total_blocks =
                        strtou64_or_err(argv[optind], _("invalid block-count"));