1 /* low_level.c --- low level r/w access to fs_fs file structures
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
28 /* Kinds that a node-rev can be. */
29 #define SVN_FS_FS__KIND_FILE "file"
30 #define SVN_FS_FS__KIND_DIR "dir"
32 /* The functions are grouped as follows:
34 * - revision trailer (up to format 6)
35 * - revision footer (since format 7)
38 * - representation (as in "text:" and "props:" lines)
39 * - representation header ("PLAIN" and "DELTA" lines)
42 /* Given the last "few" bytes (should be at least 40) of revision REV in
43 * TRAILER, parse the last line and return the offset of the root noderev
44 * in *ROOT_OFFSET and the offset of the changed paths list in
45 * *CHANGES_OFFSET. Offsets are relative to the revision's start offset.
46 * ROOT_OFFSET and / or CHANGES_OFFSET may be NULL.
48 * Note that REV is only used to construct nicer error objects.
51 svn_fs_fs__parse_revision_trailer(apr_off_t *root_offset,
52 apr_off_t *changes_offset,
53 svn_stringbuf_t *trailer,
56 /* Given the offset of the root noderev in ROOT_OFFSET and the offset of
57 * the changed paths list in CHANGES_OFFSET, return the corresponding
58 * revision's trailer. Allocate it in RESULT_POOL.
61 svn_fs_fs__unparse_revision_trailer(apr_off_t root_offset,
62 apr_off_t changes_offset,
63 apr_pool_t *result_pool);
65 /* Given the format 7+ revision / pack FOOTER, parse it destructively
66 * and return the start offsets of the index data in *L2P_OFFSET and
67 * *P2L_OFFSET, respectively. Also, return the expected checksums in
68 * in *L2P_CHECKSUM and *P2L_CHECKSUM.
70 * FOOTER_OFFSET is used for validation.
72 * Note that REV is only used to construct nicer error objects that
73 * mention this revision. Allocate the checksums in RESULT_POOL.
76 svn_fs_fs__parse_footer(apr_off_t *l2p_offset,
77 svn_checksum_t **l2p_checksum,
78 apr_off_t *p2l_offset,
79 svn_checksum_t **p2l_checksum,
80 svn_stringbuf_t *footer,
82 apr_off_t footer_offset,
83 apr_pool_t *result_pool);
85 /* Given the offset of the L2P index data in L2P_OFFSET, the content
86 * checksum in L2P_CHECKSUM and the offset plus checksum of the P2L
87 * index data in P2L_OFFSET and P2L_CHECKSUM.
89 * Return the corresponding format 7+ revision / pack file footer.
90 * Allocate it in RESULT_POOL and use SCRATCH_POOL for temporary.
93 svn_fs_fs__unparse_footer(apr_off_t l2p_offset,
94 svn_checksum_t *l2p_checksum,
96 svn_checksum_t *p2l_checksum,
97 apr_pool_t *result_pool,
98 apr_pool_t *scratch_pool);
100 /* Read up to MAX_COUNT of the changes from STREAM and store them in
101 *CHANGES, allocated in RESULT_POOL. Do temporary allocations in
104 svn_fs_fs__read_changes(apr_array_header_t **changes,
105 svn_stream_t *stream,
107 apr_pool_t *result_pool,
108 apr_pool_t *scratch_pool);
110 /* Callback function used by svn_fs_fs__read_changes_incrementally(),
111 * asking the receiver to process to process CHANGE using BATON. CHANGE
112 * and SCRATCH_POOL will not be valid beyond the current callback invocation.
114 typedef svn_error_t *(*svn_fs_fs__change_receiver_t)(
117 apr_pool_t *scratch_pool);
119 /* Read all the changes from STREAM and invoke CHANGE_RECEIVER on each change.
120 Do all allocations in SCRATCH_POOL. */
122 svn_fs_fs__read_changes_incrementally(svn_stream_t *stream,
123 svn_fs_fs__change_receiver_t
125 void *change_receiver_baton,
126 apr_pool_t *scratch_pool);
128 /* Write the changed path info from CHANGES in filesystem FS to the
129 output stream STREAM. You may call this function multiple time on
130 the same stream. If you are writing to a (proto-)revision file,
131 the last call must set TERMINATE_LIST to write an extra empty line
132 that marks the end of the changed paths list.
133 Perform temporary allocations in SCRATCH_POOL.
136 svn_fs_fs__write_changes(svn_stream_t *stream,
139 svn_boolean_t terminate_list,
140 apr_pool_t *scratch_pool);
142 /* Read a node-revision from STREAM. Set *NODEREV to the new structure,
143 allocated in RESULT_POOL. */
145 svn_fs_fs__read_noderev(node_revision_t **noderev,
146 svn_stream_t *stream,
147 apr_pool_t *result_pool,
148 apr_pool_t *scratch_pool);
150 /* Write the node-revision NODEREV into the stream OUTFILE, compatible with
151 filesystem format FORMAT. Only write mergeinfo-related metadata if
152 INCLUDE_MERGEINFO is true. Temporary allocations are from SCRATCH_POOL. */
154 svn_fs_fs__write_noderev(svn_stream_t *outfile,
155 node_revision_t *noderev,
157 svn_boolean_t include_mergeinfo,
158 apr_pool_t *scratch_pool);
160 /* Parse the description of a representation from TEXT and store it
161 into *REP_P. TEXT will be invalidated by this call. Allocate *REP_P in
162 RESULT_POOL and use SCRATCH_POOL for temporaries. */
164 svn_fs_fs__parse_representation(representation_t **rep_p,
165 svn_stringbuf_t *text,
166 apr_pool_t *result_pool,
167 apr_pool_t *scratch_pool);
169 /* Return a formatted string, compatible with filesystem format FORMAT,
170 that represents the location of representation REP. If
171 MUTABLE_REP_TRUNCATED is given, the rep is for props or dir contents,
172 and only a "-1" revision number will be given for a mutable rep.
173 If MAY_BE_CORRUPT is true, guard for NULL when constructing the string.
174 Allocate the result in RESULT_POOL and temporaries in SCRATCH_POOL. */
176 svn_fs_fs__unparse_representation(representation_t *rep,
178 svn_boolean_t mutable_rep_truncated,
179 apr_pool_t *result_pool,
180 apr_pool_t *scratch_pool);
182 /* This type enumerates all forms of representations that we support. */
183 typedef enum svn_fs_fs__rep_type_t
185 /* this is a PLAIN representation */
186 svn_fs_fs__rep_plain,
188 /* this is a DELTA representation with no base representation */
189 svn_fs_fs__rep_self_delta,
191 /* this is a DELTA representation against some base representation */
193 } svn_fs_fs__rep_type_t;
195 /* This structure is used to hold the information stored in a representation
197 typedef struct svn_fs_fs__rep_header_t
199 /* type of the representation, i.e. whether it is PLAIN, self-DELTA etc. */
200 svn_fs_fs__rep_type_t type;
202 /* if this rep is a delta against some other rep, that base rep can
203 * be found in this revision. Should be 0 if there is no base rep. */
204 svn_revnum_t base_revision;
206 /* if this rep is a delta against some other rep, that base rep can
207 * be found at this item index within the base rep's revision. Should
208 * be 0 if there is no base rep. */
209 apr_off_t base_item_index;
211 /* if this rep is a delta against some other rep, this is the (deltified)
212 * size of that base rep. Should be 0 if there is no base rep. */
213 svn_filesize_t base_length;
215 /* length of the textual representation of the header in the rep or pack
216 * file, including EOL. Only valid after reading it from disk.
217 * Should be 0 otherwise. */
218 apr_size_t header_size;
219 } svn_fs_fs__rep_header_t;
221 /* Read the next line from STREAM and parse it as a text
222 representation header. Return the parsed entry in *HEADER, allocated
223 in RESULT_POOL. Perform temporary allocations in SCRATCH_POOL. */
225 svn_fs_fs__read_rep_header(svn_fs_fs__rep_header_t **header,
226 svn_stream_t *stream,
227 apr_pool_t *result_pool,
228 apr_pool_t *scratch_pool);
230 /* Write the representation HEADER to STREAM.
231 * Use SCRATCH_POOL for temporary allocations. */
233 svn_fs_fs__write_rep_header(svn_fs_fs__rep_header_t *header,
234 svn_stream_t *stream,
235 apr_pool_t *scratch_pool);