From: root Date: Sun, 16 Oct 2022 15:53:02 +0000 (+0800) Subject: mkfs.cramfs: Support BSD lock X-Git-Tag: v2.39-rc1~484 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=57fdc17c92295d37ccf12f3cf32a1760499dcd3d;p=thirdparty%2Futil-linux.git mkfs.cramfs: Support BSD lock Addresses: #1842 #921 Signed-off-by: Karel Zak --- diff --git a/disk-utils/mkfs.cramfs.8.adoc b/disk-utils/mkfs.cramfs.8.adoc index 67f0e629d9..14ce8de823 100644 --- a/disk-utils/mkfs.cramfs.8.adoc +++ b/disk-utils/mkfs.cramfs.8.adoc @@ -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 diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 1fcb927782..20966526f5 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -44,6 +44,7 @@ */ #include +#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;