diff options
Diffstat (limited to 'e2fsprogs/old_e2fsprogs/blkid/dev.c')
-rw-r--r-- | e2fsprogs/old_e2fsprogs/blkid/dev.c | 212 |
1 files changed, 0 insertions, 212 deletions
diff --git a/e2fsprogs/old_e2fsprogs/blkid/dev.c b/e2fsprogs/old_e2fsprogs/blkid/dev.c deleted file mode 100644 index c2bbb06f3..000000000 --- a/e2fsprogs/old_e2fsprogs/blkid/dev.c +++ /dev/null | |||
@@ -1,212 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * dev.c - allocation/initialization/free routines for dev | ||
4 | * | ||
5 | * Copyright (C) 2001 Andreas Dilger | ||
6 | * Copyright (C) 2003 Theodore Ts'o | ||
7 | * | ||
8 | * %Begin-Header% | ||
9 | * This file may be redistributed under the terms of the | ||
10 | * GNU Lesser General Public License. | ||
11 | * %End-Header% | ||
12 | */ | ||
13 | |||
14 | #include <stdlib.h> | ||
15 | #include <string.h> | ||
16 | |||
17 | #include "blkidP.h" | ||
18 | |||
19 | blkid_dev blkid_new_dev(void) | ||
20 | { | ||
21 | blkid_dev dev; | ||
22 | |||
23 | dev = xzalloc(sizeof(struct blkid_struct_dev)); | ||
24 | |||
25 | INIT_LIST_HEAD(&dev->bid_devs); | ||
26 | INIT_LIST_HEAD(&dev->bid_tags); | ||
27 | |||
28 | return dev; | ||
29 | } | ||
30 | |||
31 | void blkid_free_dev(blkid_dev dev) | ||
32 | { | ||
33 | if (!dev) | ||
34 | return; | ||
35 | |||
36 | DBG(DEBUG_DEV, | ||
37 | printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type)); | ||
38 | DBG(DEBUG_DEV, blkid_debug_dump_dev(dev)); | ||
39 | |||
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, | ||
44 | bit_tags); | ||
45 | blkid_free_tag(tag); | ||
46 | } | ||
47 | free(dev->bid_name); | ||
48 | free(dev); | ||
49 | } | ||
50 | |||
51 | /* | ||
52 | * Given a blkid device, return its name | ||
53 | */ | ||
54 | const char *blkid_dev_devname(blkid_dev dev) | ||
55 | { | ||
56 | return dev->bid_name; | ||
57 | } | ||
58 | |||
59 | #ifdef CONFIG_BLKID_DEBUG | ||
60 | void blkid_debug_dump_dev(blkid_dev dev) | ||
61 | { | ||
62 | struct list_head *p; | ||
63 | |||
64 | if (!dev) { | ||
65 | printf(" dev: NULL\n"); | ||
66 | return; | ||
67 | } | ||
68 | |||
69 | printf(" dev: name = %s\n", dev->bid_name); | ||
70 | printf(" dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno); | ||
71 | printf(" dev: TIME=\"%lu\"\n", dev->bid_time); | ||
72 | printf(" dev: PRI=\"%d\"\n", dev->bid_pri); | ||
73 | printf(" dev: flags = 0x%08X\n", dev->bid_flags); | ||
74 | |||
75 | list_for_each(p, &dev->bid_tags) { | ||
76 | blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags); | ||
77 | if (tag) | ||
78 | printf(" tag: %s=\"%s\"\n", tag->bit_name, | ||
79 | tag->bit_val); | ||
80 | else | ||
81 | printf(" tag: NULL\n"); | ||
82 | } | ||
83 | bb_putchar('\n'); | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | /* | ||
88 | * dev iteration routines for the public libblkid interface. | ||
89 | * | ||
90 | * These routines do not expose the list.h implementation, which are a | ||
91 | * contamination of the namespace, and which force us to reveal far, far | ||
92 | * too much of our internal implementation. I'm not convinced I want | ||
93 | * to keep list.h in the long term, anyway. It's fine for kernel | ||
94 | * programming, but performance is not the #1 priority for this | ||
95 | * library, and I really don't like the tradeoff of type-safety for | ||
96 | * performance for this application. [tytso:20030125.2007EST] | ||
97 | */ | ||
98 | |||
99 | /* | ||
100 | * This series of functions iterate over all devices in a blkid cache | ||
101 | */ | ||
102 | #define DEV_ITERATE_MAGIC 0x01a5284c | ||
103 | |||
104 | struct blkid_struct_dev_iterate { | ||
105 | int magic; | ||
106 | blkid_cache cache; | ||
107 | struct list_head *p; | ||
108 | }; | ||
109 | |||
110 | blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache) | ||
111 | { | ||
112 | blkid_dev_iterate iter; | ||
113 | |||
114 | iter = xmalloc(sizeof(struct blkid_struct_dev_iterate)); | ||
115 | iter->magic = DEV_ITERATE_MAGIC; | ||
116 | iter->cache = cache; | ||
117 | iter->p = cache->bic_devs.next; | ||
118 | return iter; | ||
119 | } | ||
120 | |||
121 | /* | ||
122 | * Return 0 on success, -1 on error | ||
123 | */ | ||
124 | extern int blkid_dev_next(blkid_dev_iterate iter, | ||
125 | blkid_dev *dev) | ||
126 | { | ||
127 | *dev = 0; | ||
128 | if (!iter || iter->magic != DEV_ITERATE_MAGIC || | ||
129 | iter->p == &iter->cache->bic_devs) | ||
130 | return -1; | ||
131 | *dev = list_entry(iter->p, struct blkid_struct_dev, bid_devs); | ||
132 | iter->p = iter->p->next; | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | void blkid_dev_iterate_end(blkid_dev_iterate iter) | ||
137 | { | ||
138 | if (!iter || iter->magic != DEV_ITERATE_MAGIC) | ||
139 | return; | ||
140 | iter->magic = 0; | ||
141 | free(iter); | ||
142 | } | ||
143 | |||
144 | #ifdef TEST_PROGRAM | ||
145 | #ifdef HAVE_GETOPT_H | ||
146 | #include <getopt.h> | ||
147 | #else | ||
148 | extern char *optarg; | ||
149 | extern int optind; | ||
150 | #endif | ||
151 | |||
152 | void usage(char *prog) | ||
153 | { | ||
154 | fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog); | ||
155 | fprintf(stderr, "\tList all devices and exit\n"); | ||
156 | exit(1); | ||
157 | } | ||
158 | |||
159 | int main(int argc, char **argv) | ||
160 | { | ||
161 | blkid_dev_iterate iter; | ||
162 | blkid_cache cache = NULL; | ||
163 | blkid_dev dev; | ||
164 | int c, ret; | ||
165 | char *tmp; | ||
166 | char *file = NULL; | ||
167 | char *search_type = NULL; | ||
168 | char *search_value = NULL; | ||
169 | |||
170 | while ((c = getopt (argc, argv, "m:f:")) != EOF) | ||
171 | switch (c) { | ||
172 | case 'f': | ||
173 | file = optarg; | ||
174 | break; | ||
175 | case 'm': | ||
176 | blkid_debug_mask = strtoul (optarg, &tmp, 0); | ||
177 | if (*tmp) { | ||
178 | fprintf(stderr, "Invalid debug mask: %s\n", | ||
179 | optarg); | ||
180 | exit(1); | ||
181 | } | ||
182 | break; | ||
183 | case '?': | ||
184 | usage(argv[0]); | ||
185 | } | ||
186 | if (argc >= optind+2) { | ||
187 | search_type = argv[optind]; | ||
188 | search_value = argv[optind+1]; | ||
189 | optind += 2; | ||
190 | } | ||
191 | if (argc != optind) | ||
192 | usage(argv[0]); | ||
193 | |||
194 | if ((ret = blkid_get_cache(&cache, file)) != 0) { | ||
195 | fprintf(stderr, "%s: error creating cache (%d)\n", | ||
196 | argv[0], ret); | ||
197 | exit(1); | ||
198 | } | ||
199 | |||
200 | iter = blkid_dev_iterate_begin(cache); | ||
201 | if (search_type) | ||
202 | blkid_dev_set_search(iter, search_type, search_value); | ||
203 | while (blkid_dev_next(iter, &dev) == 0) { | ||
204 | printf("Device: %s\n", blkid_dev_devname(dev)); | ||
205 | } | ||
206 | blkid_dev_iterate_end(iter); | ||
207 | |||
208 | |||
209 | blkid_put_cache(cache); | ||
210 | return 0; | ||
211 | } | ||
212 | #endif | ||