1289177Speter/* rev_file.h --- revision file and index access data structure
2289177Speter *
3289177Speter * ====================================================================
4289177Speter *    Licensed to the Apache Software Foundation (ASF) under one
5289177Speter *    or more contributor license agreements.  See the NOTICE file
6289177Speter *    distributed with this work for additional information
7289177Speter *    regarding copyright ownership.  The ASF licenses this file
8289177Speter *    to you under the Apache License, Version 2.0 (the
9289177Speter *    "License"); you may not use this file except in compliance
10289177Speter *    with the License.  You may obtain a copy of the License at
11289177Speter *
12289177Speter *      http://www.apache.org/licenses/LICENSE-2.0
13289177Speter *
14289177Speter *    Unless required by applicable law or agreed to in writing,
15289177Speter *    software distributed under the License is distributed on an
16289177Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17289177Speter *    KIND, either express or implied.  See the License for the
18289177Speter *    specific language governing permissions and limitations
19289177Speter *    under the License.
20289177Speter * ====================================================================
21289177Speter */
22289177Speter
23289177Speter#ifndef SVN_LIBSVN_FS_X__REV_FILE_H
24289177Speter#define SVN_LIBSVN_FS_X__REV_FILE_H
25289177Speter
26289177Speter#include "svn_fs.h"
27289177Speter#include "id.h"
28289177Speter
29362181Sdim/* In FSX, index data must be read in sync with the respective revision /
30362181Sdim * pack file.  I.e. we must use packed index files for packed rev files and
31362181Sdim * unpacked ones for non-packed rev files.  So, the whole point is to open
32362181Sdim * them with matching "is packed" setting in case some background pack
33362181Sdim * process was run.
34362181Sdim *
35362181Sdim * Another thing that this allows us is to lazily open the file, i.e. open
36362181Sdim * it upon first access.
37289177Speter */
38289177Speter
39289177Speter/* Opaque index stream type.
40289177Speter */
41289177Spetertypedef struct svn_fs_x__packed_number_stream_t
42289177Speter  svn_fs_x__packed_number_stream_t;
43289177Speter
44362181Sdim/* Location and content meta data for an index. */
45362181Sdimtypedef struct svn_fs_x__index_info_t
46289177Speter{
47362181Sdim  /* Offset within the pack / rev file at which the index data starts. */
48362181Sdim  apr_off_t start;
49362181Sdim
50362181Sdim  /* First offset behind the index data. */
51362181Sdim  apr_off_t end;
52362181Sdim
53362181Sdim  /* MD5 checksum on the whole on-disk representation of the index. */
54362181Sdim  svn_checksum_t *checksum;
55362181Sdim
56362181Sdim} svn_fs_x__index_info_t;
57362181Sdim
58362181Sdim/* Location and content meta data for a revision / pack file. */
59362181Sdimtypedef struct svn_fs_x__rev_file_info_t
60362181Sdim{
61289177Speter  /* first (potentially only) revision in the rev / pack file.
62289177Speter   * SVN_INVALID_REVNUM for txn proto-rev files. */
63289177Speter  svn_revnum_t start_revision;
64289177Speter
65289177Speter  /* the revision was packed when the first file / stream got opened */
66289177Speter  svn_boolean_t is_packed;
67289177Speter
68362181Sdim} svn_fs_x__rev_file_info_t;
69289177Speter
70362181Sdim/* Data file, including indexes data, and associated properties for
71362181Sdim * START_REVISION.  As the FILE is kept open, background pack operations
72362181Sdim * will not cause access to this file to fail.
73362181Sdim */
74362181Sdimtypedef struct svn_fs_x__revision_file_t svn_fs_x__revision_file_t;
75289177Speter
76362181Sdim/* Initialize the revision / pack file access structure in *FILE for reading
77362181Sdim * revision REV from filesystem FS.  The file will not be opened until the
78362181Sdim * first call to any of the access functions.
79362181Sdim *
80362181Sdim * Allocate *FILE in RESULT_POOL. */
81289177Spetersvn_error_t *
82362181Sdimsvn_fs_x__rev_file_init(svn_fs_x__revision_file_t **file,
83362181Sdim                        svn_fs_t *fs,
84362181Sdim                        svn_revnum_t rev,
85362181Sdim                        apr_pool_t *result_pool);
86289177Speter
87289177Speter/* Open the correct revision file for REV with read and write access.
88289177Speter * If necessary, temporarily reset the file's read-only state.  If the
89289177Speter * filesystem FS has been packed, *FILE will be set to the packed file;
90289177Speter * otherwise, set *FILE to the revision file for REV.
91289177Speter *
92289177Speter * Return SVN_ERR_FS_NO_SUCH_REVISION if the file doesn't exist.
93289177Speter * Allocate *FILE in RESULT_POOL and use SCRATCH_POOLfor temporaries. */
94289177Spetersvn_error_t *
95362181Sdimsvn_fs_x__rev_file_open_writable(svn_fs_x__revision_file_t **file,
96362181Sdim                                 svn_fs_t *fs,
97362181Sdim                                 svn_revnum_t rev,
98362181Sdim                                 apr_pool_t *result_pool,
99362181Sdim                                 apr_pool_t *scratch_pool);
100289177Speter
101289177Speter/* Open the proto-rev file of transaction TXN_ID in FS and return it in *FILE.
102289177Speter * Allocate *FILE in RESULT_POOL use and SCRATCH_POOL for temporaries.. */
103289177Spetersvn_error_t *
104362181Sdimsvn_fs_x__rev_file_open_proto_rev(svn_fs_x__revision_file_t **file,
105362181Sdim                                  svn_fs_t *fs,
106362181Sdim                                  svn_fs_x__txn_id_t txn_id,
107362181Sdim                                  apr_pool_t* result_pool,
108362181Sdim                                  apr_pool_t *scratch_pool);
109289177Speter
110289177Speter/* Wrap the TEMP_FILE, used in the context of FS, into a revision file
111289177Speter * struct, allocated in RESULT_POOL, and return it in *FILE.
112289177Speter */
113289177Spetersvn_error_t *
114362181Sdimsvn_fs_x__rev_file_wrap_temp(svn_fs_x__revision_file_t **file,
115289177Speter                             svn_fs_t *fs,
116289177Speter                             apr_file_t *temp_file,
117289177Speter                             apr_pool_t *result_pool);
118289177Speter
119362181Sdim/* Access functions */
120362181Sdim
121362181Sdim/* Copy the L2P index info for FILE into *INFO.
122289177Speter */
123289177Spetersvn_error_t *
124362181Sdimsvn_fs_x__rev_file_info(svn_fs_x__rev_file_info_t *info,
125362181Sdim                        svn_fs_x__revision_file_t *file);
126362181Sdim
127362181Sdim/* Convenience wrapper around svn_io_file_name_get. */
128362181Sdimsvn_error_t *
129362181Sdimsvn_fs_x__rev_file_name(const char **filename,
130362181Sdim                        svn_fs_x__revision_file_t *file,
131362181Sdim                        apr_pool_t *result_pool);
132362181Sdim
133362181Sdim/* Set *STREAM to the shared stream object of FILE.
134362181Sdim */
135362181Sdimsvn_error_t *
136362181Sdimsvn_fs_x__rev_file_stream(svn_stream_t **stream,
137362181Sdim                          svn_fs_x__revision_file_t *file);
138362181Sdim
139362181Sdim/* Set *APR_FILE to the shared file object of FILE.
140362181Sdim */
141362181Sdimsvn_error_t *
142362181Sdimsvn_fs_x__rev_file_get(apr_file_t **apr_file,
143362181Sdim                       svn_fs_x__revision_file_t *file);
144362181Sdim
145362181Sdim/* Set *STREAM to the shared L2P data stream of FILE.
146362181Sdim */
147362181Sdimsvn_error_t *
148362181Sdimsvn_fs_x__rev_file_l2p_index(svn_fs_x__packed_number_stream_t **stream,
149362181Sdim                             svn_fs_x__revision_file_t *file);
150362181Sdim
151362181Sdim/* Set *STREAM to the shared P2L data stream of FILE.
152362181Sdim */
153362181Sdimsvn_error_t *
154362181Sdimsvn_fs_x__rev_file_p2l_index(svn_fs_x__packed_number_stream_t **stream,
155362181Sdim                             svn_fs_x__revision_file_t *file);
156362181Sdim
157362181Sdim/* Copy the L2P index info for FILE into *INFO.
158362181Sdim */
159362181Sdimsvn_error_t *
160362181Sdimsvn_fs_x__rev_file_l2p_info(svn_fs_x__index_info_t *info,
161362181Sdim                            svn_fs_x__revision_file_t *file);
162362181Sdim
163362181Sdim/* Copy the P2L index info for FILE into *INFO.
164362181Sdim */
165362181Sdimsvn_error_t *
166362181Sdimsvn_fs_x__rev_file_p2l_info(svn_fs_x__index_info_t *info,
167362181Sdim                            svn_fs_x__revision_file_t *file);
168362181Sdim
169362181Sdim/* Set *SIZE to the length of the revision data in FILE.
170362181Sdim */
171362181Sdimsvn_error_t *
172362181Sdimsvn_fs_x__rev_file_data_size(svn_filesize_t *size,
173362181Sdim                             svn_fs_x__revision_file_t *file);
174362181Sdim
175362181Sdim/* File manipulation. */
176362181Sdim
177362181Sdim/* Convenience wrapper around svn_io_file_aligned_seek. */
178362181Sdimsvn_error_t *
179362181Sdimsvn_fs_x__rev_file_seek(svn_fs_x__revision_file_t *file,
180362181Sdim                        apr_off_t *buffer_start,
181362181Sdim                        apr_off_t offset);
182362181Sdim
183362181Sdim/* Convenience wrapper around svn_fs_x__get_file_offset. */
184362181Sdimsvn_error_t *
185362181Sdimsvn_fs_x__rev_file_offset(apr_off_t *offset,
186362181Sdim                          svn_fs_x__revision_file_t *file);
187362181Sdim
188362181Sdim/* Convenience wrapper around svn_io_file_read_full2. */
189362181Sdimsvn_error_t *
190362181Sdimsvn_fs_x__rev_file_read(svn_fs_x__revision_file_t *file,
191362181Sdim                        void *buf,
192362181Sdim                        apr_size_t nbytes);
193362181Sdim
194362181Sdim/* Close all files and streams in FILE.  They will be reopened automatically
195362181Sdim * by any of the above access functions.
196362181Sdim */
197362181Sdimsvn_error_t *
198289177Spetersvn_fs_x__close_revision_file(svn_fs_x__revision_file_t *file);
199289177Speter
200289177Speter#endif
201