Debian Codegraph @

detect.c

raw symbols ◀ ▶
Source reconstructed at patch state 2 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 /*
2 * detect.c
3 * Detection dispatching
4 *
5 * Copyright (c) 2003 Christoph Pfisterer
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #include "global.h"
29
30 /*
31 * external detection functions
32 */
33
34 /* in amiga.c */
35 void detect_amiga_partmap(SECTION *section, int level);
36 void detect_amiga_fs(SECTION *section, int level);
37
38 /* in apple.c */
39 void detect_apple_partmap(SECTION *section, int level);
40 void detect_apple_volume(SECTION *section, int level);
41 void detect_udif(SECTION *section, int level);
42
43 /* in atari.c */
44 void detect_atari_partmap(SECTION *section, int level);
45
46 /* in dos.c */
47 void detect_dos_partmap(SECTION *section, int level);
48 void detect_gpt_partmap(SECTION *section, int level);
49 void detect_fat(SECTION *section, int level);
50 void detect_exfat(SECTION *section, int level);
51 void detect_ntfs(SECTION *section, int level);
52 void detect_hpfs(SECTION *section, int level);
53 void detect_dos_loader(SECTION *section, int level);
54
55 /* in cdrom.c */
56 void detect_iso(SECTION *section, int level);
57 void detect_cdrom_misc(SECTION *section, int level);
58
59 /* in udf.c */
60 void detect_udf(SECTION *section, int level);
61
62 /* in linux.c */
63 void detect_ext234(SECTION *section, int level);
64 void detect_btrfs(SECTION *section, int level);
65 void detect_reiser(SECTION *section, int level);
66 void detect_reiser4(SECTION *section, int level);
67 void detect_linux_raid(SECTION *section, int level);
68 void detect_linux_lvm(SECTION *section, int level);
69 void detect_linux_lvm2(SECTION *section, int level);
70 void detect_linux_swap(SECTION *section, int level);
71 void detect_linux_misc(SECTION *section, int level);
72 void detect_linux_loader(SECTION *section, int level);
73
74 /* in unix.c */
75 void detect_jfs(SECTION *section, int level);
76 void detect_xfs(SECTION *section, int level);
77 void detect_ufs(SECTION *section, int level);
78 void detect_sysv(SECTION *section, int level);
79 void detect_bsd_disklabel(SECTION *section, int level);
80 void detect_bsd_loader(SECTION *section, int level);
81 void detect_solaris_disklabel(SECTION *section, int level);
82 void detect_solaris_vtoc(SECTION *section, int level);
83 void detect_qnx(SECTION *section, int level);
84 void detect_vxfs(SECTION *section, int level);
85
86 /* in beos.c */
87 void detect_bfs(SECTION *section, int level);
88 void detect_beos_loader(SECTION *section, int level);
89
90 /* in compressed.c */
91 void detect_compressed(SECTION *section, int level);
92
93 /* in cdimage.c */
94 void detect_cdimage(SECTION *section, int level);
95
96 /* in vpc.c */
97 void detect_vhd(SECTION *section, int level);
98
99 /* in cloop.c */
100 void detect_cloop(SECTION *section, int level);
101
102 /* in archives.c */
103 void detect_archive(SECTION *section, int level);
104
105 /* in blank.c */
106 void detect_blank(SECTION *section, int level);
107
108 /*
109 * list of detectors
110 */
111
112 DETECTOR detectors[] = {
113 /* 1: disk image formats */
114 detect_vhd, /* may stop */
115 detect_cdimage, /* may stop */
116 detect_cloop,
117 detect_udif,
118 /* 2: boot code */
119 detect_linux_loader,
120 detect_bsd_loader,
121 detect_dos_loader,
122 detect_beos_loader,
123 /* 3: partition tables */
124 detect_bsd_disklabel, /* may stop, recurses with FLAG_IN_DISKLABEL */
125 detect_solaris_disklabel, /* may stop, recurses with FLAG_IN_DISKLABEL */
126 detect_solaris_vtoc,
127 detect_amiga_partmap,
128 detect_apple_partmap,
129 detect_atari_partmap,
130 detect_dos_partmap,
131 detect_gpt_partmap,
132 /* 4: file systems */
133 detect_amiga_fs,
134 detect_apple_volume,
135 detect_fat,
136 detect_exfat,
137 detect_ntfs,
138 detect_hpfs,
139 detect_udf,
140 detect_cdrom_misc,
141 detect_iso,
142 detect_ext234,
143 detect_btrfs,
144 detect_reiser,
145 detect_reiser4,
146 detect_linux_raid,
147 detect_linux_lvm,
148 detect_linux_lvm2,
149 detect_linux_swap,
150 detect_linux_misc,
151 detect_jfs,
152 detect_xfs,
153 detect_ufs,
154 detect_sysv,
155 detect_qnx,
156 detect_vxfs,
157 detect_bfs,
158 /* 5: file formats */
159 detect_archive,
160 detect_compressed, /* this is down here because of boot disks */
161 /* 6: blank formatted disk */
162 detect_blank,
163
164 NULL };
165
166
167 /*
168 * internal stuff
169 */
170
171 static void detect(SECTION *section, int level);
172
173 static int stop_flag = 0;
174
175 /*
176 * analyze a given source
177 */
178
179 void analyze_source(SOURCE *s, int level)
180 {
181 SECTION section;
182
183 /* Allow custom analyzing using special info available to the
184 data source implementation. The analyze() function must either
185 call through to analyze_source_special() or return zero. */
186 if (s->analyze != NULL) {
187 if ((*s->analyze)(s, level))
188 return;
189 }
190
191 section.source = s;
192 section.pos = 0;
193 section.size = s->size_known ? s->size : 0;
194 section.flags = 0;
195
196 detect(&section, level);
197 }
198
199 /*
200 * analyze part of a given source
201 */
202
203 void analyze_source_special(SOURCE *s, int level, u8 pos, u8 size)
204 {
205 SECTION section;
206
207 section.source = s;
208 section.pos = pos;
209 section.size = size;
210 section.flags = 0;
211
212 detect(&section, level);
213 }
214
215 /*
216 * recursively analyze a portion of a SECTION
217 */
218
219 void analyze_recursive(SECTION *section, int level,
220 u8 rel_pos, u8 size, int flags)
221 {
222 SOURCE *s;
223 SECTION rs;
224
225 /* sanity */
226 if (rel_pos == 0 && (flags & FLAG_IN_DISKLABEL) == 0)
227 return;
228 s = section->source;
229 if (s->size_known && (section->pos + rel_pos >= s->size))
230 return;
231
232 rs.source = s;
233 rs.pos = section->pos + rel_pos;
234 rs.size = size;
235 rs.flags = section->flags | flags;
236
237 detect(&rs, level);
238 }
239
240 /*
241 * detection dispatching
242 */
243
244 static void detect(SECTION *section, int level)
245 {
246 int i;
247
248 /* run the modularized detectors */
249 for (i = 0; detectors[i] && !stop_flag; i++)
250 (*detectors[i])(section, level);
251 stop_flag = 0;
252 }
253
254 /*
255 * break the detection loop
256 */
257
258 void stop_detect(void)
259 {
260 stop_flag = 1;
261 }
262
263 /* EOF */