1/*
2 *
3 * Copyright (C) Joerg Lenneis 2003
4 * All Rights Reserved.  See COPYING.
5 */
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif /* HAVE_CONFIG_H */
10
11#include <stdio.h>
12#include <string.h>
13#include <sys/param.h>
14#include <errno.h>
15#include <arpa/inet.h>
16
17#include <atalk/logger.h>
18#include <atalk/cnid_dbd_private.h>
19
20#include "pack.h"
21#include "dbif.h"
22#include "dbd.h"
23
24int dbd_check_indexes(DBD *dbd, char *dbdir)
25{
26    u_int32_t c_didname = 0, c_devino = 0, c_cnid = 0;
27
28    LOG(log_note, logtype_cnid, "CNID database at `%s' is being checked (quick)", dbdir);
29
30    if (dbif_count(dbd, DBIF_CNID, &c_cnid))
31        return -1;
32
33    if (dbif_count(dbd, DBIF_IDX_DEVINO, &c_devino))
34        return -1;
35
36    /* bailout after the first error */
37    if ( c_cnid != c_devino) {
38        LOG(log_error, logtype_cnid, "CNID database at `%s' corrupted (%u/%u)", dbdir, c_cnid, c_devino);
39        return 1;
40    }
41
42    if (dbif_count(dbd, DBIF_IDX_DIDNAME, &c_didname))
43        return -1;
44
45    if ( c_cnid != c_didname) {
46        LOG(log_error, logtype_cnid, "CNID database at `%s' corrupted (%u/%u)", dbdir, c_cnid, c_didname);
47        return 1;
48    }
49
50    LOG(log_note, logtype_cnid, "CNID database at `%s' seems ok, %u entries.", dbdir, c_cnid);
51    return 0;
52}
53
54
55