]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/9.x/sys/geom/ventoy/g_ventoy.h
e442b246efccfaeb10366a31c71fcb8f70e2735a
[Ventoy.git] / Unix / ventoy_unix_src / FreeBSD / geom_ventoy_src / 9.x / sys / geom / ventoy / g_ventoy.h
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2020 longpanda <admin@ventoy.net>
5 * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD$
30 */
31
32 #ifndef _G_VENTOY_H_
33 #define _G_VENTOY_H_
34
35 #include <sys/endian.h>
36
37 #define G_VENTOY_CLASS_NAME "VENTOY"
38
39 #define G_VENTOY_MAGIC "GEOM::VENTOY"
40 /*
41 * Version history:
42 * 1 - Initial version number.
43 * 2 - Added 'stop' command to gconcat(8).
44 * 3 - Added md_provider field to metadata and '-h' option to gconcat(8).
45 * 4 - Added md_provsize field to metadata.
46 */
47 #define G_VENTOY_VERSION 4
48
49 #ifdef _KERNEL
50 #define G_VENTOY_TYPE_MANUAL 0
51 #define G_VENTOY_TYPE_AUTOMATIC 1
52
53 #define G_DEBUG(...) if (bootverbose) printf(__VA_ARGS__)
54 #define G_VENTOY_DEBUG(lvl, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
55 #define G_VENTOY_LOGREQ(bp, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
56
57 struct g_ventoy_disk {
58 struct g_consumer *d_consumer;
59 struct g_ventoy_softc *d_softc;
60 off_t d_start;
61 off_t d_end;
62 off_t d_map_start;
63 off_t d_map_end;
64 int d_candelete;
65 int d_removed;
66 };
67
68 struct g_ventoy_softc {
69 u_int sc_type; /* provider type */
70 struct g_geom *sc_geom;
71 struct g_provider *sc_provider;
72 uint32_t sc_id; /* concat unique ID */
73
74 struct g_ventoy_disk *sc_disks;
75 uint16_t sc_ndisks;
76 struct mtx sc_lock;
77 };
78 #define sc_name sc_geom->name
79 #endif /* _KERNEL */
80
81 struct g_ventoy_metadata {
82 char md_magic[16]; /* Magic value. */
83 uint32_t md_version; /* Version number. */
84 char md_name[16]; /* Concat name. */
85 uint32_t md_id; /* Unique ID. */
86 uint16_t md_no; /* Disk number. */
87 uint16_t md_all; /* Number of all disks. */
88 char md_provider[16]; /* Hardcoded provider. */
89 uint64_t md_provsize; /* Provider's size. */
90 };
91 static __inline void
92 ventoy_metadata_encode(const struct g_ventoy_metadata *md, u_char *data)
93 {
94
95 bcopy(md->md_magic, data, sizeof(md->md_magic));
96 le32enc(data + 16, md->md_version);
97 bcopy(md->md_name, data + 20, sizeof(md->md_name));
98 le32enc(data + 36, md->md_id);
99 le16enc(data + 40, md->md_no);
100 le16enc(data + 42, md->md_all);
101 bcopy(md->md_provider, data + 44, sizeof(md->md_provider));
102 le64enc(data + 60, md->md_provsize);
103 }
104 static __inline void
105 ventoy_metadata_decode(const u_char *data, struct g_ventoy_metadata *md)
106 {
107
108 bcopy(data, md->md_magic, sizeof(md->md_magic));
109 md->md_version = le32dec(data + 16);
110 bcopy(data + 20, md->md_name, sizeof(md->md_name));
111 md->md_id = le32dec(data + 36);
112 md->md_no = le16dec(data + 40);
113 md->md_all = le16dec(data + 42);
114 bcopy(data + 44, md->md_provider, sizeof(md->md_provider));
115 md->md_provsize = le64dec(data + 60);
116 }
117 #endif /* _G_VENTOY_H_ */