1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
/* Store I/O
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
This file is part of the GNU Hurd.
The GNU Hurd is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
The GNU Hurd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __STORE_H__
#define __STORE_H__
#include <sys/types.h>
#include <mach.h>
#include <device/device.h>
#include <hurd/hurd_types.h>
struct store
{
/* If this store was created using store_create, the file from which we got
our store. */
file_t source;
/* The type of storage this is (see STORAGE_ in hurd/hurd_types.h). */
enum file_storage_class class;
/* Address ranges in the underlying storage which make up our contiguous
address space. In units of BLOCK_SIZE, below. */
off_t *runs; /* Malloced */
size_t runs_len; /* Length of RUNS. */
/* Maximum valid offset. This is the same as SIZE, but in blocks. */
off_t end;
/* WRAP_SRC is the sum of the run lengths in RUNS. If this is less than
END, then RUNS describes a repeating pattern, of length WRAP_SRC -- each
successive iteration having an additional offset of WRAP_DST. */
off_t wrap_src;
off_t wrap_dst; /* Only meaningful if WRAP_SRC < END */
/* Handles for the underlying storage. */
char *name; /* Malloced */
mach_port_t port; /* Send right */
/* The size of a `block' on this storage. */
size_t block_size;
/* The number of blocks (of size BLOCK_SIZE) in this storage. */
size_t blocks;
/* The number of bytes in this storage, including holes. */
size_t size;
/* Log_2 (BLOCK_SIZE) or 0 if not a power of 2. */
int log2_block_size;
/* Log_2 (VM_PAGE_SIZE / BLOCK_SIZE); only valid if LOG2_BLOCK_SIZE is. */
int log2_blocks_per_page;
void *misc;
struct store_meths *meths;
void *hook; /* Type specific noise. */
};
typedef error_t (*store_write_meth_t)(struct store *store,
off_t addr, size_t index,
char *buf, mach_msg_type_number_t len,
mach_msg_type_number_t *amount);
typedef error_t (*store_read_meth_t)(struct store *store,
off_t addr, size_t index,
mach_msg_type_number_t amount,
char **buf, mach_msg_type_number_t *len);
struct store_meths
{
/* Read up to AMOUNT bytes at the underlying address ADDR from the storage
into BUF and LEN. INDEX varies from 0 to the number of runs in STORE. */
store_read_meth_t read;
/* Write up to LEN bytes from BUF to the storage at the underlying address
ADDR. INDEX varies from 0 to the number of runs in STORE. */
store_write_meth_t write;
/* Called just before deallocating STORE. */
void (*cleanup) (struct store *store);
};
/* Return a new store in STORE, which refers to the storage underlying
SOURCE. A reference to SOURCE is created (but may be destroyed with
store_close_source). */
error_t store_create (file_t source, struct store **store);
/* Return a new store in STORE referring to the mach device DEVICE. Consumes
the send right DEVICE. */
error_t store_device_create (device_t device, struct store **store);
/* Like store_device_create, but doesn't query the device for information. */
error_t _store_device_create (device_t device, size_t block_size,
off_t *runs, size_t runs_len,
struct store **store);
/* Return a new store in STORE referring to the file FILE. Unlike
store_create, this will always use file i/o, even it would be possible to
be more direct. This may work in more cases, for instance if the file has
holes. Consumes the send right FILE. */
error_t store_file_create (file_t file, struct store **store);
/* Like store_file_create, but doesn't query the file for information. */
error_t _store_file_create (file_t file, size_t block_size,
off_t *runs, size_t runs_len,
struct store **store);
/* Return a new store in STORE that interleaves all the stores in STRIPES
(NUM_STRIPES of them) every INTERLEAVE bytes; INTERLEAVE must be an
integer multiple of each stripe's block size. If DEALLOC is true, then
the striped stores are freed when this store is (in any case, the array
STRIPES is copied, and so should be freed by the caller). */
error_t store_ileave_create (struct store **stripes, size_t num_stripes,
int dealloc,
off_t interleave, struct store **store);
/* Return a new store in STORE that concatenates all the stores in STORES
(NUM_STORES of them). If DEALLOC is true, then the sub-stores are freed
when this store is (in any case, the array STORES is copied, and so should
be freed by the caller). */
error_t store_concat_create (struct store **stores, size_t num_stores,
int dealloc, struct store **store);
void store_free (struct store *store);
/* Allocate a new store structure of class CLASS, with meths METHS, and the
various other fields initialized to the given parameters. */
struct store *
_make_store (enum file_storage_class class, struct store_meths *meths,
mach_port_t port, size_t block_size,
off_t *runs, size_t runs_len, off_t end);
/* Set STORE's current runs list to (a copy of) RUNS and RUNS_LEN. */
error_t store_set_runs (struct store *store, off_t *runs, size_t runs_len);
/* Sets the name associated with STORE to a copy of NAME. */
error_t store_set_name (struct store *store, const char *name);
/* Fills in the values of the various fields in STORE that are derivable from
the set of runs & the block size. */
void _store_derive (struct store *store);
/* Write LEN bytes from BUF to STORE at ADDR. Returns the amount written in
AMOUNT (in bytes). ADDR is in BLOCKS (as defined by STORE->block_size). */
error_t store_write (struct store *store,
off_t addr, char *buf, size_t len, size_t *amount);
/* Read AMOUNT bytes from STORE at ADDR into BUF & LEN (which following the
usual mach buffer-return semantics) to STORE at ADDR. ADDR is in BLOCKS
(as defined by STORE->block_size). Note that LEN is in bytes. */
error_t store_read (struct store *store,
off_t addr, size_t amount, char **buf, size_t *len);
/* If STORE was created using store_create, remove the reference to the
source from which it was created. */
void store_close_source (struct store *store);
#if 0
/* Return a memory object paging on STORE. [among other reasons,] this may
fail because store contains non-contiguous regions on the underlying
object. In such a case you can try calling some of the routines below to
get a pager. */
error_t store_map (struct store *store, vm_prot_t prot, ...,
mach_port_t *pager);
/* Returns a memory object paging on the file from which STORE was created.
If STORE wasn't created using store_create, or the source was destroyed
using store_close_source, this will fail. */
error_t store_map_source (struct store *store, vm_prot_t prot, ...,
mach_port_t *pager)
/* Create a new pager and paging threads paging on STORE, and return the
resulting memory object in PAGER. */
error_t store_create_pager (struct store *store, vm_prot_t prot, ...,
mach_port_t *pager)
#endif
/* Encode/decode table:
4 vectors are used: ports, ints, offsets (off_t), and data (char);
each type of store uses the following entries in each vector:
-type- -ports- -ints- -offsets- -data- -kids-
device DEVICE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
file FILE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
memory MEMOBJ TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
task TASK TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
(the data for the above is a name (incl '\0') and a misc data block)
null - TY, FL LEN - -
(BS is 1)
ileave - TY, FL, IL, NC - - NC
(BS is the LCM of its children; LEN is the minimum of theirs * IL)
concat - TY, FL, NC - - NC
(BS is the LCM of its children; LEN is the sum of theirs)
layer - TY, FL, NC - - NC
(BS is the LCM of its children; LEN is the minimum of theirs)
For ileave, concat, and layer, the children are encoded following the parent.
key: TY = type code, FL = flags, BS = block size, NR = num runs,
NL = name len, ML = misc len, NC = num children,
IL = interleave (bytes),
LEN = run length (blocks), OFFS = run offset (blocks),
*/
/* Encode STORE into the given arrays, suitable for passing back using
file_get_storage_info. */
error_t store_encode (const struct store *store,
mach_port_t **ports, mach_msg_type_number_t *ports_len,
int **ints, mach_msg_type_number_t *ints_len,
off_t **offsets, mach_msg_type_number_t *offsets_len,
char **data, mach_msg_type_number_t *data_len);
/* Decode the given arrays, as fetched using file_get_storage_info, and
either create a new store from them, which return in STORE, or return an
error. */
error_t store_decode (mach_port_t *ports, mach_msg_type_number_t ports_len,
int *ints, mach_msg_type_number_t ints_len,
off_t *offsets, mach_msg_type_number_t offsets_len,
char *data, mach_msg_type_number_t data_len,
struct store **store);
#endif /* __STORE_H__ */
|