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 * Note that REV is only used to construct nicer error objects that
71 * mention this revision. Allocate the checksums in RESULT_POOL.
74 svn_fs_fs__parse_footer(apr_off_t *l2p_offset,
75 svn_checksum_t **l2p_checksum,
76 apr_off_t *p2l_offset,
77 svn_checksum_t **p2l_checksum,
78 svn_stringbuf_t *footer,
80 apr_pool_t *result_pool);
82 /* Given the offset of the L2P index data in L2P_OFFSET, the content
83 * checksum in L2P_CHECKSUM and the offset plus checksum of the P2L
84 * index data in P2L_OFFSET and P2L_CHECKSUM.
86 * Return the corresponding format 7+ revision / pack file footer.
87 * Allocate it in RESULT_POOL and use SCRATCH_POOL for temporary.
90 svn_fs_fs__unparse_footer(apr_off_t l2p_offset,
91 svn_checksum_t *l2p_checksum,
93 svn_checksum_t *p2l_checksum,
94 apr_pool_t *result_pool,
95 apr_pool_t *scratch_pool);
97 /* Read all the changes from STREAM and store them in *CHANGES,
98 allocated in RESULT_POOL. Do temporary allocations in SCRATCH_POOL. */
100 svn_fs_fs__read_changes(apr_array_header_t **changes,
101 svn_stream_t *stream,
102 apr_pool_t *result_pool,
103 apr_pool_t *scratch_pool);
105 /* Callback function used by svn_fs_fs__read_changes_incrementally(),
106 * asking the receiver to process to process CHANGE using BATON. CHANGE
107 * and SCRATCH_POOL will not be valid beyond the current callback invocation.
109 typedef svn_error_t *(*svn_fs_fs__change_receiver_t)(
112 apr_pool_t *scratch_pool);
114 /* Read all the changes from STREAM and invoke CHANGE_RECEIVER on each change.
115 Do all allocations in SCRATCH_POOL. */
117 svn_fs_fs__read_changes_incrementally(svn_stream_t *stream,
118 svn_fs_fs__change_receiver_t
120 void *change_receiver_baton,
121 apr_pool_t *scratch_pool);
123 /* Write the changed path info from CHANGES in filesystem FS to the
124 output stream STREAM. You may call this function multiple time on
125 the same stream. If you are writing to a (proto-)revision file,
126 the last call must set TERMINATE_LIST to write an extra empty line
127 that marks the end of the changed paths list.
128 Perform temporary allocations in SCRATCH_POOL.
131 svn_fs_fs__write_changes(svn_stream_t *stream,
134 svn_boolean_t terminate_list,
135 apr_pool_t *scratch_pool);
137 /* Read a node-revision from STREAM. Set *NODEREV to the new structure,
138 allocated in RESULT_POOL. */
140 svn_fs_fs__read_noderev(node_revision_t **noderev,
141 svn_stream_t *stream,
142 apr_pool_t *result_pool,
143 apr_pool_t *scratch_pool);
145 /* Write the node-revision NODEREV into the stream OUTFILE, compatible with
146 filesystem format FORMAT. Only write mergeinfo-related metadata if
147 INCLUDE_MERGEINFO is true. Temporary allocations are from SCRATCH_POOL. */
149 svn_fs_fs__write_noderev(svn_stream_t *outfile,
150 node_revision_t *noderev,
152 svn_boolean_t include_mergeinfo,
153 apr_pool_t *scratch_pool);
155 /* Parse the description of a representation from TEXT and store it
156 into *REP_P. TEXT will be invalidated by this call. Allocate *REP_P in
157 RESULT_POOL and use SCRATCH_POOL for temporaries. */
159 svn_fs_fs__parse_representation(representation_t **rep_p,
160 svn_stringbuf_t *text,
161 apr_pool_t *result_pool,
162 apr_pool_t *scratch_pool);
164 /* Return a formatted string, compatible with filesystem format FORMAT,
165 that represents the location of representation REP. If
166 MUTABLE_REP_TRUNCATED is given, the rep is for props or dir contents,
167 and only a "-1" revision number will be given for a mutable rep.
168 If MAY_BE_CORRUPT is true, guard for NULL when constructing the string.
169 Allocate the result in RESULT_POOL and temporaries in SCRATCH_POOL. */
171 svn_fs_fs__unparse_representation(representation_t *rep,
173 svn_boolean_t mutable_rep_truncated,
174 apr_pool_t *result_pool,
175 apr_pool_t *scratch_pool);
177 /* This type enumerates all forms of representations that we support. */
178 typedef enum svn_fs_fs__rep_type_t
180 /* this is a PLAIN representation */
181 svn_fs_fs__rep_plain,
183 /* this is a DELTA representation with no base representation */
184 svn_fs_fs__rep_self_delta,
186 /* this is a DELTA representation against some base representation */
188 } svn_fs_fs__rep_type_t;
190 /* This structure is used to hold the information stored in a representation
192 typedef struct svn_fs_fs__rep_header_t
194 /* type of the representation, i.e. whether it is PLAIN, self-DELTA etc. */
195 svn_fs_fs__rep_type_t type;
197 /* if this rep is a delta against some other rep, that base rep can
198 * be found in this revision. Should be 0 if there is no base rep. */
199 svn_revnum_t base_revision;
201 /* if this rep is a delta against some other rep, that base rep can
202 * be found at this item index within the base rep's revision. Should
203 * be 0 if there is no base rep. */
204 apr_off_t base_item_index;
206 /* if this rep is a delta against some other rep, this is the (deltified)
207 * size of that base rep. Should be 0 if there is no base rep. */
208 svn_filesize_t base_length;
210 /* length of the textual representation of the header in the rep or pack
211 * file, including EOL. Only valid after reading it from disk.
212 * Should be 0 otherwise. */
213 apr_size_t header_size;
214 } svn_fs_fs__rep_header_t;
216 /* Read the next line from STREAM and parse it as a text
217 representation header. Return the parsed entry in *HEADER, allocated
218 in RESULT_POOL. Perform temporary allocations in SCRATCH_POOL. */
220 svn_fs_fs__read_rep_header(svn_fs_fs__rep_header_t **header,
221 svn_stream_t *stream,
222 apr_pool_t *result_pool,
223 apr_pool_t *scratch_pool);
225 /* Write the representation HEADER to STREAM.
226 * Use SCRATCH_POOL for temporary allocations. */
228 svn_fs_fs__write_rep_header(svn_fs_fs__rep_header_t *header,
229 svn_stream_t *stream,
230 apr_pool_t *scratch_pool);