cleanup load_blocks: make the common error path more visible
[hed.git] / libhed / types.h
blob6c1bb570769bbacbdce4858a271146188336995c
1 /* Basic libhed data types */
3 /* This is a libhed PUBLIC file.
4 * This header file will be installed on the target system.
5 * When you add new things here, make sure they start with hed_.
6 */
8 /*
9 * hed - Hexadecimal editor
10 * Copyright (C) 2012 Petr Tesarik <petr@tesarici.cz>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef LIBHED__TYPES_H
27 #define LIBHED__TYPES_H
29 #include <libhed/config.h>
31 /*******************************************************************
32 * UNSIGNED OFFSET TYPE
35 #include <stdint.h>
37 /* If LFS is requested, define all offset types as 64-bit integers,
38 * otherwise use the default size for the architecture
40 #ifdef HED_CONFIG_LFS
41 typedef int64_t hed_off_t;
42 typedef uint64_t hed_uoff_t;
43 #else
44 typedef signed long int hed_off_t;
45 typedef unsigned long int hed_uoff_t;
46 #endif
48 /*******************************************************************
49 * DOUBLY LINKED LIST
52 struct hed_list_head {
53 struct hed_list_head *next, *prev;
56 /*******************************************************************
57 * FILE TREE
60 struct hed_tree_node {
61 /* Used for the linked list */
62 struct hed_list_head link;
63 /* Can be the null node for the root. */
64 struct hed_tree_node *up;
65 /* Both can be the null node for leaves. */
66 struct hed_tree_node *left;
67 struct hed_tree_node *right;
68 /* Size of the entry. (This is public.) */
69 hed_uoff_t size;
70 /* Size of the entry plus its children. (Private.) */
71 hed_uoff_t cover_size;
74 /*******************************************************************
75 * BLOCK DATA
78 /* This is the block data descriptor
79 * The usage of some fields is not self-evident:
81 * @size ALWAYS denotes the number of bytes which can fit
82 * into @data
84 * @data may be embedded inside the hed_block_data object,
85 * detached in a dynamically allocated array,
86 * or unmaintained (for cached blocks with HED_CONFIG_MMAP)
88 * Some additional notes:
89 * - @data is always allocated for out-of-cache objects
91 struct hed_block_data {
92 size_t size; /* size of data */
93 void *data;
95 union {
96 struct hed_list_head free; /* free list */
97 struct {
98 int refcount; /* reference count */
99 int flags; /* flags (see HED_FDF_* below) */
100 } used;
101 } u2;
104 #define HED_FDF_CACHED 1 /* Allocated from cache */
106 #endif /* LIBHED__TYPES_H */