]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Unix/ventoy_unix_src/FreeBSD/geom_ventoy_src/11.x/sys/geom/ventoy/g_ventoy.h
81801bee70683c74750050a084720594c58251da
[Ventoy.git] / Unix / ventoy_unix_src / FreeBSD / geom_ventoy_src / 11.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 /*
33 * This file is just copied from g_concat.h and replace strings
34 * "concat" ==> "ventoy"
35 * "CONCAT" ==> "VENTOY"
36 */
37
38 #ifndef _G_VENTOY_H_
39 #define _G_VENTOY_H_
40
41 #include <sys/endian.h>
42
43 #define G_VENTOY_CLASS_NAME "VENTOY"
44
45 #define G_VENTOY_MAGIC "GEOM::VENTOY"
46 /*
47 * Version history:
48 * 1 - Initial version number.
49 * 2 - Added 'stop' command to gconcat(8).
50 * 3 - Added md_provider field to metadata and '-h' option to gconcat(8).
51 * 4 - Added md_provsize field to metadata.
52 */
53 #define G_VENTOY_VERSION 4
54
55 #ifdef _KERNEL
56 #define G_VENTOY_TYPE_MANUAL 0
57 #define G_VENTOY_TYPE_AUTOMATIC 1
58
59 #define G_DEBUG(...) if (bootverbose) printf(__VA_ARGS__)
60 #define G_VENTOY_DEBUG(lvl, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
61 #define G_VENTOY_LOGREQ(bp, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
62
63 struct g_ventoy_disk {
64 struct g_consumer *d_consumer;
65 struct g_ventoy_softc *d_softc;
66 off_t d_start;
67 off_t d_end;
68 off_t d_map_start;
69 off_t d_map_end;
70 int d_candelete;
71 int d_removed;
72 };
73
74 struct g_ventoy_softc {
75 u_int sc_type; /* provider type */
76 struct g_geom *sc_geom;
77 struct g_provider *sc_provider;
78 uint32_t sc_id; /* concat unique ID */
79
80 struct g_ventoy_disk *sc_disks;
81 uint16_t sc_ndisks;
82 struct mtx sc_lock;
83 };
84 #define sc_name sc_geom->name
85 #endif /* _KERNEL */
86
87 struct g_ventoy_metadata {
88 char md_magic[16]; /* Magic value. */
89 uint32_t md_version; /* Version number. */
90 char md_name[16]; /* Concat name. */
91 uint32_t md_id; /* Unique ID. */
92 uint16_t md_no; /* Disk number. */
93 uint16_t md_all; /* Number of all disks. */
94 char md_provider[16]; /* Hardcoded provider. */
95 uint64_t md_provsize; /* Provider's size. */
96 };
97 static __inline void
98 ventoy_metadata_encode(const struct g_ventoy_metadata *md, u_char *data)
99 {
100
101 bcopy(md->md_magic, data, sizeof(md->md_magic));
102 le32enc(data + 16, md->md_version);
103 bcopy(md->md_name, data + 20, sizeof(md->md_name));
104 le32enc(data + 36, md->md_id);
105 le16enc(data + 40, md->md_no);
106 le16enc(data + 42, md->md_all);
107 bcopy(md->md_provider, data + 44, sizeof(md->md_provider));
108 le64enc(data + 60, md->md_provsize);
109 }
110 static __inline void
111 ventoy_metadata_decode(const u_char *data, struct g_ventoy_metadata *md)
112 {
113
114 bcopy(data, md->md_magic, sizeof(md->md_magic));
115 md->md_version = le32dec(data + 16);
116 bcopy(data + 20, md->md_name, sizeof(md->md_name));
117 md->md_id = le32dec(data + 36);
118 md->md_no = le16dec(data + 40);
119 md->md_all = le16dec(data + 42);
120 bcopy(data + 44, md->md_provider, sizeof(md->md_provider));
121 md->md_provsize = le64dec(data + 60);
122 }
123 #endif /* _G_VENTOY_H_ */