Blame src/logic/tpax_archive_reset.c

cf351e
/**************************************************************/
cf351e
/*  tpax: a topological pax implementation                    */
cf351e
/*  Copyright (C) 2020--2024  SysDeer Technologies, LLC       */
cf351e
/*  Released under GPLv2 and GPLv3; see COPYING.TPAX.         */
cf351e
/**************************************************************/
cf351e
cf351e
#include <stdint.h>
cf351e
#include <stdlib.h>
cf351e
#include <sys/mman.h>
cf351e
cf351e
#include <tpax/tpax.h>
cf351e
#include "tpax_driver_impl.h"
cf351e
cf351e
/**********************************************/
cf351e
/* release and reset the following objects:   */
cf351e
/*                                            */
cf351e
/* - item queue                               */
cf351e
/* - queue vector                             */
cf351e
/* - cached prefixes                          */
cf351e
/* - prefix vector                            */
cf351e
/*                                            */
cf351e
/**********************************************/
cf351e
cf351e
int tpax_archive_reset(const struct tpax_driver_ctx * dctx)
cf351e
{
cf351e
	struct tpax_driver_ctx_impl *   ictx;
cf351e
	void *                          next;
cf351e
	size_t                          size;
cf351e
	char **                         ppref;
cf351e
cf351e
	ictx = tpax_get_driver_ictx(dctx);
cf351e
cf351e
	for (; ictx->dirents; ) {
cf351e
		next = ictx->dirents->next;
cf351e
		size = ictx->dirents->size;
cf351e
cf351e
		munmap(ictx->dirents,size);
cf351e
		ictx->dirents = (struct tpax_dirent_buffer *)next;
cf351e
	}
cf351e
cf351e
	for (ppref=ictx->prefixv; *ppref; ppref++)
cf351e
		free(*ppref);
cf351e
cf351e
	for (ppref=ictx->prefptr; ppref<ictx->prefcap; ppref++)
cf351e
		*ppref = 0;
cf351e
cf351e
	if (ictx->prefixv != ictx->prefptr)
cf351e
		free(ictx->prefixv);
cf351e
cf351e
	if (ictx->direntv)
cf351e
		free(ictx->direntv);
cf351e
cf351e
	ictx->nqueued = 0;
cf351e
	ictx->dirents = 0;
cf351e
	ictx->direntv = 0;
cf351e
	ictx->prefixv = ictx->prefptr;
cf351e
cf351e
	return 0;
cf351e
}