In the command-line client, forbid
[svn.git] / subversion / libsvn_fs_fs / fs.h
blob2c43bb1751a806f463aaf903e505acb2209a3c16
1 /* fs.h : interface to Subversion filesystem, private to libsvn_fs
3 * ====================================================================
4 * Copyright (c) 2000-2007 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
18 #ifndef SVN_LIBSVN_FS_FS_H
19 #define SVN_LIBSVN_FS_FS_H
21 #include <apr_pools.h>
22 #include <apr_hash.h>
23 #include <apr_md5.h>
24 #include <apr_thread_mutex.h>
25 #include <apr_network_io.h>
27 #include "svn_fs.h"
28 #include "private/svn_fs_private.h"
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
35 /*** The filesystem structure. ***/
37 /* Following are defines that specify the textual elements of the
38 native filesystem directories and revision files. */
40 /* Names of special files in the fs_fs filesystem. */
41 #define PATH_FORMAT "format" /* Contains format number */
42 #define PATH_UUID "uuid" /* Contains UUID */
43 #define PATH_CURRENT "current" /* Youngest revision */
44 #define PATH_LOCK_FILE "write-lock" /* Revision lock file */
45 #define PATH_REVS_DIR "revs" /* Directory of revisions */
46 #define PATH_REVPROPS_DIR "revprops" /* Directory of revprops */
47 #define PATH_TXNS_DIR "transactions" /* Directory of transactions */
48 #define PATH_TXN_CURRENT "transaction-current" /* File with next txn key */
49 #define PATH_TXN_CURRENT_LOCK "txn-current-lock" /* Lock for txn-current */
50 #define PATH_LOCKS_DIR "locks" /* Directory of locks */
52 /* Names of special files and file extensions for transactions */
53 #define PATH_CHANGES "changes" /* Records changes made so far */
54 #define PATH_TXN_PROPS "props" /* Transaction properties */
55 #define PATH_NEXT_IDS "next-ids" /* Next temporary ID assignments */
56 #define PATH_REV "rev" /* Proto rev file */
57 #define PATH_REV_LOCK "rev-lock" /* Proto rev (write) lock file */
58 #define PATH_TXN_MERGEINFO "mergeinfo" /* Transaction mergeinfo props */
59 #define PATH_PREFIX_NODE "node." /* Prefix for node filename */
60 #define PATH_EXT_TXN ".txn" /* Extension of txn dir */
61 #define PATH_EXT_CHILDREN ".children" /* Extension for dir contents */
62 #define PATH_EXT_PROPS ".props" /* Extension for node props */
64 /* The format number of this filesystem.
65 This is independent of the repository format number, and
66 independent of any other FS back ends. */
67 #define SVN_FS_FS__FORMAT_NUMBER 3
69 /* The minimum format number that supports svndiff version 1. */
70 #define SVN_FS_FS__MIN_SVNDIFF1_FORMAT 2
72 /* The minimum format number that supports transaction ID generation
73 using a transaction sequence in the transaction-current file. */
74 #define SVN_FS_FS__MIN_TXN_CURRENT_FORMAT 3
76 /* The minimum format number that supports the "layout" filesystem
77 format option. */
78 #define SVN_FS_FS__MIN_LAYOUT_FORMAT_OPTION_FORMAT 3
80 /* Maximum number of directories to cache dirents for.
81 This *must* be a power of 2 for DIR_CACHE_ENTRIES_MASK
82 to work. */
83 #define NUM_DIR_CACHE_ENTRIES 128
84 #define DIR_CACHE_ENTRIES_MASK(x) ((x) & (NUM_DIR_CACHE_ENTRIES - 1))
86 /* Maximum number of revroot ids to cache dirents for at a time. */
87 #define NUM_RRI_CACHE_ENTRIES 4096
89 /* Private FSFS-specific data shared between all svn_txn_t objects that
90 relate to a particular transaction in a filesystem (as identified
91 by transaction id and filesystem UUID). Objects of this type are
92 allocated in their own subpool of the common pool. */
93 struct fs_fs_shared_txn_data_t;
94 typedef struct fs_fs_shared_txn_data_t
96 /* The next transaction in the list, or NULL if there is no following
97 transaction. */
98 struct fs_fs_shared_txn_data_t *next;
100 /* This transaction's ID. For repositories whose format is less
101 than SVN_FS_FS__MIN_TXN_CURRENT_FORMAT, the ID is in the form
102 <rev>-<uniqueifier>, where <uniqueifier> runs from 0-99999 (see
103 create_txn_dir_pre_1_5() in fs_fs.c). For newer repositories,
104 the form is <rev>-<200 digit base 36 number> (see
105 create_txn_dir() in fs_fs.c). */
106 char txn_id[SVN_FS__TXN_MAX_LEN+1];
108 /* Whether the transaction's prototype revision file is locked for
109 writing by any thread in this process (including the current
110 thread; recursive locks are not permitted). This is effectively
111 a non-recursive mutex. */
112 svn_boolean_t being_written;
114 /* The pool in which this object has been allocated; a subpool of the
115 common pool. */
116 apr_pool_t *pool;
117 } fs_fs_shared_txn_data_t;
120 /* Private FSFS-specific data shared between all svn_fs_t objects that
121 relate to a particular filesystem, as identified by filesystem UUID.
122 Objects of this type are allocated in the common pool. */
123 typedef struct
125 /* A list of shared transaction objects for each transaction that is
126 currently active, or NULL if none are. All access to this list,
127 including the contents of the objects stored in it, is synchronised
128 under TXN_LIST_LOCK. */
129 fs_fs_shared_txn_data_t *txns;
131 /* A free transaction object, or NULL if there is no free object.
132 Access to this object is synchronised under TXN_LIST_LOCK. */
133 fs_fs_shared_txn_data_t *free_txn;
135 #if APR_HAS_THREADS
136 /* A lock for intra-process synchronization when accessing the TXNS list. */
137 apr_thread_mutex_t *txn_list_lock;
139 /* A lock for intra-process synchronization when grabbing the
140 repository write lock. */
141 apr_thread_mutex_t *fs_write_lock;
143 /* A lock for intra-process synchronization when locking the
144 transaction-current file. */
145 apr_thread_mutex_t *txn_current_lock;
146 #endif
148 /* The common pool, under which this object is allocated, subpools
149 of which are used to allocate the transaction objects. */
150 apr_pool_t *common_pool;
151 } fs_fs_shared_data_t;
153 typedef struct dag_node_t dag_node_t;
155 /* Structure for DAG-node cache. Cache items are arranged in a
156 circular LRU list with a dummy entry, and also indexed with a hash
157 table. Transaction nodes are cached within the individual txn
158 roots; revision nodes are cached together within the FS object. */
159 typedef struct dag_node_cache_t
161 const char *key; /* Lookup key for cached node: path
162 for txns; rev catenated with path
163 for revs */
164 dag_node_t *node; /* Cached node */
165 struct dag_node_cache_t *prev; /* Next node in LRU list */
166 struct dag_node_cache_t *next; /* Previous node in LRU list */
167 apr_pool_t *pool; /* Pool in which node is allocated */
168 } dag_node_cache_t;
171 /* Private (non-shared) FSFS-specific data for each svn_fs_t object. */
172 typedef struct
174 /* A cache of the last directory opened within the filesystem. */
175 svn_fs_id_t *dir_cache_id[NUM_DIR_CACHE_ENTRIES];
176 apr_hash_t *dir_cache[NUM_DIR_CACHE_ENTRIES];
177 apr_pool_t *dir_cache_pool[NUM_DIR_CACHE_ENTRIES];
179 /* The format number of this FS. */
180 int format;
181 /* The maximum number of files to store per directory (for sharded
182 layouts) or zero (for linear layouts). */
183 int max_files_per_dir;
185 /* The uuid of this FS. */
186 const char *uuid;
188 /* Caches of immutable data.
190 Both of these could be moved to fs_fs_shared_data_t to make them
191 last longer; on the other hand, this would require adding mutexes
192 for threaded builds.
195 /* A cache of revision root IDs, allocated in this subpool. (IDs
196 are so small that one pool per ID would be overkill;
197 unfortunately, this means the only way we expire cache entries is
198 by wiping the whole cache.) */
199 apr_hash_t *rev_root_id_cache;
200 apr_pool_t *rev_root_id_cache_pool;
202 /* DAG node cache for immutable nodes */
203 dag_node_cache_t rev_node_list;
204 apr_hash_t *rev_node_cache;
206 /* Data shared between all svn_fs_t objects for a given filesystem. */
207 fs_fs_shared_data_t *shared;
208 } fs_fs_data_t;
211 /*** Filesystem Transaction ***/
212 typedef struct
214 /* property list (const char * name, svn_string_t * value).
215 may be NULL if there are no properties. */
216 apr_hash_t *proplist;
218 /* node revision id of the root node. */
219 const svn_fs_id_t *root_id;
221 /* node revision id of the node which is the root of the revision
222 upon which this txn is base. (unfinished only) */
223 const svn_fs_id_t *base_id;
225 /* copies list (const char * copy_ids), or NULL if there have been
226 no copies in this transaction. */
227 apr_array_header_t *copies;
229 } transaction_t;
232 /*** Representation ***/
233 /* If you add fields to this, check to see if you need to change
234 * svn_fs_fs__rep_copy. */
235 typedef struct
237 /* MD5 checksum for the contents produced by this representation.
238 This checksum is for the contents the rep shows to consumers,
239 regardless of how the rep stores the data under the hood. It is
240 independent of the storage (fulltext, delta, whatever).
242 If all the bytes are 0, then for compatibility behave as though
243 this checksum matches the expected checksum. */
244 unsigned char checksum[APR_MD5_DIGESTSIZE];
246 /* Revision where this representation is located. */
247 svn_revnum_t revision;
249 /* Offset into the revision file where it is located. */
250 apr_off_t offset;
252 /* The size of the representation in bytes as seen in the revision
253 file. */
254 svn_filesize_t size;
256 /* The size of the fulltext of the representation. */
257 svn_filesize_t expanded_size;
259 /* Is this representation a transaction? */
260 const char *txn_id;
262 } representation_t;
265 /*** Node-Revision ***/
266 /* If you add fields to this, check to see if you need to change
267 * copy_node_revision in dag.c. */
268 typedef struct
270 /* node kind */
271 svn_node_kind_t kind;
273 /* The node-id for this node-rev. */
274 const svn_fs_id_t *id;
276 /* predecessor node revision id, or NULL if there is no predecessor
277 for this node revision */
278 const svn_fs_id_t *predecessor_id;
280 /* If this node-rev is a copy, where was it copied from? */
281 const char *copyfrom_path;
282 svn_revnum_t copyfrom_rev;
284 /* Helper for history tracing, root of the parent tree from whence
285 this node-rev was copied. */
286 svn_revnum_t copyroot_rev;
287 const char *copyroot_path;
289 /* number of predecessors this node revision has (recursively), or
290 -1 if not known (for backward compatibility). */
291 int predecessor_count;
293 /* representation key for this node's properties. may be NULL if
294 there are no properties. */
295 representation_t *prop_rep;
297 /* representation for this node's data. may be NULL if there is
298 no data. */
299 representation_t *data_rep;
301 /* path at which this node first came into existence. */
302 const char *created_path;
304 /* is this the unmodified root of a transaction? */
305 svn_boolean_t is_fresh_txn_root;
307 } node_revision_t;
310 /*** Change ***/
311 typedef struct
313 /* Path of the change. */
314 const char *path;
316 /* Node revision ID of the change. */
317 const svn_fs_id_t *noderev_id;
319 /* The kind of change. */
320 svn_fs_path_change_kind_t kind;
322 /* Text or property mods? */
323 svn_boolean_t text_mod;
324 svn_boolean_t prop_mod;
326 /* Copyfrom revision and path. */
327 svn_revnum_t copyfrom_rev;
328 const char * copyfrom_path;
330 } change_t;
333 #ifdef __cplusplus
335 #endif /* __cplusplus */
337 #endif /* SVN_LIBSVN_FS_FS_H */