18d8363epjd/*-
2a82e3a8pfg * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3a82e3a8pfg *
47d8dd19pjd * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
58d8363epjd * All rights reserved.
68d8363epjd *
78d8363epjd * Redistribution and use in source and binary forms, with or without
88d8363epjd * modification, are permitted provided that the following conditions
98d8363epjd * are met:
108d8363epjd * 1. Redistributions of source code must retain the above copyright
118d8363epjd *    notice, this list of conditions and the following disclaimer.
128d8363epjd * 2. Redistributions in binary form must reproduce the above copyright
138d8363epjd *    notice, this list of conditions and the following disclaimer in the
148d8363epjd *    documentation and/or other materials provided with the distribution.
156f074b6pjd *
168d8363epjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
178d8363epjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188d8363epjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198d8363epjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
208d8363epjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218d8363epjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228d8363epjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238d8363epjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248d8363epjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258d8363epjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268d8363epjd * SUCH DAMAGE.
278d8363epjd *
288d8363epjd * $FreeBSD$
298d8363epjd */
308d8363epjd
318d8363epjd#ifndef	_G_SHSEC_H_
328d8363epjd#define	_G_SHSEC_H_
338d8363epjd
348d8363epjd#include <sys/endian.h>
358d8363epjd
368d8363epjd#define	G_SHSEC_CLASS_NAME	"SHSEC"
378d8363epjd
388d8363epjd#define	G_SHSEC_MAGIC		"GEOM::SHSEC"
398d8363epjd/*
408d8363epjd * Version history:
418d8363epjd * 0 - Initial version number.
42668a028pjd * 1 - Added md_provsize field to metadata.
438d8363epjd */
44668a028pjd#define	G_SHSEC_VERSION	1
458d8363epjd
468d8363epjd#ifdef _KERNEL
478d8363epjd#define	G_SHSEC_BFLAG_FIRST	0x1
488d8363epjd
4910d53fccem#define	G_SHSEC_DEBUG(lvl, ...) \
5010d53fccem    _GEOM_DEBUG("GEOM_SHSEC", g_shsec_debug, (lvl), NULL, __VA_ARGS__)
5110d53fccem#define	G_SHSEC_LOGREQ(lvl, bp, ...) \
5210d53fccem    _GEOM_DEBUG("GEOM_SHSEC", g_shsec_debug, (lvl), (bp), __VA_ARGS__)
538d8363epjd
548d8363epjdstruct g_shsec_softc {
558d8363epjd	u_int		 sc_type;	/* provider type */
568d8363epjd	struct g_geom	*sc_geom;
578d8363epjd	struct g_provider *sc_provider;
588d8363epjd	uint32_t	 sc_id;		/* device unique ID */
598d8363epjd	struct g_consumer **sc_disks;
608d8363epjd	uint16_t	 sc_ndisks;
618d8363epjd};
628d8363epjd#define	sc_name	sc_geom->name
638d8363epjd#endif	/* _KERNEL */
648d8363epjd
658d8363epjdstruct g_shsec_metadata {
668d8363epjd	char		md_magic[16];	/* Magic value. */
678d8363epjd	uint32_t	md_version;	/* Version number. */
688d8363epjd	char		md_name[16];	/* Stripe name. */
698d8363epjd	uint32_t	md_id;		/* Unique ID. */
708d8363epjd	uint16_t	md_no;		/* Disk number. */
718d8363epjd	uint16_t	md_all;		/* Number of all disks. */
728d8363epjd	char		md_provider[16]; /* Hardcoded provider. */
73668a028pjd	uint64_t	md_provsize;	/* Provider's size. */
748d8363epjd};
758d8363epjdstatic __inline void
768d8363epjdshsec_metadata_encode(const struct g_shsec_metadata *md, u_char *data)
778d8363epjd{
788d8363epjd
798d8363epjd	bcopy(md->md_magic, data, sizeof(md->md_magic));
808d8363epjd	le32enc(data + 16, md->md_version);
818d8363epjd	bcopy(md->md_name, data + 20, sizeof(md->md_name));
828d8363epjd	le32enc(data + 36, md->md_id);
838d8363epjd	le16enc(data + 40, md->md_no);
848d8363epjd	le16enc(data + 42, md->md_all);
858d8363epjd	bcopy(md->md_provider, data + 44, sizeof(md->md_provider));
86668a028pjd	le64enc(data + 60, md->md_provsize);
878d8363epjd}
888d8363epjdstatic __inline void
898d8363epjdshsec_metadata_decode(const u_char *data, struct g_shsec_metadata *md)
908d8363epjd{
918d8363epjd
928d8363epjd	bcopy(data, md->md_magic, sizeof(md->md_magic));
938d8363epjd	md->md_version = le32dec(data + 16);
948d8363epjd	bcopy(data + 20, md->md_name, sizeof(md->md_name));
958d8363epjd	md->md_id = le32dec(data + 36);
968d8363epjd	md->md_no = le16dec(data + 40);
978d8363epjd	md->md_all = le16dec(data + 42);
988d8363epjd	bcopy(data + 44, md->md_provider, sizeof(md->md_provider));
99668a028pjd	md->md_provsize = le64dec(data + 60);
1008d8363epjd}
1018d8363epjd#endif	/* _G_SHSEC_H_ */
102