Deleted Added
full compact
boot0cfg.c (183487) boot0cfg.c (185579)
1/*
1/*
2 * Copyright (c) 2008 Luigi Rizzo
2 * Copyright (c) 1999 Robert Nordier
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
3 * Copyright (c) 1999 Robert Nordier
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/usr.sbin/boot0cfg/boot0cfg.c 183487 2008-09-30 07:18:49Z lulf $");
29__FBSDID("$FreeBSD: head/usr.sbin/boot0cfg/boot0cfg.c 185579 2008-12-03 14:53:59Z luigi $");
29
30#include <sys/param.h>
31#include <sys/disklabel.h>
32#include <sys/diskmbr.h>
33#include <sys/stat.h>
34
35#include <err.h>
36#include <errno.h>
37#include <fcntl.h>
38#include <libgeom.h>
39#include <paths.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <unistd.h>
44
45#define MBRSIZE 512 /* master boot record size */
46
30
31#include <sys/param.h>
32#include <sys/disklabel.h>
33#include <sys/diskmbr.h>
34#include <sys/stat.h>
35
36#include <err.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <libgeom.h>
40#include <paths.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <unistd.h>
45
46#define MBRSIZE 512 /* master boot record size */
47
47#define OFF_VERSION 0x1b0 /* offset: version number */
48#define OFF_OPT 0x1b9 /* offset: default boot option */
49#define OFF_DRIVE 0x1ba /* offset: setdrv drive */
50#define OFF_FLAGS 0x1bb /* offset: option flags */
51#define OFF_TICKS 0x1bc /* offset: clock ticks */
48#define OFF_VERSION 0x1b0 /* offset: version number, only boot0version */
49#define OFF_SERIAL 0x1b8 /* offset: volume serial number */
52#define OFF_PTBL 0x1be /* offset: partition table */
53#define OFF_MAGIC 0x1fe /* offset: magic number */
50#define OFF_PTBL 0x1be /* offset: partition table */
51#define OFF_MAGIC 0x1fe /* offset: magic number */
52/*
53 * Offsets to the parameters of the 512-byte boot block.
54 * For historical reasons they are set as macros
55 */
56struct opt_offsets {
57 int opt;
58 int drive;
59 int flags;
60 int ticks;
61};
54
62
63struct opt_offsets b0_ofs[] = {
64 { 0x0, 0x0, 0x0, 0x0 }, /* no boot block */
65 { 0x1b9, 0x1ba, 0x1bb, 0x1bc }, /* original block */
66 { 0x1b5, 0x1b6, 0x1b7, 0x1bc }, /* NT_SERIAL block */
67};
68
69int b0_ver; /* boot block version set by boot0bs */
70
71#define OFF_OPT (b0_ofs[b0_ver].opt) /* default boot option */
72#define OFF_DRIVE (b0_ofs[b0_ver].drive) /* setdrv drive */
73#define OFF_FLAGS (b0_ofs[b0_ver].flags) /* option flags */
74#define OFF_TICKS (b0_ofs[b0_ver].ticks) /* clock ticks */
75
76
55#define cv2(p) ((p)[0] | (p)[1] << 010)
56
57#define mk2(p, x) \
58 (p)[0] = (u_int8_t)(x), \
59 (p)[1] = (u_int8_t)((x) >> 010)
60
61static const struct {
62 const char *tok;

--- 13 unchanged lines hidden (view full) ---

76
77static int read_mbr(const char *, u_int8_t **, int);
78static void write_mbr(const char *, int, u_int8_t *, int);
79static void display_mbr(u_int8_t *);
80static int boot0version(const u_int8_t *);
81static int boot0bs(const u_int8_t *);
82static void stropt(const char *, int *, int *);
83static int argtoi(const char *, int, int, int);
77#define cv2(p) ((p)[0] | (p)[1] << 010)
78
79#define mk2(p, x) \
80 (p)[0] = (u_int8_t)(x), \
81 (p)[1] = (u_int8_t)((x) >> 010)
82
83static const struct {
84 const char *tok;

--- 13 unchanged lines hidden (view full) ---

98
99static int read_mbr(const char *, u_int8_t **, int);
100static void write_mbr(const char *, int, u_int8_t *, int);
101static void display_mbr(u_int8_t *);
102static int boot0version(const u_int8_t *);
103static int boot0bs(const u_int8_t *);
104static void stropt(const char *, int *, int *);
105static int argtoi(const char *, int, int, int);
106static int set_bell(u_int8_t *, int, int);
84static void usage(void);
85
107static void usage(void);
108
109unsigned vol_id[5]; /* 4 plus 1 for flag */
110
111int v_flag;
86/*
87 * Boot manager installation/configuration utility.
88 */
89int
90main(int argc, char *argv[])
91{
92 u_int8_t *mbr, *boot0;
93 int boot0_size, mbr_size;
94 const char *bpath, *fpath;
95 char *disk;
112/*
113 * Boot manager installation/configuration utility.
114 */
115int
116main(int argc, char *argv[])
117{
118 u_int8_t *mbr, *boot0;
119 int boot0_size, mbr_size;
120 const char *bpath, *fpath;
121 char *disk;
96 int B_flag, v_flag, o_flag;
122 int B_flag, o_flag;
97 int d_arg, m_arg, s_arg, t_arg;
123 int d_arg, m_arg, s_arg, t_arg;
98 int o_and, o_or;
124 int o_and, o_or, o_e = -1;
99 int up, c;
100
101 bpath = "/boot/boot0";
102 fpath = NULL;
103 B_flag = v_flag = o_flag = 0;
104 d_arg = m_arg = s_arg = t_arg = -1;
105 o_and = 0xff;
106 o_or = 0;
125 int up, c;
126
127 bpath = "/boot/boot0";
128 fpath = NULL;
129 B_flag = v_flag = o_flag = 0;
130 d_arg = m_arg = s_arg = t_arg = -1;
131 o_and = 0xff;
132 o_or = 0;
107 while ((c = getopt(argc, argv, "Bvb:d:f:m:o:s:t:")) != -1)
133 while ((c = getopt(argc, argv, "Bvb:d:e:f:i:m:o:s:t:")) != -1)
108 switch (c) {
109 case 'B':
110 B_flag = 1;
111 break;
112 case 'v':
113 v_flag = 1;
114 break;
115 case 'b':
116 bpath = optarg;
117 break;
118 case 'd':
119 d_arg = argtoi(optarg, 0, 0xff, 'd');
120 break;
134 switch (c) {
135 case 'B':
136 B_flag = 1;
137 break;
138 case 'v':
139 v_flag = 1;
140 break;
141 case 'b':
142 bpath = optarg;
143 break;
144 case 'd':
145 d_arg = argtoi(optarg, 0, 0xff, 'd');
146 break;
147 case 'e':
148 if (optarg[0] == '0' && optarg[1] == 'x')
149 sscanf(optarg, "0x%02x", &o_e);
150 else
151 o_e = optarg[0];
152 break;
121 case 'f':
122 fpath = optarg;
123 break;
153 case 'f':
154 fpath = optarg;
155 break;
156 case 'i':
157 if (sscanf(optarg, "%02x%02x-%02x%02x",
158 vol_id, vol_id+1, vol_id+2, vol_id+3) == 4)
159 vol_id[4] = 1;
160 else
161 errx(1, "bad argument %s", optarg);
162 break;
124 case 'm':
125 m_arg = argtoi(optarg, 0, 0xf, 'm');
126 break;
127 case 'o':
128 stropt(optarg, &o_and, &o_or);
129 o_flag = 1;
130 break;
131 case 's':

--- 10 unchanged lines hidden (view full) ---

142 if (argc != 1)
143 usage();
144 disk = g_device_path(*argv);
145 if (disk == NULL)
146 errx(1, "Unable to get providername for %s\n", *argv);
147 up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1
148 || t_arg != -1;
149
163 case 'm':
164 m_arg = argtoi(optarg, 0, 0xf, 'm');
165 break;
166 case 'o':
167 stropt(optarg, &o_and, &o_or);
168 o_flag = 1;
169 break;
170 case 's':

--- 10 unchanged lines hidden (view full) ---

181 if (argc != 1)
182 usage();
183 disk = g_device_path(*argv);
184 if (disk == NULL)
185 errx(1, "Unable to get providername for %s\n", *argv);
186 up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1
187 || t_arg != -1;
188
150 /* open the disk and read in the existing mbr */
189 /* open the disk and read in the existing mbr. Either here or
190 * when reading the block from disk, we do check for the version
191 * and abort if a suitable block is not found.
192 */
151 mbr_size = read_mbr(disk, &mbr, !B_flag);
152
153 /* save the existing MBR if we are asked to do so */
154 if (fpath)
155 write_mbr(fpath, O_CREAT | O_TRUNC, mbr, mbr_size);
156
157 /*
158 * If we are installing the boot loader, read it from disk and copy the
159 * slice table over from the existing MBR. If not, then point boot0
160 * back at the MBR we just read in. After this, boot0 is the data to
161 * write back to disk if we are going to do a write.
162 */
163 if (B_flag) {
164 boot0_size = read_mbr(bpath, &boot0, 1);
165 memcpy(boot0 + OFF_PTBL, mbr + OFF_PTBL,
166 sizeof(struct dos_partition) * NDOSPART);
193 mbr_size = read_mbr(disk, &mbr, !B_flag);
194
195 /* save the existing MBR if we are asked to do so */
196 if (fpath)
197 write_mbr(fpath, O_CREAT | O_TRUNC, mbr, mbr_size);
198
199 /*
200 * If we are installing the boot loader, read it from disk and copy the
201 * slice table over from the existing MBR. If not, then point boot0
202 * back at the MBR we just read in. After this, boot0 is the data to
203 * write back to disk if we are going to do a write.
204 */
205 if (B_flag) {
206 boot0_size = read_mbr(bpath, &boot0, 1);
207 memcpy(boot0 + OFF_PTBL, mbr + OFF_PTBL,
208 sizeof(struct dos_partition) * NDOSPART);
209 if (b0_ver == 2) /* volume serial number support */
210 memcpy(boot0 + OFF_SERIAL, mbr + OFF_SERIAL, 4);
167 } else {
168 boot0 = mbr;
169 boot0_size = mbr_size;
170 }
171
172 /* set the drive */
173 if (d_arg != -1)
174 boot0[OFF_DRIVE] = d_arg;

--- 11 unchanged lines hidden (view full) ---

186 /* set the default boot selection */
187 if (s_arg != -1)
188 boot0[OFF_OPT] = s_arg - 1;
189
190 /* set the timeout */
191 if (t_arg != -1)
192 mk2(boot0 + OFF_TICKS, t_arg);
193
211 } else {
212 boot0 = mbr;
213 boot0_size = mbr_size;
214 }
215
216 /* set the drive */
217 if (d_arg != -1)
218 boot0[OFF_DRIVE] = d_arg;

--- 11 unchanged lines hidden (view full) ---

230 /* set the default boot selection */
231 if (s_arg != -1)
232 boot0[OFF_OPT] = s_arg - 1;
233
234 /* set the timeout */
235 if (t_arg != -1)
236 mk2(boot0 + OFF_TICKS, t_arg);
237
238 /* set the bell char */
239 if (o_e != -1 && set_bell(boot0, o_e, 0) != -1)
240 up = 1;
241
242 if (vol_id[4]) {
243 if (b0_ver != 2)
244 errx(1, "incompatible boot block, cannot set volume ID");
245 boot0[OFF_SERIAL] = vol_id[0];
246 boot0[OFF_SERIAL+1] = vol_id[1];
247 boot0[OFF_SERIAL+2] = vol_id[2];
248 boot0[OFF_SERIAL+3] = vol_id[3];
249 up = 1; /* force update */
250 }
194 /* write the MBR back to disk */
195 if (up)
196 write_mbr(disk, 0, boot0, boot0_size);
197
198 /* display the MBR */
199 if (v_flag)
200 display_mbr(boot0);
201
202 /* clean up */
203 if (mbr != boot0)
204 free(boot0);
205 free(mbr);
206 free(disk);
207
208 return 0;
209}
210
251 /* write the MBR back to disk */
252 if (up)
253 write_mbr(disk, 0, boot0, boot0_size);
254
255 /* display the MBR */
256 if (v_flag)
257 display_mbr(boot0);
258
259 /* clean up */
260 if (mbr != boot0)
261 free(boot0);
262 free(mbr);
263 free(disk);
264
265 return 0;
266}
267
268/* get or set the 'bell' character to be used in case of errors.
269 * Lookup for a certain code sequence, return -1 if not found.
270 */
271static int
272set_bell(u_int8_t *mbr, int new_bell, int report)
273{
274 /* lookup sequence: 0x100 means skip, 0x200 means done */
275 static unsigned seq[] =
276 { 0xb0, 0x100, 0xe8, 0x100, 0x100, 0x30, 0xe4, 0x200 };
277 int ofs, i, c;
278 for (ofs = 0x60; ofs < 0x180; ofs++) { /* search range */
279 if (mbr[ofs] != seq[0]) /* search initial pattern */
280 continue;
281 for (i=0;; i++) {
282 if (seq[i] == 0x200) { /* found */
283 c = mbr[ofs+1];
284 if (!report)
285 mbr[ofs+1] = c = new_bell;
286 else
287 printf(" bell=%c (0x%x)",
288 (c >= ' ' && c < 0x7f) ? c : ' ', c);
289 return c;
290 }
291 if (seq[i] != 0x100 && seq[i] != mbr[ofs+i])
292 break;
293 }
294 }
295 warn("bell not found");
296 return -1;
297}
211/*
212 * Read in the MBR of the disk. If it is boot0, then use the version to
213 * read in all of it if necessary. Use pointers to return a malloc'd
214 * buffer containing the MBR and then return its size.
215 */
216static int
217read_mbr(const char *disk, u_int8_t **mbr, int check_version)
218{
219 u_int8_t buf[MBRSIZE];
220 int mbr_size, fd;
298/*
299 * Read in the MBR of the disk. If it is boot0, then use the version to
300 * read in all of it if necessary. Use pointers to return a malloc'd
301 * buffer containing the MBR and then return its size.
302 */
303static int
304read_mbr(const char *disk, u_int8_t **mbr, int check_version)
305{
306 u_int8_t buf[MBRSIZE];
307 int mbr_size, fd;
308 int ver;
221 ssize_t n;
222
223 if ((fd = open(disk, O_RDONLY)) == -1)
224 err(1, "open %s", disk);
225 if ((n = read(fd, buf, MBRSIZE)) == -1)
226 err(1, "read %s", disk);
227 if (n != MBRSIZE)
228 errx(1, "%s: short read", disk);
229 if (cv2(buf + OFF_MAGIC) != 0xaa55)
230 errx(1, "%s: bad magic", disk);
231
309 ssize_t n;
310
311 if ((fd = open(disk, O_RDONLY)) == -1)
312 err(1, "open %s", disk);
313 if ((n = read(fd, buf, MBRSIZE)) == -1)
314 err(1, "read %s", disk);
315 if (n != MBRSIZE)
316 errx(1, "%s: short read", disk);
317 if (cv2(buf + OFF_MAGIC) != 0xaa55)
318 errx(1, "%s: bad magic", disk);
319
232 if (!boot0bs(buf)) {
320 if (! (ver = boot0bs(buf))) {
233 if (check_version)
234 errx(1, "%s: unknown or incompatible boot code", disk);
235 } else if (boot0version(buf) == 0x101) {
236 mbr_size = 1024;
237 if ((*mbr = malloc(mbr_size)) == NULL)
238 errx(1, "%s: unable to allocate read buffer", disk);
239 if (lseek(fd, 0, SEEK_SET) == -1 ||
240 (n = read(fd, *mbr, mbr_size)) == -1)

--- 92 unchanged lines hidden (view full) ---

333 printf(fmt1, 1 + i, part[i].dp_flag,
334 part[i].dp_scyl + ((part[i].dp_ssect & 0xc0) << 2),
335 part[i].dp_shd, part[i].dp_ssect & 0x3f, part[i].dp_typ,
336 part[i].dp_ecyl + ((part[i].dp_esect & 0xc0) << 2),
337 part[i].dp_ehd, part[i].dp_esect & 0x3f, part[i].dp_start,
338 part[i].dp_size);
339 printf("\n");
340 version = boot0version(mbr);
321 if (check_version)
322 errx(1, "%s: unknown or incompatible boot code", disk);
323 } else if (boot0version(buf) == 0x101) {
324 mbr_size = 1024;
325 if ((*mbr = malloc(mbr_size)) == NULL)
326 errx(1, "%s: unable to allocate read buffer", disk);
327 if (lseek(fd, 0, SEEK_SET) == -1 ||
328 (n = read(fd, *mbr, mbr_size)) == -1)

--- 92 unchanged lines hidden (view full) ---

421 printf(fmt1, 1 + i, part[i].dp_flag,
422 part[i].dp_scyl + ((part[i].dp_ssect & 0xc0) << 2),
423 part[i].dp_shd, part[i].dp_ssect & 0x3f, part[i].dp_typ,
424 part[i].dp_ecyl + ((part[i].dp_esect & 0xc0) << 2),
425 part[i].dp_ehd, part[i].dp_esect & 0x3f, part[i].dp_start,
426 part[i].dp_size);
427 printf("\n");
428 version = boot0version(mbr);
341 printf("version=%d.%d drive=0x%x mask=0x%x ticks=%u\noptions=",
429 printf("version=%d.%d drive=0x%x mask=0x%x ticks=%u",
342 version >> 8, version & 0xff, mbr[OFF_DRIVE],
343 mbr[OFF_FLAGS] & 0xf, cv2(mbr + OFF_TICKS));
430 version >> 8, version & 0xff, mbr[OFF_DRIVE],
431 mbr[OFF_FLAGS] & 0xf, cv2(mbr + OFF_TICKS));
432 set_bell(mbr, 0, 1);
433 printf("\noptions=");
344 for (i = 0; i < nopt; i++) {
345 if (i)
346 printf(",");
347 if (!(mbr[OFF_FLAGS] & 1 << (7 - i)) ^ opttbl[i].def)
348 printf("no");
349 printf("%s", opttbl[i].tok);
350 }
351 printf("\n");
434 for (i = 0; i < nopt; i++) {
435 if (i)
436 printf(",");
437 if (!(mbr[OFF_FLAGS] & 1 << (7 - i)) ^ opttbl[i].def)
438 printf("no");
439 printf("%s", opttbl[i].tok);
440 }
441 printf("\n");
442 if (b0_ver == 2)
443 printf("volume serial ID %02x%02x-%02x%02x\n",
444 mbr[OFF_SERIAL], mbr[OFF_SERIAL+1],
445 mbr[OFF_SERIAL+2], mbr[OFF_SERIAL+3]);
352 printf("default_selection=F%d (", mbr[OFF_OPT] + 1);
353 if (mbr[OFF_OPT] < 4)
354 printf("Slice %d", mbr[OFF_OPT] + 1);
355 else
356 printf("Drive 1");
357 printf(")\n");
358}
359
360/*
361 * Return the boot0 version with the minor revision in the low byte, and
362 * the major revision in the next higher byte.
363 */
364static int
365boot0version(const u_int8_t *bs)
366{
446 printf("default_selection=F%d (", mbr[OFF_OPT] + 1);
447 if (mbr[OFF_OPT] < 4)
448 printf("Slice %d", mbr[OFF_OPT] + 1);
449 else
450 printf("Drive 1");
451 printf(")\n");
452}
453
454/*
455 * Return the boot0 version with the minor revision in the low byte, and
456 * the major revision in the next higher byte.
457 */
458static int
459boot0version(const u_int8_t *bs)
460{
367 static u_int8_t idold[] = {0xfe, 0x45, 0xf2, 0xe9, 0x00, 0x8a};
368
369 /* Check for old version, and return 0x100 if found. */
461 /* Check for old version, and return 0x100 if found. */
370 if (memcmp(bs + 0x1c, idold, sizeof(idold)) == 0)
371 return 0x100;
462 int v = boot0bs(bs);
463 if (v != 0)
464 return v << 8;
372
373 /* We have a newer boot0, so extract the version number and return it. */
374 return *(const int *)(bs + OFF_VERSION) & 0xffff;
375}
376
465
466 /* We have a newer boot0, so extract the version number and return it. */
467 return *(const int *)(bs + OFF_VERSION) & 0xffff;
468}
469
470/* descriptor of a pattern to match.
471 * Start from the first entry trying to match the chunk of bytes,
472 * if you hit an entry with len=0 terminate the search and report
473 * off as the version. Otherwise skip to the next block after len=0
474 * An entry with len=0, off=0 is the end marker.
475 */
476struct byte_pattern {
477 unsigned off;
478 unsigned len;
479 u_int8_t *key;
480};
481
377/*
378 * Decide if we have valid boot0 boot code by looking for
379 * characteristic byte sequences at fixed offsets.
380 */
381static int
382boot0bs(const u_int8_t *bs)
383{
482/*
483 * Decide if we have valid boot0 boot code by looking for
484 * characteristic byte sequences at fixed offsets.
485 */
486static int
487boot0bs(const u_int8_t *bs)
488{
489 /* the initial code sequence */
384 static u_int8_t id0[] = {0xfc, 0x31, 0xc0, 0x8e, 0xc0, 0x8e, 0xd8,
385 0x8e, 0xd0, 0xbc, 0x00, 0x7c };
490 static u_int8_t id0[] = {0xfc, 0x31, 0xc0, 0x8e, 0xc0, 0x8e, 0xd8,
491 0x8e, 0xd0, 0xbc, 0x00, 0x7c };
492 /* the drive id */
386 static u_int8_t id1[] = {'D', 'r', 'i', 'v', 'e', ' '};
493 static u_int8_t id1[] = {'D', 'r', 'i', 'v', 'e', ' '};
387 static struct {
388 unsigned off;
389 unsigned len;
390 u_int8_t *key;
391 } ident[2] = {
494 static struct byte_pattern patterns[] = {
392 {0x0, sizeof(id0), id0},
495 {0x0, sizeof(id0), id0},
393 {0x1b2, sizeof(id1), id1}
496 {0x1b2, sizeof(id1), id1},
497 {1, 0, NULL},
498 {0x0, sizeof(id0), id0}, /* version with NT support */
499 {0x1ae, sizeof(id1), id1},
500 {2, 0, NULL},
501 {0, 0, NULL},
394 };
502 };
395 unsigned int i;
503 struct byte_pattern *p = patterns;
396
504
397 for (i = 0; i < sizeof(ident) / sizeof(ident[0]); i++)
398 if (memcmp(bs + ident[i].off, ident[i].key, ident[i].len))
399 return 0;
400 return 1;
505 for (; p->off || p->len; p++) {
506 if (p->len == 0)
507 break;
508 if (!memcmp(bs + p->off, p->key, p->len)) /* match */
509 continue;
510 while (p->len) /* skip to next block */
511 p++;
512 }
513 b0_ver = p->off; /* XXX ugly side effect */
514 return p->off;
401}
402
403/*
404 * Adjust "and" and "or" masks for a -o option argument.
405 */
406static void
407stropt(const char *arg, int *xa, int *xo)
408{

--- 52 unchanged lines hidden ---
515}
516
517/*
518 * Adjust "and" and "or" masks for a -o option argument.
519 */
520static void
521stropt(const char *arg, int *xa, int *xo)
522{

--- 52 unchanged lines hidden ---