/* perform inform command */ static int procinform(const char *path, int omode) { TCHDB *hdb = tchdbnew(); if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd); tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL); if (!tchdbopen(hdb, path, HDBOREADER | omode)) { printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; const char *npath = tchdbpath(hdb); if (!npath) npath = "(unknown)"; printf("path: %s\n", npath); const char *type = "(unknown)"; switch (tchdbtype(hdb)) { case TCDBTHASH: type = "hash"; break; case TCDBTBTREE: type = "btree"; break; case TCDBTFIXED: type = "fixed"; break; case TCDBTTABLE: type = "table"; break; } printf("database type: %s\n", type); uint8_t flags = tchdbflags(hdb); printf("additional flags:"); if (flags & HDBFOPEN) printf(" open"); if (flags & HDBFFATAL) printf(" fatal"); printf("\n"); printf("bucket number: %" PRIu64 "\n", (uint64_t) tchdbbnum(hdb)); #ifndef NDEBUG if (hdb->cnt_writerec >= 0) printf("used bucket number: %" PRId64 "\n", (int64_t) tchdbbnumused(hdb)); #endif printf("alignment: %u\n", tchdbalign(hdb)); printf("free block pool: %u\n", tchdbfbpmax(hdb)); printf("inode number: %" PRId64 "\n", (int64_t) tchdbinode(hdb)); char date[48]; tcdatestrwww(tchdbmtime(hdb), INT_MAX, date); printf("modified time: %s\n", date); uint8_t opts = tchdbopts(hdb); printf("options:"); if (opts & HDBTLARGE) printf(" large"); if (opts & HDBTDEFLATE) printf(" deflate"); if (opts & HDBTBZIP) printf(" bzip"); if (opts & HDBTTCBS) printf(" tcbs"); if (opts & HDBTEXCODEC) printf(" excodec"); printf("\n"); printf("record number: %" PRIu64 "\n", (uint64_t) tchdbrnum(hdb)); printf("file size: %" PRIu64 "\n", (uint64_t) tchdbfsiz(hdb)); if (!tchdbclose(hdb)) { if (!err) printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }
/* perform inform command */ static int procinform(const char *path, int omode){ TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbopen(hdb, path, HDBOREADER | omode)){ printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; const char *npath = tchdbpath(hdb); if(!npath) npath = "(unknown)"; printf("path: %s\n", npath); const char *type = "(unknown)"; switch(tchdbtype(hdb)){ case HDBTHASH: type = "hash"; break; case HDBTBTREE: type = "btree"; break; } printf("database type: %s\n", type); uint8_t flags = tchdbflags(hdb); printf("additional flags:"); if(flags & HDBFOPEN) printf(" open"); if(flags & HDBFFATAL) printf(" fatal"); printf("\n"); printf("bucket number: %llu\n", (unsigned long long)tchdbbnum(hdb)); if(hdb->cnt_writerec >= 0) printf("used bucket number: %lld\n", (long long)tchdbbnumused(hdb)); printf("alignment: %u\n", tchdbalign(hdb)); printf("free block pool: %u\n", tchdbfbpmax(hdb)); uint8_t opts = tchdbopts(hdb); printf("options:"); if(opts & HDBTLARGE) printf(" large"); if(opts & HDBTDEFLATE) printf(" deflate"); printf("\n"); printf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb)); printf("file size: %llu\n", (unsigned long long)tchdbfsiz(hdb)); if(!tchdbclose(hdb)){ if(!err) printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }