summaryrefslogtreecommitdiff
path: root/src/logic/tpax_archive_reset.c
blob: 52a9008bad5e052d0768cdc4d698303ccbf771d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**************************************************************/
/*  tpax: a topological pax implementation                    */
/*  Copyright (C) 2020--2024  SysDeer Technologies, LLC       */
/*  Released under GPLv2 and GPLv3; see COPYING.TPAX.         */
/**************************************************************/

#include <stdint.h>
#include <stdlib.h>
#include <sys/mman.h>

#include <tpax/tpax.h>
#include "tpax_driver_impl.h"

/**********************************************/
/* release and reset the following objects:   */
/*                                            */
/* - item queue                               */
/* - queue vector                             */
/* - cached prefixes                          */
/* - prefix vector                            */
/*                                            */
/**********************************************/

int tpax_archive_reset(const struct tpax_driver_ctx * dctx)
{
	struct tpax_driver_ctx_impl *   ictx;
	void *                          next;
	size_t                          size;
	char **                         ppref;

	ictx = tpax_get_driver_ictx(dctx);

	for (; ictx->dirents; ) {
		next = ictx->dirents->next;
		size = ictx->dirents->size;

		munmap(ictx->dirents,size);
		ictx->dirents = (struct tpax_dirent_buffer *)next;
	}

	for (ppref=ictx->prefixv; *ppref; ppref++)
		free(*ppref);

	for (ppref=ictx->prefptr; ppref<ictx->prefcap; ppref++)
		*ppref = 0;

	if (ictx->prefixv != ictx->prefptr)
		free(ictx->prefixv);

	if (ictx->direntv)
		free(ictx->direntv);

	ictx->nqueued = 0;
	ictx->dirents = 0;
	ictx->direntv = 0;
	ictx->prefixv = ictx->prefptr;

	return 0;
}