libblkid-tiny: use separated buffer for each block device read
[project/fstools.git] / libblkid-tiny / probe.c
1 /*
2 * Low-level libblkid probing API
3 *
4 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
5 *
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
8 */
9
10 #include <stdlib.h>
11
12 #include "blkidP.h"
13 #include "libblkid-tiny.h"
14
15 static int blkid_probe_reset_buffers(struct blkid_struct_probe *pr);
16
17 struct blkid_struct_probe *blkid_new_probe(void)
18 {
19 struct blkid_struct_probe *pr;
20
21 pr = calloc(1, sizeof(struct blkid_struct_probe));
22 if (!pr)
23 return NULL;
24
25 INIT_LIST_HEAD(&pr->buffers);
26
27 return pr;
28 }
29
30 void blkid_free_probe(struct blkid_struct_probe *pr)
31 {
32 if (!pr)
33 return;
34
35 blkid_probe_reset_buffers(pr);
36
37 free(pr);
38 }
39
40 static int blkid_probe_reset_buffers(struct blkid_struct_probe *pr)
41 {
42 if (list_empty(&pr->buffers))
43 return 0;
44
45 while (!list_empty(&pr->buffers)) {
46 struct blkid_bufinfo *bf = list_first_entry(&pr->buffers, struct blkid_bufinfo, bufs);
47
48 list_del(&bf->bufs);
49
50 free(bf);
51 }
52
53 return 0;
54 }