static couchstore_error_t local_doc_print(couchfile_lookup_request *rq, const sized_buf *k, const sized_buf *v) { int* count = (int*) rq->callback_ctx; if (!v) { return COUCHSTORE_ERROR_DOC_NOT_FOUND; } (*count)++; sized_buf *id = (sized_buf *) k; if (dumpJson) { printf("{\"id\":\""); printjquote(id); printf("\","); } else { printf("Key: "); printsb(id); } if (dumpJson) { printf("\"value\":\""); printjquote(v); printf("\"}\n"); } else { printf("Value: "); printsb(v); printf("\n"); } return COUCHSTORE_SUCCESS; }
static int foldprint(Db *db, DocInfo *docinfo, void *ctx) { int *count = (int *) ctx; (*count)++; Doc *doc = NULL; uint64_t cas; uint32_t expiry, flags; if (mode == DumpBySequence) { printf("Doc seq: %"PRIu64"\n", docinfo->db_seq); printf(" id: "); printsb(&docinfo->id); } else { printf(" Doc ID: "); printsb(&docinfo->id); if (docinfo->db_seq > 0) { printf(" seq: %"PRIu64"\n", docinfo->db_seq); } } if (docinfo->bp == 0 && docinfo->deleted == 0) { printf(" ** This b-tree node is corrupt; raw node value follows:*\n"); printf(" raw: "); printsbhex(&docinfo->rev_meta, 1); return 0; } printf(" rev: %"PRIu64"\n", docinfo->rev_seq); printf(" content_meta: %d\n", docinfo->content_meta); if (docinfo->rev_meta.size == sizeof(CouchbaseRevMeta)) { const CouchbaseRevMeta* meta = (const CouchbaseRevMeta*)docinfo->rev_meta.buf; cas = decode_raw64(meta->cas); expiry = decode_raw32(meta->expiry); flags = decode_raw32(meta->flags); printf(" cas: %"PRIu64", expiry: %"PRIu32", flags: %"PRIu32"\n", cas, expiry, flags); } if (docinfo->deleted) { printf(" doc deleted\n"); } couchstore_error_t docerr = couchstore_open_doc_with_docinfo(db, docinfo, &doc, 0); if(docerr != COUCHSTORE_SUCCESS) { printf(" could not read document body: %s\n", couchstore_strerror(docerr)); } else if (doc && (docinfo->content_meta & COUCH_DOC_IS_COMPRESSED)) { size_t rlen; snappy_uncompressed_length(doc->data.buf, doc->data.size, &rlen); char *decbuf = (char *) malloc(rlen); size_t uncompr_len; snappy_uncompress(doc->data.buf, doc->data.size, decbuf, &uncompr_len); printf(" data: (snappy) %.*s\n", (int) uncompr_len, decbuf); free(decbuf); } else if(doc) { printf(" data: "); printsb(&doc->data); } couchstore_free_document(doc); return 0; }
static int visit_node(Db *db, int depth, const DocInfo* docinfo, uint64_t subtreeSize, const sized_buf* reduceValue, void *ctx) { (void) db; for (int i = 0; i < depth; ++i) printf(" "); if (reduceValue) { // This is a tree node: printf("+ (%llu) ", (unsigned long long) subtreeSize); printsbhex(reduceValue, 0); } else if (docinfo->bp > 0) { // This is a document: printf("%c (%llu) ", (docinfo->deleted ? 'x' : '*'), (unsigned long long) docinfo->size); if (mode == DumpBySequence) { printf("#%llu ", (unsigned long long) docinfo->db_seq); } printsb(&docinfo->id); int *count = (int *) ctx; (*count)++; } else { // Document, but not in a known format: printf("**corrupt?** "); printsbhex(&docinfo->rev_meta, 1); } return 0; }
int main(int argc, char* argv[]) { int fd = open("fs.img", O_RDWR); if (fd < 0) { printf("error: fd < 0\n"); } struct superblock* sb; sb = (struct superblock*)(malloc(sizeof(struct superblock))); if (lseek(fd, BSIZE, SEEK_SET) < 0) { printf("error: lseek failed\n"); } if (read(fd, sb, sizeof(struct superblock)) < 0) { printf("error: read failed\n"); } printsb(sb); //inode struct struct dinode* dn; dn = (struct dinode*)(malloc(sizeof(struct dinode))); if ( lseek(fd, BSIZE * 2, SEEK_SET) < 0) { printf("error: lseek failed\n"); } if (read(fd, dn, 200 * sizeof(struct dinode)) < 0) { printf("error: read failed\n"); } printf("inode0 is reserved. Not printing.\n"); int inode_cnt; for(inode_cnt = 1; inode_cnt < 200; inode_cnt++) { dn++; printf("inode%d\n", inode_cnt); printdn(dn); } /* dn++; printf("inode%d\n", 1); printdn(dn); dn++; printf("inode%d\n", 2); printdn(dn); dn++; printf("inode%d\n", 3); printdn(dn); dn++; printf("inode%d\n", 4); printdn(dn); */ //dirent struct //struct dirent* dir; //dir = (struct dirent*)(malloc(sizeof(struct dirent))); char bitmap[512]; if ( lseek(fd, BSIZE * 28, SEEK_SET) < 0) { printf("error: lseek failed\n"); } if (read(fd, &bitmap, BSIZE) < 0) { printf("error: read failed\n"); } //printf("dirent%d\n",1); //printdir(dir); printf("====\nBit map is:\n"); int j; for(j = 0; j<512; j++) { printf("bitmap[%d] is : %c\n",j, bitmap[j]); } return 0; }
static int foldprint(Db *db, DocInfo *docinfo, void *ctx) { int *count = (int *) ctx; Doc *doc = NULL; uint64_t cas; uint32_t expiry, flags; couchstore_error_t docerr; (*count)++; if (dumpJson) { printf("{\"seq\":%"PRIu64",\"id\":\"", docinfo->db_seq); printjquote(&docinfo->id); printf("\","); } else { if (mode == DumpBySequence) { printf("Doc seq: %"PRIu64"\n", docinfo->db_seq); printf(" id: "); printsb(&docinfo->id); } else { printf(" Doc ID: "); printsb(&docinfo->id); if (docinfo->db_seq > 0) { printf(" seq: %"PRIu64"\n", docinfo->db_seq); } } } if (docinfo->bp == 0 && docinfo->deleted == 0 && !dumpJson) { printf(" ** This b-tree node is corrupt; raw node value follows:*\n"); printf(" raw: "); printsbhex(&docinfo->rev_meta, 1); return 0; } if (dumpJson) { printf("\"rev\":%"PRIu64",\"content_meta\":%d,", docinfo->rev_seq, docinfo->content_meta); printf("\"physical_size\":%zu,", docinfo->size); } else { printf(" rev: %"PRIu64"\n", docinfo->rev_seq); printf(" content_meta: %d\n", docinfo->content_meta); printf(" size (on disk): %zu\n", docinfo->size); } if (docinfo->rev_meta.size >= sizeof(CouchbaseRevMeta)) { const CouchbaseRevMeta* meta = (const CouchbaseRevMeta*)docinfo->rev_meta.buf; cas = decode_raw64(meta->cas); expiry = decode_raw32(meta->expiry); flags = decode_raw32(meta->flags); if (dumpJson) { printf("\"cas\":\"%"PRIu64"\",\"expiry\":%"PRIu32",\"flags\":%"PRIu32",", cas, expiry, flags); } else { printf(" cas: %"PRIu64", expiry: %"PRIu32", flags: %"PRIu32"\n", cas, expiry, flags); } } if (docinfo->deleted) { if (dumpJson) { printf("\"deleted\":true,"); } else { printf(" doc deleted\n"); } } if (!noBody) { docerr = couchstore_open_doc_with_docinfo(db, docinfo, &doc, 0); if (docerr != COUCHSTORE_SUCCESS) { if (dumpJson) { printf("\"body\":null}\n"); } else { printf(" could not read document body: %s\n", couchstore_strerror(docerr)); } } else if (doc && (docinfo->content_meta & COUCH_DOC_IS_COMPRESSED)) { size_t rlen; snappy_uncompressed_length(doc->data.buf, doc->data.size, &rlen); char *decbuf = (char *) malloc(rlen); size_t uncompr_len; snappy_uncompress(doc->data.buf, doc->data.size, decbuf, &uncompr_len); sized_buf uncompr_body; uncompr_body.size = uncompr_len; uncompr_body.buf = decbuf; if (dumpJson) { printf("\"size\":%zu,", uncompr_body.size); printf("\"snappy\":true,\"body\":\""); if (dumpHex) { printsbhexraw(&uncompr_body); } else { printjquote(&uncompr_body); } printf("\"}\n"); } else { printf(" size: %zu\n", uncompr_body.size); printf(" data: (snappy) "); if (dumpHex) { printsbhexraw(&uncompr_body); printf("\n"); } else { printsb(&uncompr_body); } } } else if (doc) { if (dumpJson) { printf("\"size\":%zu,", doc->data.size); printf("\"body\":\""); printjquote(&doc->data); printf("\"}\n"); } else { printf(" size: %zu\n", doc->data.size); printf(" data: "); if (dumpHex) { printsbhexraw(&doc->data); printf("\n"); } else { printsb(&doc->data); } } } } else { if (dumpJson) { printf("\"body\":null}\n"); } else { printf("\n"); } } couchstore_free_document(doc); return 0; }