int database_flush() { if (!config->db_persist) return 0; pthread_mutex_lock(&lock); FILE *fp = fopen(DATA_DIR "/database.txt", "w"); if (!fp) return 1; for (struct lnode *cur = listend(file_list); cur; cur = cur->prev){ struct file_entry *fe = cur->data; fprintf(fp, "%llx %zu %s %s\n", fe->id, fe->len, fe->ext[0] ? fe->ext : "NULL", fe->hash); } fclose(fp); pthread_mutex_unlock(&lock); return 0; }
struct client_ctx *queue_pop() { pthread_mutex_lock(&avail_lock); if (!client_queue) pthread_cond_wait(&avail_cond, &avail_lock); struct lnode *n = lnode_pop(listend(client_queue)); struct client_ctx *cc = n->data; queue_size--; free(n); if (n == client_queue) client_queue = 0; pthread_mutex_unlock(&avail_lock); return cc; }
/** * Create a deleted node with its parent, not for an orphan node. */ void Ntfs::_createDeletedWithParent(std::string fileNameS, std::list<uint64_t> pathRefs, uint32_t mftEntry, AttributeFileName *fileName, AttributeData *data, bool file, AttributeStandardInformation *SI, uint64_t offset) { NtfsNode *current = _root; std::list<uint64_t>::const_iterator iter(pathRefs.begin()); std::list<uint64_t>::const_iterator listend(pathRefs.end()); std::string dirName; Attribute *attribute; AttributeFileName *metaFileName = NULL; AttributeStandardInformation *metaSI = NULL; NtfsNode *checkNode = NULL; uint32_t parentId; NtfsNode *newFile; MftEntry *parent; /** * Iter every parents */ while (iter != listend) { if (!(parent = _mftMainFile->get(*iter))) { break; } // parent->dumpHeader(); while ((attribute = parent->getNextAttribute())) { attribute->readHeader(); if (attribute->getType() == ATTRIBUTE_FILE_NAME) { /** * Read parent directory name */ if (metaFileName != NULL) { delete metaFileName; } metaFileName = new AttributeFileName(*attribute); if (metaFileName->data()->nameSpace & ATTRIBUTE_FN_NAMESPACE_WIN32 || metaFileName->data()->nameSpace == ATTRIBUTE_FN_NAMESPACE_POSIX) { dirName = metaFileName->getFileName(); DEBUG(INFO, "filename PARENT %s flags 0x%x\n", metaFileName->getFileName().c_str(), metaFileName->data()->flags); } } if (attribute->getType() == ATTRIBUTE_STANDARD_INFORMATION) { metaSI = new AttributeStandardInformation(*attribute); } } /** * Check if parent exists in current directory, create it if needed */ if ((checkNode = _ntfsNodeExists(dirName, current)) == NULL) { #if __WORDSIZE == 64 parentId = (*iter) & 0xffffffUL; #else parentId = (*iter) & 0xffffffULL; #endif _mftMainFile->entryDiscovered(parentId); current = new NtfsNode(dirName.c_str(), 0, current, this, false, metaFileName, metaSI, parent, parentId, _mftMainFile->data()->offsetFromID(parentId)); //XXX _mftMainFile->entryDiscovered(id); DEBUG(INFO, "creating %s as deleted\n", dirName.c_str()); current->setDeleted(); } else { current = checkNode; } ++iter; } DEBUG(INFO, "%s in %s\n", fileName->getFileName().c_str(), current->name().c_str()); if (_ntfsNodeExists(fileNameS, current) == NULL || !_mftMainFile->isEntryDiscovered(mftEntry)) { newFile = new NtfsNode(fileNameS, data->getSize(), current, this, file, fileName, SI, _mftEntry, mftEntry, offset); DEBUG(INFO, "Created (usual) node : %s in %s\n", fileName->getFileName().c_str(), "tmp"); newFile->node(_node); if (file) { newFile->data(data); } DEBUG(INFO, "creating %s as deleted in current2\n", fileName->getFileName().c_str()); newFile->setDeleted(); } }