Debian Codegraph @

detect.c

raw symbols ◀ ▶ SCIP
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 /* in f2fs.c */
109 void detect_f2fs(SECTION *section, int level);
110
111 /*
112 * list of detectors
113 */
114
115 DETECTOR detectors[] = {
116 /* 1: disk image formats */
117 detect_vhd, /* may stop */
118 detect_cdimage, /* may stop */
119 detect_cloop,
120 detect_udif,
121 /* 2: boot code */
122 detect_linux_loader,
123 detect_bsd_loader,
124 detect_dos_loader,
125 detect_beos_loader,
126 /* 3: partition tables */
127 detect_bsd_disklabel, /* may stop, recurses with FLAG_IN_DISKLABEL */
128 detect_solaris_disklabel, /* may stop, recurses with FLAG_IN_DISKLABEL */
129 detect_solaris_vtoc,
130 detect_amiga_partmap,
131 detect_apple_partmap,
132 detect_atari_partmap,
133 detect_dos_partmap,
134 detect_gpt_partmap,
135 /* 4: file systems */
136 detect_amiga_fs,
137 detect_apple_volume,
138 detect_fat,
•139 detect_exfat,
140 detect_ntfs,
141 detect_hpfs,
142 detect_udf,
143 detect_cdrom_misc,
144 detect_iso,
•145 detect_ext234,
146 detect_btrfs,
147 detect_reiser,
148 detect_reiser4,
149 detect_linux_raid,
150 detect_linux_lvm,
151 detect_linux_lvm2,
152 detect_linux_swap,
153 detect_linux_misc,
•154 detect_f2fs,
155 detect_jfs,
156 detect_xfs,
157 detect_ufs,
158 detect_sysv,
159 detect_qnx,
160 detect_vxfs,
161 detect_bfs,
162 /* 5: file formats */
163 detect_archive,
•164 detect_compressed, /* this is down here because of boot disks */
165 /* 6: blank formatted disk */
166 detect_blank,
167
168 NULL };
169
170
171 /*
172 * internal stuff
173 */
174
175 static void detect(SECTION *section, int level);
176
177 static int stop_flag = 0;
178
179 /*
180 * analyze a given source
181 */
182
183 void analyze_source(SOURCE *s, int level)
184 {
185 SECTION section;
186
187 /* Allow custom analyzing using special info available to the
188 data source implementation. The analyze() function must either
189 call through to analyze_source_special() or return zero. */
190 if (s->analyze != NULL) {
191 if ((*s->analyze)(s, level))
192 return;
193 }
194
195 section.source = s;
196 section.pos = 0;
197 section.size = s->size_known ? s->size : 0;
198 section.flags = 0;
199
200 detect(&section, level);
201 }
202
203 /*
204 * analyze part of a given source
205 */
206
207 void analyze_source_special(SOURCE *s, int level, u8 pos, u8 size)
208 {
209 SECTION section;
210
211 section.source = s;
212 section.pos = pos;
213 section.size = size;
214 section.flags = 0;
215
216 detect(&section, level);
217 }
218
219 /*
220 * recursively analyze a portion of a SECTION
221 */
222
223 void analyze_recursive(SECTION *section, int level,
224 u8 rel_pos, u8 size, int flags)
225 {
226 SOURCE *s;
227 SECTION rs;
228
229 /* sanity */
230 if (rel_pos == 0 && (flags & FLAG_IN_DISKLABEL) == 0)
231 return;
232 s = section->source;
233 if (s->size_known && (section->pos + rel_pos >= s->size))
234 return;
235
236 rs.source = s;
237 rs.pos = section->pos + rel_pos;
238 rs.size = size;
239 rs.flags = section->flags | flags;
240
241 detect(&rs, level);
242 }
243
244 /*
245 * detection dispatching
246 */
247
248 static void detect(SECTION *section, int level)
249 {
250 int i;
251
252 /* run the modularized detectors */
253 for (i = 0; detectors[i] && !stop_flag; i++)
254 (*detectors[i])(section, level);
255 stop_flag = 0;
256 }
257
258 /*
259 * break the detection loop
260 */
261
262 void stop_detect(void)
263 {
264 stop_flag = 1;
265 }
266
267 /* EOF */