Fix compiler warning due to missing function prototype.
[svn.git] / subversion / libsvn_fs_base / bdb / uuids-table.c
blob9148cc5cbd6e2a89ccefe32c9b169000d3b8bfdf
1 /* uuids-table.c : operations on the `uuids' table
3 * ====================================================================
4 * Copyright (c) 2000-2004 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 #include <apr_uuid.h>
20 #include "bdb_compat.h"
21 #include "svn_fs.h"
22 #include "../fs.h"
23 #include "../err.h"
24 #include "dbt.h"
25 #include "../trail.h"
26 #include "../../libsvn_fs/fs-loader.h"
27 #include "bdb-err.h"
28 #include "uuids-table.h"
30 #include "svn_private_config.h"
33 /*** Creating and opening the uuids table.
34 When the table is created, the repository's uuid is
35 generated and stored as record #1. ***/
37 int
38 svn_fs_bdb__open_uuids_table(DB **uuids_p,
39 DB_ENV *env,
40 svn_boolean_t create)
42 const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
43 DB *uuids;
44 int error;
46 BDB_ERR(svn_fs_bdb__check_version());
47 BDB_ERR(db_create(&uuids, env, 0));
48 BDB_ERR(uuids->set_re_len(uuids, APR_UUID_FORMATTED_LENGTH));
50 error = (uuids->open)(SVN_BDB_OPEN_PARAMS(uuids, NULL),
51 "uuids", 0, DB_RECNO,
52 open_flags, 0666);
54 /* This is a temporary compatibility check; it creates the
55 UUIDs table if one does not already exist. */
56 if (error == ENOENT && (! create))
58 BDB_ERR(uuids->close(uuids, 0));
59 return svn_fs_bdb__open_uuids_table(uuids_p, env, TRUE);
62 BDB_ERR(error);
64 if (create)
66 char buffer[APR_UUID_FORMATTED_LENGTH + 1];
67 DBT key, value;
68 apr_uuid_t uuid;
69 int recno = 0;
71 svn_fs_base__clear_dbt(&key);
72 key.data = &recno;
73 key.size = sizeof(recno);
74 key.ulen = key.size;
75 key.flags |= DB_DBT_USERMEM;
77 svn_fs_base__clear_dbt(&value);
78 value.data = buffer;
79 value.size = sizeof(buffer) - 1;
81 apr_uuid_get(&uuid);
82 apr_uuid_format(buffer, &uuid);
84 BDB_ERR(uuids->put(uuids, 0, &key, &value, DB_APPEND));
87 *uuids_p = uuids;
88 return 0;
91 svn_error_t *svn_fs_bdb__get_uuid(svn_fs_t *fs,
92 int idx,
93 const char **uuid,
94 trail_t *trail,
95 apr_pool_t *pool)
97 base_fs_data_t *bfd = fs->fsap_data;
98 char buffer[APR_UUID_FORMATTED_LENGTH + 1];
99 DB *uuids = bfd->uuids;
100 DBT key;
101 DBT value;
103 svn_fs_base__clear_dbt(&key);
104 key.data = &idx;
105 key.size = sizeof(idx);
107 svn_fs_base__clear_dbt(&value);
108 value.data = buffer;
109 value.size = sizeof(buffer) - 1;
110 value.ulen = value.size;
111 value.flags |= DB_DBT_USERMEM;
113 svn_fs_base__trail_debug(trail, "uuids", "get");
114 SVN_ERR(BDB_WRAP(fs, _("get repository uuid"),
115 uuids->get(uuids, trail->db_txn, &key, &value, 0)));
117 *uuid = apr_pstrmemdup(pool, value.data, value.size);
119 return SVN_NO_ERROR;
122 svn_error_t *svn_fs_bdb__set_uuid(svn_fs_t *fs,
123 int idx,
124 const char *uuid,
125 trail_t *trail,
126 apr_pool_t *pool)
128 base_fs_data_t *bfd = fs->fsap_data;
129 DB *uuids = bfd->uuids;
130 DBT key;
131 DBT value;
133 svn_fs_base__clear_dbt(&key);
134 key.data = &idx;
135 key.size = sizeof(idx);
137 svn_fs_base__clear_dbt(&value);
138 value.size = strlen(uuid);
139 value.data = apr_pstrmemdup(pool, uuid, value.size + 1);
141 svn_fs_base__trail_debug(trail, "uuids", "put");
142 SVN_ERR(BDB_WRAP(fs, _("set repository uuid"),
143 uuids->put(uuids, trail->db_txn, &key, &value, 0)));
145 return SVN_NO_ERROR;