util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libblkid: Add support for zonefs
@ 2020-03-20  4:55 Damien Le Moal
  2020-03-23 10:33 ` Karel Zak
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2020-03-20  4:55 UTC (permalink / raw)
  To: util-linux, Karel Zak, Benno Schulenberg

The zonefs filesystem was added to upstream linux kernel 5.6. This
patch add support for probing zonefs formatted zoned block devices so
that other file system formatting tool can detect its presence on a
device.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 libblkid/src/Makemodule.am             |  1 +
 libblkid/src/superblocks/superblocks.c |  3 +-
 libblkid/src/superblocks/superblocks.h |  1 +
 libblkid/src/superblocks/zonefs.c      | 87 ++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 libblkid/src/superblocks/zonefs.c

diff --git a/libblkid/src/Makemodule.am b/libblkid/src/Makemodule.am
index c5d9426b1..394c2ed43 100644
--- a/libblkid/src/Makemodule.am
+++ b/libblkid/src/Makemodule.am
@@ -101,6 +101,7 @@ libblkid_la_SOURCES = \
 	libblkid/src/superblocks/vxfs.c \
 	libblkid/src/superblocks/xfs.c \
 	libblkid/src/superblocks/zfs.c \
+	libblkid/src/superblocks/zonefs.c \
 	\
 	libblkid/src/topology/topology.c \
 	libblkid/src/topology/topology.h
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index baf35e51b..67172d0a0 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -167,7 +167,8 @@ static const struct blkid_idinfo *idinfos[] =
 	&exfat_idinfo,
 	&f2fs_idinfo,
 	&mpool_idinfo,
-	&apfs_idinfo
+	&apfs_idinfo,
+	&zonefs_idinfo
 };
 
 /*
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index 0cd0caccf..5ebe6bc43 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -84,6 +84,7 @@ extern const struct blkid_idinfo vdo_idinfo;
 extern const struct blkid_idinfo stratis_idinfo;
 extern const struct blkid_idinfo bitlocker_idinfo;
 extern const struct blkid_idinfo apfs_idinfo;
+extern const struct blkid_idinfo zonefs_idinfo;
 
 /*
  * superblock functions
diff --git a/libblkid/src/superblocks/zonefs.c b/libblkid/src/superblocks/zonefs.c
new file mode 100644
index 000000000..aa5d2e1bd
--- /dev/null
+++ b/libblkid/src/superblocks/zonefs.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2020 Western Digital Corporation or its affiliates.
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License
+ */
+#include <stddef.h>
+#include <string.h>
+#include <uuid/uuid.h>
+
+#include "superblocks.h"
+
+#define ZONEFS_MAGIC		"SFOZ" /* 0x5a4f4653 'Z' 'O' 'F' 'S' */
+#define ZONEFS_MAGIC_SIZE	4
+#define ZONEFS_MAGIC_OFST	0
+#define ZONEFS_UUID_SIZE	16
+#define ZONEFS_LABEL_SIZE	32
+#define ZONEFS_SB_OFST		0
+
+#define ZONEFS_BLOCK_SIZE	4096U
+
+struct zonefs_super {
+
+	/* Magic number */
+	__le32		s_magic;
+
+	/* Checksum */
+	__le32		s_crc;
+
+	/* Volume label */
+	char		s_label[ZONEFS_LABEL_SIZE];
+
+	/* 128-bit uuid */
+	__u8		s_uuid[ZONEFS_UUID_SIZE];
+
+	/* Features */
+	__le64		s_features;
+
+	/* UID/GID to use for files */
+	__le32		s_uid;
+	__le32		s_gid;
+
+	/* File permissions */
+	__le32		s_perm;
+
+	/* Padding to 4096 bytes */
+	/* __u8		s_reserved[4020]; */
+
+} __attribute__ ((packed));
+
+static int probe_zonefs(blkid_probe pr,
+		const struct blkid_idmag *mag  __attribute__((__unused__)))
+{
+	struct zonefs_super *sb;
+
+	sb = (struct zonefs_super *)
+		blkid_probe_get_buffer(pr, ZONEFS_SB_OFST,
+				       sizeof(struct zonefs_super));
+	if (!sb)
+		return errno ? -errno : 1;
+
+	if (sb->s_label[0])
+		blkid_probe_set_label(pr, (unsigned char *) sb->s_label,
+				      sizeof(sb->s_label));
+
+	blkid_probe_set_uuid(pr, sb->s_uuid);
+	blkid_probe_set_block_size(pr, ZONEFS_BLOCK_SIZE);
+
+	return 0;
+}
+
+const struct blkid_idinfo zonefs_idinfo =
+{
+	.name           = "zonefs",
+	.usage          = BLKID_USAGE_FILESYSTEM,
+	.probefunc      = probe_zonefs,
+	.magics         =
+        {
+		{
+			.magic = (char *)ZONEFS_MAGIC,
+			.len = ZONEFS_MAGIC_SIZE,
+			.kboff = ZONEFS_SB_OFST,
+			.sboff = ZONEFS_MAGIC_OFST,
+		},
+		{ NULL }
+	}
+};
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] libblkid: Add support for zonefs
  2020-03-20  4:55 [PATCH] libblkid: Add support for zonefs Damien Le Moal
@ 2020-03-23 10:33 ` Karel Zak
  2020-03-23 10:38   ` Damien Le Moal
  2020-04-01  4:44   ` Damien Le Moal
  0 siblings, 2 replies; 5+ messages in thread
