1+ // This file is a part of the IncludeOS unikernel - www.includeos.org
2+ //
3+ // Copyright 2017 IncludeOS AS, Oslo, Norway
4+ //
5+ // Licensed under the Apache License, Version 2.0 (the "License");
6+ // you may not use this file except in compliance with the License.
7+ // You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing, software
12+ // distributed under the License is distributed on an "AS IS" BASIS,
13+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ // See the License for the specific language governing permissions and
15+ // limitations under the License.
116/* *
217 * Master thesis
318 * by Alf-Andre Walla 2016-2017
4- *
19+ *
520**/
621#pragma once
722#include < cstdint>
@@ -45,12 +60,12 @@ struct storage_entry
4560{
4661 storage_entry (int16_t type, uint16_t id, int length);
4762 storage_entry (int16_t type);
48-
63+
4964 int16_t type = TYPE_END;
5065 uint16_t id = 0 ;
5166 int len = 0 ;
5267 char vla[0 ];
53-
68+
5469 int length () const noexcept {
5570 if (type != TYPE_INTEGER)
5671 return len;
@@ -66,7 +81,7 @@ struct storage_entry
6681 const char * data () const noexcept {
6782 return vla;
6883 }
69-
84+
7085 storage_entry* next () const noexcept ;
7186 uint32_t checksum () const ;
7287};
@@ -75,7 +90,7 @@ struct storage_header
7590{
7691 typedef delegate<int (char *)> construct_func;
7792 static const uint64_t LIVEUPD_MAGIC;
78-
93+
7994 size_t get_length () const noexcept {
8095 return this ->length ;
8196 }
@@ -85,9 +100,9 @@ struct storage_header
85100 uint32_t get_entries () const noexcept {
86101 return this ->entries ;
87102 }
88-
103+
89104 storage_header ();
90-
105+
91106 void add_marker (uint16_t id);
92107 void add_int (uint16_t id, int value);
93108 void add_string (uint16_t id, const std::string& data);
@@ -97,28 +112,28 @@ struct storage_header
97112 void add_vector (uint16_t , const void *, size_t cnt, size_t esize);
98113 void add_string_vector (uint16_t id, const std::vector<std::string>& vec);
99114 void add_end ();
100-
115+
101116 storage_entry* begin ();
102117 storage_entry* next (storage_entry*);
103-
118+
104119 template <typename ... Args>
105120 storage_entry& create_entry (Args&&... args);
106-
121+
107122 inline storage_entry&
108123 var_entry (int16_t type, uint16_t id, construct_func func);
109-
124+
110125 void append_eof () noexcept {
111126 ((storage_entry*) &vla[length])->type = TYPE_END;
112127 }
113128 void finalize ();
114129 bool validate () noexcept ;
115-
130+
116131 // zero out the entire header and its data, for extra security
117132 void zero ();
118-
133+
119134private:
120135 uint32_t generate_checksum () noexcept ;
121-
136+
122137 uint64_t magic;
123138 uint32_t crc;
124139 uint32_t entries = 0 ;
0 commit comments