]> git.sur5r.net Git - openldap/blobdiff - libraries/libmdb/mdb_stat.c
Add some legalese
[openldap] / libraries / libmdb / mdb_stat.c
index 505d62e65b31b3537713d1a7ed77d007ef093bea..e55e5ae51ea42becc9dbbf18e4a3d79601078c18 100644 (file)
@@ -1,3 +1,16 @@
+/* mdb_stat.c - memory-mapped database status tool */
+/*
+ * Copyright 2011 Howard Chu, Symas Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 
 int main(int argc,char * argv[])
 {
-       int i = 0, rc;
+       int rc;
        MDB_env *env;
-       MDB_db *db;
-       MDB_stat *mst;
+       MDB_txn *txn;
+       MDB_dbi dbi;
+       MDB_stat mst;
        char *envname = argv[1];
        char *subname = NULL;
 
        if (argc > 2)
                subname = argv[2];
    
-       rc = mdbenv_create(&env, 0);
+       rc = mdbenv_create(&env);
        rc = mdbenv_open(env, envname, MDB_RDONLY, 0);
        if (rc) {
                printf("mdbenv_open failed, error %d\n", rc);
                exit(1);
        }
-       rc = mdb_open(env, NULL, NULL, 0, &db);
+       rc = mdb_txn_begin(env, 1, &txn);
+       if (rc) {
+               printf("mdb_txn_begin failed, error %d\n", rc);
+               exit(1);
+       }
+       rc = mdb_open(txn, subname, 0, &dbi);
        if (rc) {
                printf("mdb_open failed, error %d\n", rc);
                exit(1);
        }
    
-       rc = mdb_stat(db, &mst);
-       printf("Created at %s", ctime(&mst->ms_created_at));
-       printf("Page size: %u\n", mst->ms_psize);
-       printf("Tree depth: %u\n", mst->ms_depth);
-       printf("Branch pages: %lu\n", mst->ms_branch_pages);
-       printf("Leaf pages: %lu\n", mst->ms_leaf_pages);
-       printf("Overflow pages: %lu\n", mst->ms_overflow_pages);
-       printf("Revisions: %lu\n", mst->ms_revisions);
-       printf("Entries: %lu\n", mst->ms_entries);
-       mdb_close(db);
+       rc = mdb_stat(txn, dbi, &mst);
+       printf("Page size: %u\n", mst.ms_psize);
+       printf("Tree depth: %u\n", mst.ms_depth);
+       printf("Branch pages: %lu\n", mst.ms_branch_pages);
+       printf("Leaf pages: %lu\n", mst.ms_leaf_pages);
+       printf("Overflow pages: %lu\n", mst.ms_overflow_pages);
+       printf("Entries: %lu\n", mst.ms_entries);
+       mdb_close(txn, dbi);
+       mdb_txn_abort(txn);
        mdbenv_close(env);
 
        return 0;