From: Karel Zak @ 2020-03-23 10:33 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: util-linux, Benno Schulenberg

On Fri, Mar 20, 2020 at 01:55:43PM +0900, Damien Le Moal wrote:
>  libblkid/src/Makemodule.am             |  1 +
>  libblkid/src/superblocks/superblocks.c |  3 +-
>  libblkid/src/superblocks/superblocks.h |  1 +
>  libblkid/src/superblocks/zonefs.c      | 87 ++++++++++++++++++++++++++
>  4 files changed, 91 insertions(+), 1 deletion(-)
>  create mode 100644 libblkid/src/superblocks/zonefs.c

Applied (with a small change), thanks.

> +struct zonefs_super {
> +
> +	/* Magic number */
> +	__le32		s_magic;

We use standard integer types rather than this kernel-ism ;-) Fixed.

It would be nice to have a test image for zonefs, something small what
we can add to tests/ts/blkid/images-fs/ ;-)


    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libblkid: Add support for zonefs
  2020-03-23 10:33 ` Karel Zak
@ 2020-03-23 10:38   ` Damien Le Moal
  2020-04-01  4:44   ` Damien Le Moal
  1 sibling, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2020-03-23 10:38 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Benno Schulenberg

On 2020/03/23 19:33, Karel Zak wrote:
> On Fri, Mar 20, 2020 at 01:55:43PM +0900, Damien Le Moal wrote:
>>  libblkid/src/Makemodule.am             |  1 +
>>  libblkid/src/superblocks/superblocks.c |  3 +-
>>  libblkid/src/superblocks/superblocks.h |  1 +
>>  libblkid/src/superblocks/zonefs.c      | 87 ++++++++++++++++++++++++++
>>  4 files changed, 91 insertions(+), 1 deletion(-)
>>  create mode 100644 libblkid/src/superblocks/zonefs.c
> 
> Applied (with a small change), thanks.
> 
>> +struct zonefs_super {
>> +
>> +	/* Magic number */
>> +	__le32		s_magic;
> 
> We use standard integer types rather than this kernel-ism ;-) Fixed.
> 
> It would be nice to have a test image for zonefs, something small what
> we can add to tests/ts/blkid/images-fs/ ;-)

Overlooked that. With null-blk with zoned=1 option set, it is easy to create a
test device without any hardware. Because with an image file, we are not going
to get a zoned block device with loopback, which may cause some problems as that
would not be normal at all to see zonefs on a regular block device.

> 
> 
>     Karel
> 


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libblkid: Add support for zonefs
  2020-03-23 10:33 ` Karel Zak
  2020-03-23 10:38   ` Damien Le Moal
@ 2020-04-01  4:44   ` Damien Le Moal
  2020-04-06 13:35     ` Karel Zak
  1 sibling, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2020-04-01  4:44 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Benno Schulenberg

[-- Attachment #1: Type: text/plain, Size: 1263 bytes --]

On 2020/03/23 19:33, Karel Zak wrote:
> On Fri, Mar 20, 2020 at 01:55:43PM +0900, Damien Le Moal wrote:
>>  libblkid/src/Makemodule.am             |  1 +
>>  libblkid/src/superblocks/superblocks.c |  3 +-
>>  libblkid/src/superblocks/superblocks.h |  1 +
>>  libblkid/src/superblocks/zonefs.c      | 87 ++++++++++++++++++++++++++
>>  4 files changed, 91 insertions(+), 1 deletion(-)
>>  create mode 100644 libblkid/src/superblocks/zonefs.c
> 
> Applied (with a small change), thanks.
> 
>> +struct zonefs_super {
>> +
>> +	/* Magic number */
>> +	__le32		s_magic;
> 
> We use standard integer types rather than this kernel-ism ;-) Fixed.
> 
> It would be nice to have a test image for zonefs, something small what
> we can add to tests/ts/blkid/images-fs/ ;-)

Hi Karel,

Please find attached the zonefs.img.xz file for a small (4 MB uncompressed)
image of a zonefs file system. I tested it with the blkid run in
tests/ts/blkid/low-probe and it works. I am not sure if other tests are run
against FS images as I have not dig into the test suite (I should !).

If this is OK, please feel free to add the image to tests/ts/blkid/images-fs/.

Best regards.

> 
> 
>     Karel
> 


-- 
Damien Le Moal
Western Digital Research

[-- Attachment #2: zonefs.img.xz --]
[-- Type: application/octet-stream, Size: 784 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libblkid: Add support for zonefs
  2020-04-01  4:44   ` Damien Le Moal
