]> arthur.barton.de Git - netatalk.git/blob - etc/cnid_dbd/dbd_dbcheck.c
Add an indexes check and rebuild, optionnal for dbd (parameter check
[netatalk.git] / etc / cnid_dbd / dbd_dbcheck.c
1 /*
2  * $Id: dbd_dbcheck.c,v 1.1.2.1 2004-12-21 13:36:12 didg Exp $
3  *
4  * Copyright (C) Joerg Lenneis 2003
5  * All Rights Reserved.  See COPYING.
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <sys/param.h>
16 #include <errno.h>
17 #include <netatalk/endian.h>
18 #include <atalk/logger.h>
19 #include <atalk/cnid_dbd_private.h>
20
21 #include "pack.h"
22 #include "dbif.h"
23 #include "dbd.h"
24
25 int dbd_check(char *dbdir)
26 {
27     u_int32_t c_didname = 0, c_devino = 0, c_cnid = 0;
28 #if 0
29     char dbdir[MAXPATHLEN];
30
31     if (NULL == getcwd(dbdir, sizeof(dbdir)) )
32         return -1;
33 #endif
34
35     LOG(log_debug, logtype_cnid, "CNID database at `%s' is being checked (quick)", dbdir);
36
37     if (dbif_count(DBIF_IDX_CNID, &c_cnid)) 
38         return -1;
39
40     if (dbif_count(DBIF_IDX_DIDNAME, &c_didname)) 
41         return -1;
42     
43     /* bailout after the first error */
44     if (dbif_count(DBIF_IDX_DEVINO, &c_devino))
45         return -1;
46
47     if ( c_cnid != c_devino) {
48         LOG(log_error, logtype_cnid, "CNID database at `%s' corrupted (%u/%u)", dbdir, c_cnid, c_devino);
49         return 1;
50     }
51
52     if ( c_cnid != c_didname) {
53         LOG(log_error, logtype_cnid, "CNID database at `%s' corrupted (%u/%u)", dbdir, c_cnid, c_didname);
54         return 1;
55     }
56
57     LOG(log_debug, logtype_cnid, "CNID database at `%s' seems ok, %u entries.", dbdir, c_cnid);
58     return 0;  
59 }
60