]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.cramfs: Support BSD lock
authorroot <root@172.16.239.132>
Sun, 16 Oct 2022 15:53:02 +0000 (23:53 +0800)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Oct 2022 07:38:07 +0000 (09:38 +0200)
Addresses: #1842 #921
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkfs.cramfs.8.adoc
disk-utils/mkfs.cramfs.c

index 67f0e629d91926c866679449cd1a64ab65f9e461..14ce8de8238511b827d40d9a4cabcff146997246 100644 (file)
@@ -62,6 +62,15 @@ This option is ignored. Originally the *-s* turned on directory entry sorting.
 *-z*::
 Make explicit holes.
 
+*-l*\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
+
 include::man-common/help-version.adoc[]
 
 == EXIT STATUS
index 1fcb927782aea344e1b9336eeff11fc14155bca2..20966526f500f595fabcad8fdaa57e4b779de9fa 100644 (file)
@@ -44,6 +44,7 @@
  */
 #include <zlib.h>
 
+#include "blkdev.h"
 #include "c.h"
 #include "cramfs.h"
 #include "md5.h"
@@ -140,6 +141,7 @@ static void __attribute__((__noreturn__)) usage(void)
        printf(_(" -p             pad by %d bytes for boot code\n"), PAD_SIZE);
        puts(_(  " -s             sort directory entries (old option, ignored)"));
        puts(_(  " -z             make explicit holes"));
+       puts(_(  " -l lockmode    use exclusive device lock (yes, no or nonblock)"));
        puts(_(  " dirname        root of the filesystem to be compressed"));
        puts(_(  " outfile        output file"));
        fputs(USAGE_SEPARATOR, stdout);
@@ -707,6 +709,7 @@ int main(int argc, char **argv)
        loff_t fslen_ub = sizeof(struct cramfs_super);
        unsigned int fslen_max;
        char const *dirname, *outfile;
+       char *lockmode = 0;
        uint32_t crc = crc32(0L, NULL, 0);
        int c;
        cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; /* default is to use host order */
@@ -730,7 +733,7 @@ int main(int argc, char **argv)
        strutils_set_exitcode(MKFS_EX_USAGE);
 
        /* command line options */
-       while ((c = getopt(argc, argv, "hb:Ee:i:n:N:psVvz")) != EOF) {
+       while ((c = getopt(argc, argv, "hb:Ee:i:n:N:l:psVvz")) != EOF) {
                switch (c) {
                case 'h':
                        usage();
@@ -761,6 +764,14 @@ int main(int argc, char **argv)
                        image_length = st.st_size; /* may be padded later */
                        fslen_ub += (image_length + 3); /* 3 is for padding */
                        break;
+               case 'l':
+                        lockmode = "1";
+                       if (optarg) {
+                                if (*optarg == '=')
+                                       optarg++;
+                               lockmode = optarg;
+                       }
+                       break;
                case 'n':
                        opt_name = optarg;
                        break;
@@ -800,6 +811,9 @@ int main(int argc, char **argv)
        if (fd < 0)
                err(MKFS_EX_USAGE, _("cannot open %s"), outfile);
 
+        if (blkdev_lock(fd, outfile, lockmode) != 0)
+               exit(MKFS_EX_ERROR);
+
        root_entry = xcalloc(1, sizeof(struct entry));
        root_entry->mode = st.st_mode;
        root_entry->uid = st.st_uid;