2 * dev.c - allocation/initialization/free routines for dev
4 * Copyright (C) 2001 Andreas Dilger
5 * Copyright (C) 2003 Theodore Ts'o
8 * This file may be redistributed under the terms of the
9 * GNU Lesser General Public License.
18 blkid_dev blkid_new_dev(void)
22 if (!(dev = (blkid_dev) calloc(1, sizeof(struct blkid_struct_dev))))
25 INIT_LIST_HEAD(&dev->bid_devs);
26 INIT_LIST_HEAD(&dev->bid_tags);
31 void blkid_free_dev(blkid_dev dev)
37 printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
38 DEB_DUMP_DEV(DEBUG_DEV, dev);
40 list_del(&dev->bid_devs);
41 while (!list_empty(&dev->bid_tags)) {
42 blkid_tag tag = list_entry(dev->bid_tags.next,
43 struct blkid_struct_tag,
53 * Given a blkid device, return its name
55 extern const char *blkid_dev_devname(blkid_dev dev)
61 * dev iteration routines for the public libblkid interface.
63 * These routines do not expose the list.h implementation, which are a
64 * contamination of the namespace, and which force us to reveal far, far
65 * too much of our internal implemenation. I'm not convinced I want
66 * to keep list.h in the long term, anyway. It's fine for kernel
67 * programming, but performance is not the #1 priority for this
68 * library, and I really don't like the tradeoff of type-safety for
69 * performance for this application. [tytso:20030125.2007EST]
73 * This series of functions iterate over all devices in a blkid cache
75 #define DEV_ITERATE_MAGIC 0x01a5284c
77 struct blkid_struct_dev_iterate {
83 extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
85 blkid_dev_iterate iter;
87 iter = xmalloc(sizeof(struct blkid_struct_dev_iterate));
88 iter->magic = DEV_ITERATE_MAGIC;
90 iter->p = cache->bic_devs.next;
95 * Return 0 on success, -1 on error
97 extern int blkid_dev_next(blkid_dev_iterate iter,
101 if (!iter || iter->magic != DEV_ITERATE_MAGIC ||
102 iter->p == &iter->cache->bic_devs)
104 *dev = list_entry(iter->p, struct blkid_struct_dev, bid_devs);
105 iter->p = iter->p->next;
109 extern void blkid_dev_iterate_end(blkid_dev_iterate iter)
111 if (!iter || iter->magic != DEV_ITERATE_MAGIC)