fs_fs.h revision 299742
189837Skris/* fs_fs.h : interface to the native filesystem layer
289837Skris *
3142425Snectar * ====================================================================
489837Skris *    Licensed to the Apache Software Foundation (ASF) under one
589837Skris *    or more contributor license agreements.  See the NOTICE file
689837Skris *    distributed with this work for additional information
789837Skris *    regarding copyright ownership.  The ASF licenses this file
889837Skris *    to you under the Apache License, Version 2.0 (the
989837Skris *    "License"); you may not use this file except in compliance
1089837Skris *    with the License.  You may obtain a copy of the License at
1189837Skris *
1289837Skris *      http://www.apache.org/licenses/LICENSE-2.0
1389837Skris *
1489837Skris *    Unless required by applicable law or agreed to in writing,
1589837Skris *    software distributed under the License is distributed on an
16111147Snectar *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17111147Snectar *    KIND, either express or implied.  See the License for the
18111147Snectar *    specific language governing permissions and limitations
19111147Snectar *    under the License.
20111147Snectar * ====================================================================
21111147Snectar */
22111147Snectar
23111147Snectar#ifndef SVN_LIBSVN_FS__FS_FS_H
24111147Snectar#define SVN_LIBSVN_FS__FS_FS_H
25111147Snectar
26111147Snectar#include "fs.h"
27111147Snectar
28111147Snectar/* Read the 'format' file of fsfs filesystem FS and store its info in FS.
29111147Snectar * Use SCRATCH_POOL for temporary allocations. */
30111147Snectarsvn_error_t *
31111147Snectarsvn_fs_fs__read_format_file(svn_fs_t *fs, apr_pool_t *scratch_pool);
32111147Snectar
33111147Snectar/* Open the fsfs filesystem pointed to by PATH and associate it with
34111147Snectar   filesystem object FS.  Use POOL for temporary allocations.
35111147Snectar
36111147Snectar   ### Some parts of *FS must have been initialized beforehand; some parts
37111147Snectar       (including FS->path) are initialized by this function. */
38142425Snectarsvn_error_t *svn_fs_fs__open(svn_fs_t *fs,
39111147Snectar                             const char *path,
40111147Snectar                             apr_pool_t *pool);
41111147Snectar
42111147Snectar/* Upgrade the fsfs filesystem FS.  Indicate progress via the optional
43111147Snectar * NOTIFY_FUNC callback using NOTIFY_BATON.  The optional CANCEL_FUNC
44111147Snectar * will periodically be called with CANCEL_BATON to allow for preemption.
4589837Skris * Use POOL for temporary allocations. */
4689837Skrissvn_error_t *svn_fs_fs__upgrade(svn_fs_t *fs,
4789837Skris                                svn_fs_upgrade_notify_t notify_func,
4889837Skris                                void *notify_baton,
4989837Skris                                svn_cancel_func_t cancel_func,
5089837Skris                                void *cancel_baton,
5189837Skris                                apr_pool_t *pool);
5289837Skris
5389837Skris/* Set *YOUNGEST to the youngest revision in filesystem FS.  Do any
5489837Skris   temporary allocation in POOL. */
5589837Skrissvn_error_t *svn_fs_fs__youngest_rev(svn_revnum_t *youngest,
5689837Skris                                     svn_fs_t *fs,
5789837Skris                                     apr_pool_t *pool);
5889837Skris
5989837Skris/* Return the shard size of filesystem FS.  Return 0 for non-shared ones. */
6089837Skrisint
6189837Skrissvn_fs_fs__shard_size(svn_fs_t *fs);
6289837Skris
6389837Skris/* Set *MIN_UNPACKED to the oldest non-packed revision in filesystem FS.
6489837Skris   Do any temporary allocation in POOL. */
6589837Skrissvn_error_t *
6689837Skrissvn_fs_fs__min_unpacked_rev(svn_revnum_t *min_unpacked,
6789837Skris                            svn_fs_t *fs,
6889837Skris                            apr_pool_t *pool);
6989837Skris
7089837Skris/* Return SVN_ERR_FS_NO_SUCH_REVISION if the given revision REV is newer
7189837Skris   than the current youngest revision in FS or is simply not a valid
7289837Skris   revision number, else return success. */
7389837Skrissvn_error_t *
7489837Skrissvn_fs_fs__ensure_revision_exists(svn_revnum_t rev,
7589837Skris                                  svn_fs_t *fs,
7689837Skris                                  apr_pool_t *pool);
7789837Skris
7889837Skris/* Set *LENGTH to the be fulltext length of the node revision
7989837Skris   specified by NODEREV.  Use POOL for temporary allocations. */
8089837Skrissvn_error_t *svn_fs_fs__file_length(svn_filesize_t *length,
8189837Skris                                    node_revision_t *noderev,
8289837Skris                                    apr_pool_t *pool);
8389837Skris
8489837Skris/* Return TRUE if the representation keys in A and B both point to the
8589837Skris   same representation, else return FALSE. */
8689837Skrissvn_boolean_t svn_fs_fs__noderev_same_rep_key(representation_t *a,
8789837Skris                                              representation_t *b);
8889837Skris
8989837Skris/* Set *EQUAL to TRUE if the text representations in A and B within FS
9089837Skris   have equal contents, else set it to FALSE.
9189837Skris   Use SCRATCH_POOL for temporary allocations. */
9289837Skrissvn_error_t *
9389837Skrissvn_fs_fs__file_text_rep_equal(svn_boolean_t *equal,
9489837Skris                               svn_fs_t *fs,
9589837Skris                               node_revision_t *a,
9689837Skris                               node_revision_t *b,
9789837Skris                               apr_pool_t *scratch_pool);
9889837Skris
9989837Skris/* Set *EQUAL to TRUE if the property representations in A and B within FS
10089837Skris   have equal contents, else set it to FALSE.
10189837Skris   Use SCRATCH_POOL for temporary allocations. */
10289837Skrissvn_error_t *
10389837Skrissvn_fs_fs__prop_rep_equal(svn_boolean_t *equal,
10489837Skris                          svn_fs_t *fs,
10589837Skris                          node_revision_t *a,
10689837Skris                          node_revision_t *b,
10789837Skris                          apr_pool_t *scratch_pool);
10889837Skris
10989837Skris
11089837Skris/* Return a copy of the representation REP allocated from POOL. */
11189837Skrisrepresentation_t *svn_fs_fs__rep_copy(representation_t *rep,
11289837Skris                                      apr_pool_t *pool);
11389837Skris
11489837Skris
11589837Skris/* Return the recorded checksum of type KIND for the text representation
11689837Skris   of NODREV into CHECKSUM, allocating from POOL.  If no stored checksum is
11789837Skris   available, put all NULL into CHECKSUM. */
11889837Skrissvn_error_t *svn_fs_fs__file_checksum(svn_checksum_t **checksum,
11989837Skris                                      node_revision_t *noderev,
12089837Skris                                      svn_checksum_kind_t kind,
12189837Skris                                      apr_pool_t *pool);
12289837Skris
12389837Skris/* Return whether or not the given FS supports mergeinfo metadata. */
12489837Skrissvn_boolean_t svn_fs_fs__fs_supports_mergeinfo(svn_fs_t *fs);
12589837Skris
12689837Skris/* Under the repository db PATH, create a FSFS repository with FORMAT,
12789837Skris * the given SHARD_SIZE. If USE_LOG_ADDRESSING is non-zero, repository
12889837Skris * will use logical addressing. If not supported by the respective format,
12989837Skris * the latter two parameters will be ignored. FS will be updated.
13089837Skris *
13189837Skris * The only file not being written is the 'format' file.  This allows
13289837Skris * callers such as hotcopy to modify the contents before turning the
13389837Skris * tree into an accessible repository.
13489837Skris *
13589837Skris * Use POOL for temporary allocations.
13689837Skris */
13789837Skrissvn_error_t *
13889837Skrissvn_fs_fs__create_file_tree(svn_fs_t *fs,
13989837Skris                            const char *path,
14089837Skris                            int format,
14189837Skris                            int shard_size,
14289837Skris                            svn_boolean_t use_log_addressing,
14389837Skris                            apr_pool_t *pool);
14489837Skris
14589837Skris/* Create a fs_fs fileysystem referenced by FS at path PATH.  Get any
14689837Skris   temporary allocations from POOL.
14789837Skris
148142425Snectar   ### Some parts of *FS must have been initialized beforehand; some parts
149142425Snectar       (including FS->path) are initialized by this function. */
150142425Snectarsvn_error_t *svn_fs_fs__create(svn_fs_t *fs,
151142425Snectar                               const char *path,
152142425Snectar                               apr_pool_t *pool);
153142425Snectar
15489837Skris/* Set the uuid of repository FS to UUID and the instance ID to INSTANCE_ID.
15589837Skris   If any of them is NULL, use a newly generated UUID / ID instead.  Ignore
15689837Skris   INSTANCE_ID whenever instance IDs are not supported by the FS format.
15789837Skris   Perform temporary allocations in POOL. */
15889837Skrissvn_error_t *svn_fs_fs__set_uuid(svn_fs_t *fs,
15989837Skris                                 const char *uuid,
16089837Skris                                 const char *instance_id,
16189837Skris                                 apr_pool_t *pool);
16289837Skris
16389837Skris/* Return the path to the 'current' file in FS.
16489837Skris   Perform allocation in POOL. */
16589837Skrisconst char *
16689837Skrissvn_fs_fs__path_current(svn_fs_t *fs, apr_pool_t *pool);
16789837Skris
16889837Skris/* Write the format number and maximum number of files per directory
16989837Skris   for FS, possibly expecting to overwrite a previously existing file.
17089837Skris
17189837Skris   Use POOL for temporary allocation. */
17289837Skrissvn_error_t *
17389837Skrissvn_fs_fs__write_format(svn_fs_t *fs,
17489837Skris                        svn_boolean_t overwrite,
17589837Skris                        apr_pool_t *pool);
17689837Skris
17789837Skris/* Obtain a write lock on the filesystem FS in a subpool of POOL, call
17889837Skris   BODY with BATON and that subpool, destroy the subpool (releasing the write
17989837Skris   lock) and return what BODY returned. */
180194206Ssimonsvn_error_t *
18189837Skrissvn_fs_fs__with_write_lock(svn_fs_t *fs,
18289837Skris                           svn_error_t *(*body)(void *baton,
18389837Skris                                                apr_pool_t *pool),
18489837Skris                           void *baton,
185142425Snectar                           apr_pool_t *pool);
186194206Ssimon
18789837Skris/* Obtain a pack operation lock on the filesystem FS in a subpool of POOL,
188194206Ssimon   call BODY with BATON and that subpool, destroy the subpool (releasing the
189142425Snectar   write lock) and return what BODY returned. */
19089837Skrissvn_error_t *
19189837Skrissvn_fs_fs__with_pack_lock(svn_fs_t *fs,
192142425Snectar                          svn_error_t *(*body)(void *baton,
19389837Skris                                               apr_pool_t *pool),
19489837Skris                          void *baton,
19589837Skris                          apr_pool_t *pool);
19689837Skris
19789837Skris/* Run BODY (with BATON and POOL) while the txn-current file
19889837Skris   of FS is locked. */
19989837Skrissvn_error_t *
20089837Skrissvn_fs_fs__with_txn_current_lock(svn_fs_t *fs,
20189837Skris                                 svn_error_t *(*body)(void *baton,
20289837Skris                                                      apr_pool_t *pool),
20389837Skris                                 void *baton,
20489837Skris                                 apr_pool_t *pool);
20589837Skris
20689837Skris/* Obtain all locks on the filesystem FS in a subpool of POOL, call BODY
20789837Skris   with BATON and that subpool, destroy the subpool (releasing the locks)
20889837Skris   and return what BODY returned.
20989837Skris
21089837Skris   This combines svn_fs_fs__with_write_lock, svn_fs_fs__with_pack_lock,
21189837Skris   and svn_fs_fs__with_txn_current_lock, ensuring correct lock ordering. */
212111147Snectarsvn_error_t *
21389837Skrissvn_fs_fs__with_all_locks(svn_fs_t *fs,
21489837Skris                          svn_error_t *(*body)(void *baton,
21589837Skris                                               apr_pool_t *pool),
21689837Skris                          void *baton,
21789837Skris                          apr_pool_t *pool);
21889837Skris
21989837Skris/* Find the value of the property named PROPNAME in transaction TXN.
22089837Skris   Return the contents in *VALUE_P.  The contents will be allocated
22189837Skris   from POOL. */
22289837Skrissvn_error_t *svn_fs_fs__revision_prop(svn_string_t **value_p, svn_fs_t *fs,
22389837Skris                                      svn_revnum_t rev,
22489837Skris                                      const char *propname,
22589837Skris                                      apr_pool_t *pool);
22689837Skris
22789837Skris/* Change, add, or delete a property on a revision REV in filesystem
22889837Skris   FS.  NAME gives the name of the property, and value, if non-NULL,
22989837Skris   gives the new contents of the property.  If value is NULL, then the
23089837Skris   property will be deleted.  If OLD_VALUE_P is not NULL, do nothing unless the
23189837Skris   preexisting value is *OLD_VALUE_P.  Do any temporary allocation in POOL.  */
23289837Skrissvn_error_t *svn_fs_fs__change_rev_prop(svn_fs_t *fs, svn_revnum_t rev,
233194206Ssimon                                        const char *name,
23489837Skris                                        const svn_string_t *const *old_value_p,
23589837Skris                                        const svn_string_t *value,
23689837Skris                                        apr_pool_t *pool);
23789837Skris
238142425Snectar/* If directory PATH does not exist, create it and give it the same
239194206Ssimon   permissions as FS_PATH.*/
24089837Skrissvn_error_t *svn_fs_fs__ensure_dir_exists(const char *path,
241194206Ssimon                                          const char *fs_path,
242142425Snectar                                          apr_pool_t *pool);
24389837Skris
24489837Skris/* Update the node origin index for FS, recording the mapping from
245142425Snectar   NODE_ID to NODE_REV_ID.  Use POOL for any temporary allocations.
24689837Skris
24789837Skris   Because this is just an "optional" cache, this function does not
24889837Skris   return an error if the underlying storage is readonly; it still
24989837Skris   returns an error for other error conditions.
25089837Skris */
25189837Skrissvn_error_t *
25289837Skrissvn_fs_fs__set_node_origin(svn_fs_t *fs,
25389837Skris                           const svn_fs_fs__id_part_t *node_id,
25489837Skris                           const svn_fs_id_t *node_rev_id,
25589837Skris                           apr_pool_t *pool);
25689837Skris
25789837Skris/* Set *ORIGIN_ID to the node revision ID from which the history of
25889837Skris   all nodes in FS whose "Node ID" is NODE_ID springs, as determined
25989837Skris   by a look in the index.  ORIGIN_ID needs to be parsed in an
26089837Skris   FS-backend-specific way.  Use POOL for allocations.
26189837Skris
26289837Skris   If there is no entry for NODE_ID in the cache, return NULL
26389837Skris   in *ORIGIN_ID. */
26489837Skrissvn_error_t *
265111147Snectarsvn_fs_fs__get_node_origin(const svn_fs_id_t **origin_id,
26689837Skris                           svn_fs_t *fs,
26789837Skris                           const svn_fs_fs__id_part_t *node_id,
26889837Skris                           apr_pool_t *pool);
26989837Skris
27089837Skris
27189837Skris/* Initialize all session-local caches in FS according to the global
27289837Skris   cache settings. Use POOL for temporary allocations.
27389837Skris
27489837Skris   Please note that it is permissible for this function to set some
27589837Skris   or all of these caches to NULL, regardless of any setting. */
27689837Skrissvn_error_t *
27789837Skrissvn_fs_fs__initialize_caches(svn_fs_t *fs, apr_pool_t *pool);
27889837Skris
27989837Skris/* Initialize all transaction-local caches in FS according to the global
28089837Skris   cache settings and make TXN_ID part of their key space. Use POOL for
28189837Skris   allocations.
28289837Skris
28389837Skris   Please note that it is permissible for this function to set some or all
28489837Skris   of these caches to NULL, regardless of any setting. */
28589837Skrissvn_error_t *
28689837Skrissvn_fs_fs__initialize_txn_caches(svn_fs_t *fs,
28789837Skris                                 const char *txn_id,
28889837Skris                                 apr_pool_t *pool);
28989837Skris
290111147Snectar/* Resets the svn_cache__t structures local to the current transaction in FS.
29189837Skris   Calling it more than once per txn or from outside any txn is allowed. */
29289837Skrisvoid
29389837Skrissvn_fs_fs__reset_txn_caches(svn_fs_t *fs);
29489837Skris
29589837Skris#endif
296194206Ssimon