g_concat.h revision 126589
138032Speter/*- 2141858Sgshapiro * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 338032Speter * All rights reserved. 438032Speter * 538032Speter * Redistribution and use in source and binary forms, with or without 638032Speter * modification, are permitted provided that the following conditions 738032Speter * are met: 838032Speter * 1. Redistributions of source code must retain the above copyright 9141858Sgshapiro * notice, this list of conditions and the following disclaimer. 10141858Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright 11141858Sgshapiro * notice, this list of conditions and the following disclaimer in the 12141858Sgshapiro * documentation and/or other materials provided with the distribution. 13141858Sgshapiro * 14141858Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15141858Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16141858Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17141858Sgshapiro * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18141858Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19141858Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20141858Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21141858Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22141858Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23141858Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24141858Sgshapiro * SUCH DAMAGE. 25141858Sgshapiro * 26141858Sgshapiro * $FreeBSD: head/sys/geom/concat/g_concat.h 126589 2004-03-04 10:22:42Z pjd $ 27141858Sgshapiro */ 28141858Sgshapiro 29141858Sgshapiro#ifndef _G_CONCAT_H_ 30141858Sgshapiro#define _G_CONCAT_H_ 31141858Sgshapiro 32141858Sgshapiro#include <sys/endian.h> 33141858Sgshapiro 34141858Sgshapiro#define G_CONCAT_CLASS_NAME "CONCAT" 35141858Sgshapiro 36141858Sgshapiro#define G_CONCAT_MAGIC "GEOM::CONCAT" 37141858Sgshapiro#define G_CONCAT_VERSION 0 38141858Sgshapiro 39141858Sgshapiro#ifdef _KERNEL 40141858Sgshapiro#define G_CONCAT_TYPE_MANUAL 0 41141858Sgshapiro#define G_CONCAT_TYPE_AUTOMATIC 1 42141858Sgshapiro 43141858Sgshapiro#define G_CONCAT_DEBUG(lvl, ...) do { \ 44141858Sgshapiro if (g_concat_debug >= (lvl)) { \ 45141858Sgshapiro printf("GEOM_CONCAT[%u]: ", lvl); \ 46141858Sgshapiro printf(__VA_ARGS__); \ 47141858Sgshapiro printf("\n"); \ 48141858Sgshapiro } \ 49141858Sgshapiro} while (0) 50141858Sgshapiro#define G_CONCAT_LOGREQ(bp, ...) do { \ 51141858Sgshapiro if (g_concat_debug >= 2) { \ 52141858Sgshapiro printf("GEOM_CONCAT[2]: "); \ 53141858Sgshapiro printf(__VA_ARGS__); \ 54141858Sgshapiro g_print_bio(bp); \ 55141858Sgshapiro printf("\n"); \ 56141858Sgshapiro } \ 57141858Sgshapiro} while (0) 58141858Sgshapiro 59141858Sgshapirostruct g_concat_disk { 60141858Sgshapiro struct g_consumer *d_consumer; 61141858Sgshapiro struct g_concat_softc *d_softc; 62141858Sgshapiro off_t d_start; 63141858Sgshapiro off_t d_end; 64141858Sgshapiro}; 65141858Sgshapiro 66141858Sgshapirostruct g_concat_softc { 67141858Sgshapiro u_int sc_type; /* provider type */ 68141858Sgshapiro struct g_provider *sc_provider; 69141858Sgshapiro char sc_name[16]; /* concat name */ 70141858Sgshapiro uint32_t sc_id; /* concat unique ID */ 71141858Sgshapiro 72141858Sgshapiro struct g_concat_disk *sc_disks; 73141858Sgshapiro uint16_t sc_ndisks; 74132943Sgshapiro}; 75132943Sgshapiro#endif /* _KERNEL */ 76132943Sgshapiro 77132943Sgshapirostruct g_concat_metadata { 78132943Sgshapiro char md_magic[16]; /* Magic value. */ 79132943Sgshapiro uint32_t md_version; /* Version number. */ 80132943Sgshapiro char md_name[16]; /* Concat name. */ 81132943Sgshapiro uint32_t md_id; /* Unique ID. */ 82132943Sgshapiro uint16_t md_no; /* Disk number. */ 83132943Sgshapiro uint16_t md_all; /* Number of all disks. */ 84132943Sgshapiro}; 85132943Sgshapirostatic __inline void 86132943Sgshapiroconcat_metadata_encode(const struct g_concat_metadata *md, u_char *data) 87132943Sgshapiro{ 88132943Sgshapiro 89132943Sgshapiro bcopy(md->md_magic, data, sizeof(md->md_magic)); 90132943Sgshapiro le32enc(data + 16, md->md_version); 91132943Sgshapiro bcopy(md->md_name, data + 20, sizeof(md->md_name)); 92132943Sgshapiro le32enc(data + 36, md->md_id); 93132943Sgshapiro le16enc(data + 40, md->md_no); 94132943Sgshapiro le16enc(data + 42, md->md_all); 95132943Sgshapiro} 96132943Sgshapirostatic __inline void 97132943Sgshapiroconcat_metadata_decode(const u_char *data, struct g_concat_metadata *md) 98132943Sgshapiro{ 99132943Sgshapiro 100132943Sgshapiro bcopy(data, md->md_magic, sizeof(md->md_magic)); 101132943Sgshapiro md->md_version = le32dec(data + 16); 102132943Sgshapiro bcopy(data + 20, md->md_name, sizeof(md->md_name)); 103132943Sgshapiro md->md_id = le32dec(data + 36); 104132943Sgshapiro md->md_no = le16dec(data + 40); 105132943Sgshapiro md->md_all = le16dec(data + 42); 106132943Sgshapiro} 107132943Sgshapiro#endif /* _G_CONCAT_H_ */ 108132943Sgshapiro