rev_file.h revision 362181
1/* rev_file.h --- revision file and index access data structure
2 *
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
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
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
19 *    under the License.
20 * ====================================================================
21 */
22
23#ifndef SVN_LIBSVN_FS_X__REV_FILE_H
24#define SVN_LIBSVN_FS_X__REV_FILE_H
25
26#include "svn_fs.h"
27#include "id.h"
28
29/* In FSX, index data must be read in sync with the respective revision /
30 * pack file.  I.e. we must use packed index files for packed rev files and
31 * unpacked ones for non-packed rev files.  So, the whole point is to open
32 * them with matching "is packed" setting in case some background pack
33 * process was run.
34 *
35 * Another thing that this allows us is to lazily open the file, i.e. open
36 * it upon first access.
37 */
38
39/* Opaque index stream type.
40 */
41typedef struct svn_fs_x__packed_number_stream_t
42  svn_fs_x__packed_number_stream_t;
43
44/* Location and content meta data for an index. */
45typedef struct svn_fs_x__index_info_t
46{
47  /* Offset within the pack / rev file at which the index data starts. */
48  apr_off_t start;
49
50  /* First offset behind the index data. */
51  apr_off_t end;
52
53  /* MD5 checksum on the whole on-disk representation of the index. */
54  svn_checksum_t *checksum;
55
56} svn_fs_x__index_info_t;
57
58/* Location and content meta data for a revision / pack file. */
59typedef struct svn_fs_x__rev_file_info_t
60{
61  /* first (potentially only) revision in the rev / pack file.
62   * SVN_INVALID_REVNUM for txn proto-rev files. */
63  svn_revnum_t start_revision;
64
65  /* the revision was packed when the first file / stream got opened */
66  svn_boolean_t is_packed;
67
68} svn_fs_x__rev_file_info_t;
69
70/* Data file, including indexes data, and associated properties for
71 * START_REVISION.  As the FILE is kept open, background pack operations
72 * will not cause access to this file to fail.
73 */
74typedef struct svn_fs_x__revision_file_t svn_fs_x__revision_file_t;
75
76/* Initialize the revision / pack file access structure in *FILE for reading
77 * revision REV from filesystem FS.  The file will not be opened until the
78 * first call to any of the access functions.
79 *
80 * Allocate *FILE in RESULT_POOL. */
81svn_error_t *
82svn_fs_x__rev_file_init(svn_fs_x__revision_file_t **file,
83                        svn_fs_t *fs,
84                        svn_revnum_t rev,
85                        apr_pool_t *result_pool);
86
87/* Open the correct revision file for REV with read and write access.
88 * If necessary, temporarily reset the file's read-only state.  If the
89 * filesystem FS has been packed, *FILE will be set to the packed file;
90 * otherwise, set *FILE to the revision file for REV.
91 *
92 * Return SVN_ERR_FS_NO_SUCH_REVISION if the file doesn't exist.
93 * Allocate *FILE in RESULT_POOL and use SCRATCH_POOLfor temporaries. */
94svn_error_t *
95svn_fs_x__rev_file_open_writable(svn_fs_x__revision_file_t **file,
96                                 svn_fs_t *fs,
97                                 svn_revnum_t rev,
98                                 apr_pool_t *result_pool,
99                                 apr_pool_t *scratch_pool);
100
101/* Open the proto-rev file of transaction TXN_ID in FS and return it in *FILE.
102 * Allocate *FILE in RESULT_POOL use and SCRATCH_POOL for temporaries.. */
103svn_error_t *
104svn_fs_x__rev_file_open_proto_rev(svn_fs_x__revision_file_t **file,
105                                  svn_fs_t *fs,
106                                  svn_fs_x__txn_id_t txn_id,
107                                  apr_pool_t* result_pool,
108                                  apr_pool_t *scratch_pool);
109
110/* Wrap the TEMP_FILE, used in the context of FS, into a revision file
111 * struct, allocated in RESULT_POOL, and return it in *FILE.
112 */
113svn_error_t *
114svn_fs_x__rev_file_wrap_temp(svn_fs_x__revision_file_t **file,
115                             svn_fs_t *fs,
116                             apr_file_t *temp_file,
117                             apr_pool_t *result_pool);
118
119/* Access functions */
120
121/* Copy the L2P index info for FILE into *INFO.
122 */
123svn_error_t *
124svn_fs_x__rev_file_info(svn_fs_x__rev_file_info_t *info,
125                        svn_fs_x__revision_file_t *file);
126
127/* Convenience wrapper around svn_io_file_name_get. */
128svn_error_t *
129svn_fs_x__rev_file_name(const char **filename,
130                        svn_fs_x__revision_file_t *file,
131                        apr_pool_t *result_pool);
132
133/* Set *STREAM to the shared stream object of FILE.
134 */
135svn_error_t *
136svn_fs_x__rev_file_stream(svn_stream_t **stream,
137                          svn_fs_x__revision_file_t *file);
138
139/* Set *APR_FILE to the shared file object of FILE.
140 */
141svn_error_t *
142svn_fs_x__rev_file_get(apr_file_t **apr_file,
143                       svn_fs_x__revision_file_t *file);
144
145/* Set *STREAM to the shared L2P data stream of FILE.
146 */
147svn_error_t *
148svn_fs_x__rev_file_l2p_index(svn_fs_x__packed_number_stream_t **stream,
149                             svn_fs_x__revision_file_t *file);
150
151/* Set *STREAM to the shared P2L data stream of FILE.
152 */
153svn_error_t *
154svn_fs_x__rev_file_p2l_index(svn_fs_x__packed_number_stream_t **stream,
155                             svn_fs_x__revision_file_t *file);
156
157/* Copy the L2P index info for FILE into *INFO.
158 */
159svn_error_t *
160svn_fs_x__rev_file_l2p_info(svn_fs_x__index_info_t *info,
161                            svn_fs_x__revision_file_t *file);
162
163/* Copy the P2L index info for FILE into *INFO.
164 */
165svn_error_t *
166svn_fs_x__rev_file_p2l_info(svn_fs_x__index_info_t *info,
167                            svn_fs_x__revision_file_t *file);
168
169/* Set *SIZE to the length of the revision data in FILE.
170 */
171svn_error_t *
172svn_fs_x__rev_file_data_size(svn_filesize_t *size,
173                             svn_fs_x__revision_file_t *file);
174
175/* File manipulation. */
176
177/* Convenience wrapper around svn_io_file_aligned_seek. */
178svn_error_t *
179svn_fs_x__rev_file_seek(svn_fs_x__revision_file_t *file,
180                        apr_off_t *buffer_start,
181                        apr_off_t offset);
182
183/* Convenience wrapper around svn_fs_x__get_file_offset. */
184svn_error_t *
185svn_fs_x__rev_file_offset(apr_off_t *offset,
186                          svn_fs_x__revision_file_t *file);
187
188/* Convenience wrapper around svn_io_file_read_full2. */
189svn_error_t *
190svn_fs_x__rev_file_read(svn_fs_x__revision_file_t *file,
191                        void *buf,
192                        apr_size_t nbytes);
193
194/* Close all files and streams in FILE.  They will be reopened automatically
195 * by any of the above access functions.
196 */
197svn_error_t *
198svn_fs_x__close_revision_file(svn_fs_x__revision_file_t *file);
199
200#endif
201