along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <inttypes.h>
+#include "sparse-endian.h"
#include <systemd/sd-id128.h>
uint8_t type;
uint8_t flags;
uint8_t reserved[6];
- uint64_t size;
+ le64_t size;
uint8_t payload[];
};
_packed_ struct DataObject {
ObjectHeader object;
- uint64_t hash;
- uint64_t next_hash_offset;
- uint64_t next_field_offset;
- uint64_t entry_offset; /* the first array entry we store inline */
- uint64_t entry_array_offset;
- uint64_t n_entries;
+ le64_t hash;
+ le64_t next_hash_offset;
+ le64_t next_field_offset;
+ le64_t entry_offset; /* the first array entry we store inline */
+ le64_t entry_array_offset;
+ le64_t n_entries;
uint8_t payload[];
};
_packed_ struct FieldObject {
ObjectHeader object;
- uint64_t hash;
- uint64_t next_hash_offset;
- uint64_t head_data_offset;
- uint64_t tail_data_offset;
+ le64_t hash;
+ le64_t next_hash_offset;
+ le64_t head_data_offset;
+ le64_t tail_data_offset;
uint8_t payload[];
};
_packed_ struct EntryItem {
- uint64_t object_offset;
- uint64_t hash;
+ le64_t object_offset;
+ le64_t hash;
};
_packed_ struct EntryObject {
ObjectHeader object;
- uint64_t seqnum;
- uint64_t realtime;
- uint64_t monotonic;
+ le64_t seqnum;
+ le64_t realtime;
+ le64_t monotonic;
sd_id128_t boot_id;
- uint64_t xor_hash;
+ le64_t xor_hash;
EntryItem items[];
};
_packed_ struct HashItem {
- uint64_t head_hash_offset;
- uint64_t tail_hash_offset;
+ le64_t head_hash_offset;
+ le64_t tail_hash_offset;
};
_packed_ struct HashTableObject {
_packed_ struct EntryArrayObject {
ObjectHeader object;
- uint64_t next_entry_array_offset;
- uint64_t items[];
+ le64_t next_entry_array_offset;
+ le64_t items[];
};
union Object {
sd_id128_t machine_id;
sd_id128_t boot_id;
sd_id128_t seqnum_id;
- uint64_t arena_offset;
- uint64_t arena_size;
- uint64_t data_hash_table_offset; /* for looking up data objects */
- uint64_t data_hash_table_size;
- uint64_t field_hash_table_offset; /* for looking up field objects */
- uint64_t field_hash_table_size;
- uint64_t tail_object_offset;
- uint64_t n_objects;
- uint64_t n_entries;
- uint64_t seqnum;
- uint64_t first_seqnum;
- uint64_t entry_array_offset;
- uint64_t head_entry_realtime;
- uint64_t tail_entry_realtime;
- uint64_t tail_entry_monotonic;
+ le64_t arena_offset;
+ le64_t arena_size;
+ le64_t data_hash_table_offset; /* for looking up data objects */
+ le64_t data_hash_table_size;
+ le64_t field_hash_table_offset; /* for looking up field objects */
+ le64_t field_hash_table_size;
+ le64_t tail_object_offset;
+ le64_t n_objects;
+ le64_t n_entries;
+ le64_t seqnum;
+ le64_t first_seqnum;
+ le64_t entry_array_offset;
+ le64_t head_entry_realtime;
+ le64_t tail_entry_realtime;
+ le64_t tail_entry_monotonic;
};
#endif
}
static int link_entry_into_array(JournalFile *f,
- uint64_t *first,
- uint64_t *idx,
+ le64_t *first,
+ le64_t *idx,
uint64_t p) {
int r;
uint64_t n = 0, ap = 0, q, i, a, hidx;
}
static int link_entry_into_array_plus_one(JournalFile *f,
- uint64_t *extra,
- uint64_t *first,
- uint64_t *idx,
+ le64_t *extra,
+ le64_t *first,
+ le64_t *idx,
uint64_t p) {
int r;
if (*idx == 0)
*extra = htole64(p);
else {
- uint64_t i;
+ le64_t i;
i = htole64(le64toh(*idx) - 1);
r = link_entry_into_array(f, first, &i, p);
items = alloca(sizeof(EntryItem) * n);
for (i = 0; i < n; i++) {
- uint64_t le_hash, l, h;
+ uint64_t l, h;
+ le64_t le_hash;
size_t t;
void *data;
Object *u;
#include <systemd/sd-id128.h>
+#include "sparse-endian.h"
#include "journal-def.h"
#include "util.h"
struct Match {
char *data;
size_t size;
- uint64_t le_hash;
+ le64_t le_hash;
LIST_FIELDS(Match, matches);
};
p = e + 1;
continue;
} else {
+ le64_t l_le;
uint64_t l;
char *k;
break;
}
- memcpy(&l, e + 1, sizeof(uint64_t));
- l = le64toh(l);
+ memcpy(&l_le, e + 1, sizeof(uint64_t));
+ l = le64toh(l_le);
if (remaining < e - p + 1 + sizeof(uint64_t) + l + 1 ||
e[1+sizeof(uint64_t)+l] != '\n') {
_public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size) {
Match *m, *after = NULL;
- uint64_t le_hash;
+ le64_t le_hash;
if (!j)
return -EINVAL;
Object *c, *d;
uint64_t cp, dp;
- r = journal_file_find_data_object_with_hash(f, m->data, m->size, m->le_hash, &d, &dp);
+ r = journal_file_find_data_object_with_hash(f, m->data, m->size, le64toh(m->le_hash), &d, &dp);
if (r <= 0)
return r;
n = journal_file_entry_n_items(o);
for (i = 0; i < n; i++) {
- uint64_t p, l, le_hash;
+ uint64_t p, l;
+ le64_t le_hash;
size_t t;
p = le64toh(o->entry.items[i].object_offset);
_public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t *size) {
JournalFile *f;
- uint64_t p, l, n, le_hash;
+ uint64_t p, l, n;
+ le64_t le_hash;
int r;
Object *o;
size_t t;
--- /dev/null
+/* Copyright (c) 2012 Josh Triplett <josh@joshtriplett.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#ifndef SPARSE_ENDIAN_H
+#define SPARSE_ENDIAN_H
+
+#include <endian.h>
+#include <stdint.h>
+
+#ifdef __CHECKER__
+#define __bitwise __attribute__((bitwise))
+#define __force __attribute__((force))
+#else
+#define __bitwise
+#define __force
+#endif
+
+typedef uint16_t __bitwise le16_t;
+typedef uint16_t __bitwise be16_t;
+typedef uint32_t __bitwise le32_t;
+typedef uint32_t __bitwise be32_t;
+typedef uint64_t __bitwise le64_t;
+typedef uint64_t __bitwise be64_t;
+
+#undef htobe16
+#undef htole16
+#undef be16toh
+#undef le16toh
+#undef htobe32
+#undef htole32
+#undef be32toh
+#undef le32toh
+#undef htobe64
+#undef htole64
+#undef be64toh
+#undef le64toh
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define bswap_16_on_le(x) __bswap_16(x)
+#define bswap_32_on_le(x) __bswap_32(x)
+#define bswap_64_on_le(x) __bswap_64(x)
+#define bswap_16_on_be(x) (x)
+#define bswap_32_on_be(x) (x)
+#define bswap_64_on_be(x) (x)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define bswap_16_on_le(x) (x)
+#define bswap_32_on_le(x) (x)
+#define bswap_64_on_le(x) (x)
+#define bswap_16_on_be(x) __bswap_16(x)
+#define bswap_32_on_be(x) __bswap_32(x)
+#define bswap_64_on_be(x) __bswap_64(x)
+#endif
+
+static inline le16_t htole16(uint16_t value) { return (le16_t __force) bswap_16_on_be(value); }
+static inline le32_t htole32(uint32_t value) { return (le32_t __force) bswap_32_on_be(value); }
+static inline le64_t htole64(uint64_t value) { return (le64_t __force) bswap_64_on_be(value); }
+
+static inline be16_t htobe16(uint16_t value) { return (be16_t __force) bswap_16_on_le(value); }
+static inline be32_t htobe32(uint32_t value) { return (be32_t __force) bswap_32_on_le(value); }
+static inline be64_t htobe64(uint64_t value) { return (be64_t __force) bswap_64_on_le(value); }
+
+static inline uint16_t le16toh(le16_t value) { return bswap_16_on_be((uint16_t __force)value); }
+static inline uint32_t le32toh(le32_t value) { return bswap_32_on_be((uint32_t __force)value); }
+static inline uint64_t le64toh(le64_t value) { return bswap_64_on_be((uint64_t __force)value); }
+
+static inline uint16_t be16toh(be16_t value) { return bswap_16_on_le((uint16_t __force)value); }
+static inline uint32_t be32toh(be32_t value) { return bswap_32_on_le((uint32_t __force)value); }
+static inline uint64_t be64toh(be64_t value) { return bswap_64_on_le((uint64_t __force)value); }
+
+#endif /* SPARSE_ENDIAN_H */