Back to index

openldap  2.4.31
mfree.c
Go to the documentation of this file.
00001 /* mfree.c - memory-mapped database freelist scanner */
00002 /*
00003  * Copyright 2011 Howard Chu, Symas Corp.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted only as authorized by the OpenLDAP
00008  * Public License.
00009  *
00010  * A copy of this license is available in the file LICENSE in the
00011  * top-level directory of the distribution or, alternatively, at
00012  * <http://www.OpenLDAP.org/license.html>.
00013  */
00014 #define _XOPEN_SOURCE 500          /* srandom(), random() */
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <time.h>
00018 #include "mdb.h"
00019 #include "midl.h"
00020 
00021 int main(int argc,char * argv[])
00022 {
00023        int rc;
00024        MDB_env *env;
00025        MDB_dbi dbi;
00026        MDB_val key, data;
00027        MDB_txn *txn;
00028        MDB_stat mst;
00029        MDB_cursor *cursor;
00030        ID i, j, *iptr;
00031 
00032        if (argc != 2) {
00033               fprintf(stderr, "usage: %s <pathname>\n", argv[0]);
00034               exit(1);
00035        }
00036 
00037        rc = mdb_env_create(&env);
00038        rc = mdb_env_open(env, argv[1], MDB_RDONLY, 0664);
00039        rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
00040        dbi = 0;
00041        rc = mdb_cursor_open(txn, dbi, &cursor);
00042        while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
00043               printf("key: %p %zu, data: %p\n",
00044                      key.mv_data,  *(ID *) key.mv_data,
00045                      data.mv_data);
00046               iptr = data.mv_data;
00047               j = *iptr++;
00048               for (i=0; i<j; i++)
00049                      printf(" %zu\n", iptr[i]);
00050        }
00051        mdb_cursor_close(cursor);
00052        mdb_txn_abort(txn);
00053        mdb_env_close(env);
00054 
00055        return 0;
00056 }