summaryrefslogtreecommitdiff
path: root/libblkid-tiny/probe.c
blob: ae7e7088f36d39556ce8411b5e5d09f2e053be63 (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
/*
 * Low-level libblkid probing API
 *
 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
 *
 * This file may be redistributed under the terms of the
 * GNU Lesser General Public License.
 */

#include <stdlib.h>

#include "blkidP.h"
#include "libblkid-tiny.h"

static int blkid_probe_reset_buffers(struct blkid_struct_probe *pr);

struct blkid_struct_probe *blkid_new_probe(void)
{
	struct blkid_struct_probe *pr;

	pr = calloc(1, sizeof(struct blkid_struct_probe));
	if (!pr)
		return NULL;

	INIT_LIST_HEAD(&pr->buffers);

	return pr;
}

void blkid_free_probe(struct blkid_struct_probe *pr)
{
	if (!pr)
		return;

	blkid_probe_reset_buffers(pr);

	free(pr);
}

static int blkid_probe_reset_buffers(struct blkid_struct_probe *pr)
{
	if (list_empty(&pr->buffers))
		return 0;

	while (!list_empty(&pr->buffers)) {
		struct blkid_bufinfo *bf = list_first_entry(&pr->buffers, struct blkid_bufinfo, bufs);

		list_del(&bf->bufs);

		free(bf);
	}

	return 0;
}