(root)/
util-linux-2.39/
libblkid/
src/
superblocks/
mpool.c
       1  /*
       2   * Copyright (C) 2016 Micron Technology, Inc.
       3   *
       4   * This file may be redistributed under the terms of the
       5   * GNU Lesser General Public License.
       6   */
       7  
       8  #include <stdio.h>
       9  #include <stdlib.h>
      10  #include <unistd.h>
      11  #include <string.h>
      12  #include <stdint.h>
      13  #include "crc32c.h"
      14  #include "superblocks.h"
      15  
      16  #define MAX_MPOOL_NAME_LEN 32
      17  
      18  struct omf_sb_descriptor {
      19  	uint64_t        osb_magic;
      20  	uint8_t         osb_name[MAX_MPOOL_NAME_LEN];
      21  	unsigned char   osb_poolid[16]; /* UUID of pool this drive belongs to */
      22  	uint16_t        osb_vers;
      23  	uint32_t        osb_gen;
      24  	uint32_t        osb_cksum1; /* crc32c of the preceding fields */
      25  } __attribute__((packed));
      26  
      27  static int probe_mpool(blkid_probe pr, const struct blkid_idmag *mag)
      28  {
      29  	struct omf_sb_descriptor *osd;
      30  	uint32_t sb_crc;
      31  
      32  	osd = blkid_probe_get_sb(pr, mag, struct omf_sb_descriptor);
      33  	if (!osd)
      34  		return errno ? -errno : 1;
      35  
      36  	sb_crc = crc32c(~0L, (const void *)osd,
      37  			offsetof(struct omf_sb_descriptor, osb_cksum1));
      38  	sb_crc ^= ~0L;
      39  
      40  	if (!blkid_probe_verify_csum(pr, sb_crc, le32_to_cpu(osd->osb_cksum1)))
      41  		return 1;
      42  
      43  	blkid_probe_set_label(pr, osd->osb_name, sizeof(osd->osb_name));
      44  	blkid_probe_set_uuid(pr, osd->osb_poolid);
      45  
      46  	return 0;
      47  }
      48  
      49  /* "mpoolDev" in ASCII */
      50  #define MPOOL_SB_MAGIC "\x6D\x70\x6f\x6f\x6c\x44\x65\x76"
      51  
      52  const struct blkid_idinfo mpool_idinfo =
      53  {
      54  	.name		= "mpool",
      55  	.usage		= BLKID_USAGE_FILESYSTEM,
      56  	.probefunc	= probe_mpool,
      57  	.magics		=
      58  	{
      59  		{ .magic = MPOOL_SB_MAGIC, .len = 8},
      60  		{ NULL }
      61  	}
      62  };