void MessageStorage::initialize(char * storageRoot, bool deleteOldQueue)
{
	if(storageRoot == NULL)
	{
		module_debug_strg("cannot work without storage root!");
		return;
	}
	
	strcpy(m_storageRoot, storageRoot);
	
	// mount the actual storage device we use for storing data
	module_debug_strg("mounting storage...");
	if(mountStorage())
		module_debug_strg("storage available!");
	else
		module_debug_strg("storage not available!");
	
	uint8_t cnt = 15;
	
	module_debug_strg("starting speed tests...");
	while(cnt--)
		FATFS_speedTest(8);
	
	module_debug_strg("end of speed tests...");
	
	module_debug_strg("changing to storage root: %s", m_storageRoot);
	// change to storage root
	changeDirectory(m_storageRoot);
	
	module_debug_strg("creating storage subdirs...");
	// create subdirectories
	createDirectory(SUBDIR_QUEUE);
	createDirectory(SUBDIR_AUDIO);
	createDirectory(SUBDIR_LOG);
	
	
	// count list of existing files in storage root,
	module_debug_strg("counting files...");
	
	// count disk files on queue
	m_queueCount = traverseDirectory(SUBDIR_QUEUE, &m_nextMessageSeqNumber, deleteOldQueue);
	
	// traverse audio samples as well to find latest seq number there
	// hardcoded to not remove old files, gut sound is a valuable commodity...
	traverseDirectory(SUBDIR_AUDIO, &m_nextAudioSeqNumber, false);
}
void BlobStorage::synchronize()
{
    ASSERT(!RunLoop::isMain());

    WebCore::makeAllDirectories(blobDirectoryPath());

    m_approximateSize = 0;
    auto blobDirectory = blobDirectoryPath();
    traverseDirectory(blobDirectory, DT_REG, [this, &blobDirectory](const String& name) {
        auto path = WebCore::pathByAppendingComponent(blobDirectory, name);
        auto filePath = WebCore::fileSystemRepresentation(path);
        struct stat stat;
        ::stat(filePath.data(), &stat);
        // No clients left for this blob.
        if (stat.st_nlink == 1)
            unlink(filePath.data());
        else
            m_approximateSize += stat.st_size;
    });

    LOG(NetworkCacheStorage, "(NetworkProcess) blob synchronization completed approximateSize=%zu", approximateSize());
}