Download
jcs
/amend
/bile.h
(View History)
jcs *: Lots of little fixes and dead variable removal | Latest amendment: 110 on 2023-02-06 |
1 | /* |
2 | * Copyright (c) 2022 joshua stein <jcs@jcs.org> |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above |
6 | * copyright notice and this permission notice appear in all copies. |
7 | * |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ |
16 | |
17 | #ifndef __BILE_H__ |
18 | #define __BILE_H__ |
19 | |
20 | #include "util.h" |
21 | |
22 | /* |
23 | * File format: |
24 | * [ bile header - BILE_HEADER_LEN ] |
25 | * [ BILE_MAGIC - BILE_MAGIC_LEN ] |
26 | * [ map pointer object ] |
27 | * [ pointer position - long ] |
28 | * [ pointer size - long ] |
29 | * [ pointer type (_BL>) - long ] |
30 | * [ pointer id - long ] |
31 | * [ previous map pointer object ] |
32 | * [ pointer position - long ] |
33 | * [ pointer size - long ] |
34 | * [ pointer type (_BL>) - long ] |
35 | * [ pointer id - long ] |
36 | * [ padding for future use ] |
37 | * [ object[0] start (map points to this as its position) ] |
38 | * [ object[0] position - long ] |
39 | * [ object[0] size - long ] |
40 | * [ object[0] type - long ] |
41 | * [ object[0] id - long ] |
42 | * [ object[1] start ] |
43 | * [ .. ] |
44 | * [ map object - (pointed to by map pointer position) ] |
45 | * [ map position - long ] |
46 | * [ map size - long ] |
47 | * [ map type (_BLM) - long ] |
48 | * [ map id - long ] |
49 | * [ map contents ] |
50 | */ |
51 | #define BILE_MAGIC "BILE2" |
52 | #define BILE_MAGIC_LEN 5 |
53 | #define BILE_TYPE_MAP '_BLM' |
54 | #define BILE_TYPE_MAPPTR '_BL>' |
55 | #define BILE_TYPE_PURGE '_BLP' |
56 | #define BILE_TYPE_HIGHESTID '_BLH' |
57 | |
58 | struct bile_object { |
59 | unsigned long pos; |
60 | unsigned long size; |
61 | OSType type; |
62 | unsigned long id; |
63 | }; |
64 | #define BILE_OBJECT_SIZE (sizeof(struct bile_object)) |
65 | #define BILE_HEADER_LEN 256 |
66 | |
67 | /* allocate filesystem space in chunks of this */ |
68 | #define BILE_ALLOCATE_SIZE 8192 |
69 | |
70 | #ifndef BILE1_MAGIC |
71 | #define BILE1_MAGIC "BILE1" |
72 | #endif |
73 | #ifndef BILE1_MAGIC_LEN |
74 | #define BILE1_MAGIC_LEN 5 |
75 | #endif |
76 | |
77 | #define BILE_ERR_NEED_UPGRADE_1 -4000 |
78 | #define BILE_ERR_BOGUS_OBJECT -4001 |
79 | |
80 | struct bile_highest_id { |
81 | OSType type; |
82 | unsigned long highest_id; |
83 | }; |
84 | |
85 | struct bile { |
86 | struct bile_object map_ptr; |
87 | struct bile_object old_map_ptr; |
88 | short vrefnum, frefnum, last_error; |
89 | Str255 filename; |
90 | size_t file_size; |
91 | struct bile_object *map; /* array of bile_objects */ |
92 | size_t nobjects; |
93 | char magic[5]; |
94 | }; |
95 | |
96 | struct bile_object_field { |
97 | size_t struct_off; |
98 | ssize_t size; |
99 | size_t object_len_off; |
100 | }; |
101 | |
102 | short bile_error(struct bile *bile); |
103 | |
104 | struct bile * bile_create(const Str255 filename, short vrefnum, |
105 | const OSType creator, const OSType type); |
106 | struct bile * bile_open(const Str255 filename, short vrefnum); |
107 | struct bile * bile_open_recover_map(const Str255 filename, |
108 | short vrefnum); |
109 | short bile_flush(struct bile *bile, bool and_vol); |
110 | void bile_close(struct bile *bile); |
111 | |
112 | struct bile_object * bile_find(struct bile *bile, const OSType type, |
113 | const unsigned long id); |
114 | size_t bile_count_by_type(struct bile *bile, |
115 | const OSType type); |
116 | size_t bile_sorted_ids_by_type(struct bile *bile, |
117 | const OSType type, unsigned long **ret); |
118 | struct bile_object * bile_get_nth_of_type(struct bile *bile, |
119 | const unsigned long index, const OSType type); |
120 | unsigned long bile_next_id(struct bile *bile, const OSType type); |
121 | short bile_delete(struct bile *bile, const OSType type, |
122 | const unsigned long id); |
123 | size_t bile_read_object(struct bile *bile, |
124 | const struct bile_object *o, void *data, |
125 | const size_t len); |
126 | size_t bile_read(struct bile *bile, const OSType type, |
127 | const unsigned long id, void *data, |
128 | const size_t len); |
129 | size_t bile_read_alloc(struct bile *bile, |
130 | const OSType type, const unsigned long id, |
131 | void *data_ptr); |
132 | size_t bile_write(struct bile *bile, OSType type, |
133 | const unsigned long id, const void *data, |
134 | const size_t len); |
135 | short bile_verify(struct bile *bile); |
136 | |
137 | short bile_marshall_object(struct bile *bile, |
138 | const struct bile_object_field *fields, |
139 | const size_t nfields, void *object, |
140 | void *ret_ptr, size_t *ret_size, char *note); |
141 | short bile_unmarshall_object(struct bile *bile, |
142 | const struct bile_object_field *fields, |
143 | const size_t nfields, const void *data, |
144 | const size_t data_size, void *object, |
145 | const size_t object_size, bool deep, char *note); |
146 | |
147 | #endif |