@ 2020-04-06 13:35     ` Karel Zak
  0 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2020-04-06 13:35 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: util-linux, Benno Schulenberg

On Wed, Apr 01, 2020 at 04:44:29AM +0000, Damien Le Moal wrote:
> On 2020/03/23 19:33, Karel Zak wrote:
> > On Fri, Mar 20, 2020 at 01:55:43PM +0900, Damien Le Moal wrote:
> >>  libblkid/src/Makemodule.am             |  1 +
> >>  libblkid/src/superblocks/superblocks.c |  3 +-
> >>  libblkid/src/superblocks/superblocks.h |  1 +
> >>  libblkid/src/superblocks/zonefs.c      | 87 ++++++++++++++++++++++++++
> >>  4 files changed, 91 insertions(+), 1 deletion(-)
> >>  create mode 100644 libblkid/src/superblocks/zonefs.c
> > 
> > Applied (with a small change), thanks.
> > 
> >> +struct zonefs_super {
> >> +
> >> +	/* Magic number */
> >> +	__le32		s_magic;
> > 
> > We use standard integer types rather than this kernel-ism ;-) Fixed.
> > 
> > It would be nice to have a test image for zonefs, something small what
> > we can add to tests/ts/blkid/images-fs/ ;-)
> 
> Hi Karel,
> 
> Please find attached the zonefs.img.xz file for a small (4 MB uncompressed)
> image of a zonefs file system. I tested it with the blkid run in
> tests/ts/blkid/low-probe and it works. I am not sure if other tests are run
> against FS images as I have not dig into the test suite (I should !).

No problem ;-)

> If this is OK, please feel free to add the image to tests/ts/blkid/images-fs/.

Done, thanks for the image!
https://github.com/karelzak/util-linux/commit/ea4dcdc788f2736c0f36cc59e79fb421e5bef915

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-06 13:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20  4:55 [PATCH] libblkid: Add support for zonefs Damien Le Moal
2020-03-23 10:33 ` Karel Zak
2020-03-23 10:38   ` Damien Le Moal
2020-04-01  4:44   ` Damien Le Moal
2020-04-06 13:35     ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).