Skip to content

Commit a9b8f8d

Browse files
committed
IMG.CFG: Fix scoping of per-track sector sizes.
Refs #751
1 parent d44a5e7 commit a9b8f8d

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

src/image/img.c

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,13 @@ static bool_t raw_type_open(struct image *im, const struct raw_type *type)
235235
return raw_open(im);
236236
}
237237

238+
struct tag_layout {
239+
struct simple_layout s;
240+
uint8_t no[256];
241+
};
242+
238243
static void tag_add_layout(
239-
struct image *im, const struct simple_layout *layout,
240-
const uint8_t *no, unsigned int trk_idx)
244+
struct image *im, const struct tag_layout *layout, unsigned int trk_idx)
241245
{
242246
struct raw_sec *sec;
243247
struct raw_trk *trk;
@@ -246,23 +250,23 @@ static void tag_add_layout(
246250
if (trk_idx == 0)
247251
init_track_map(im);
248252

249-
trk = add_track_layout(im, layout->nr_sectors, trk_idx);
250-
trk->is_fm = layout->is_fm;
251-
trk->rpm = layout->rpm;
252-
trk->has_iam = layout->has_iam;
253-
trk->gap_2 = layout->gap2;
254-
trk->gap_3 = layout->gap3;
255-
trk->gap_4a = layout->gap4a;
256-
trk->data_rate = layout->data_rate;
257-
trk->interleave = layout->interleave;
258-
trk->cskew = layout->cskew;
259-
trk->hskew = layout->hskew;
260-
trk->head = layout->head;
253+
trk = add_track_layout(im, layout->s.nr_sectors, trk_idx);
254+
trk->is_fm = layout->s.is_fm;
255+
trk->rpm = layout->s.rpm;
256+
trk->has_iam = layout->s.has_iam;
257+
trk->gap_2 = layout->s.gap2;
258+
trk->gap_3 = layout->s.gap3;
259+
trk->gap_4a = layout->s.gap4a;
260+
trk->data_rate = layout->s.data_rate;
261+
trk->interleave = layout->s.interleave;
262+
trk->cskew = layout->s.cskew;
263+
trk->hskew = layout->s.hskew;
264+
trk->head = layout->s.head;
261265

262266
sec = &im->img.sec_info_base[trk->sec_off];
263-
for (i = 0; i < layout->nr_sectors; i++) {
264-
sec->r = i + layout->base[0];
265-
sec->n = no[i];
267+
for (i = 0; i < layout->s.nr_sectors; i++) {
268+
sec->r = i + layout->s.base[0];
269+
sec->n = layout->no[i];
266270
sec++;
267271
}
268272
}
@@ -315,12 +319,12 @@ static bool_t tag_open(struct image *im, char *tag)
315319
};
316320

317321
int match, active, option, nr_t = 0;
318-
struct simple_layout t_layout, d_layout;
319322
struct {
320323
FIL file;
321324
struct slot slot;
322325
char buf[512];
323-
uint8_t no[256];
326+
struct tag_layout t_layout;
327+
struct tag_layout d_layout;
324328
} *heap = (void *)im->bufs.write_bc.p;
325329
struct opts opts = {
326330
.file = &heap->file,
@@ -344,7 +348,7 @@ static bool_t tag_open(struct image *im, char *tag)
344348
char *p, *q;
345349
/* New section: Finalise any currently-active section. */
346350
if (active) {
347-
tag_add_layout(im, &t_layout, heap->no, nr_t);
351+
tag_add_layout(im, &heap->t_layout, nr_t);
348352
finalise_track_map(im);
349353
active = 0;
350354
}
@@ -375,8 +379,9 @@ static bool_t tag_open(struct image *im, char *tag)
375379
/* Best score so far: Process the section. */
376380
match = active;
377381
reset_all_params(im);
378-
d_layout = t_layout = dfl_simple_layout;
379-
memset(heap->no, ~0, sizeof(heap->no));
382+
heap->d_layout.s = dfl_simple_layout;
383+
memset(heap->d_layout.no, ~0, sizeof(heap->d_layout.no));
384+
heap->t_layout = heap->d_layout;
380385
nr_t = 0;
381386
} else {
382387
/* Mark ourselves inactive for this section. */
@@ -392,10 +397,10 @@ static bool_t tag_open(struct image *im, char *tag)
392397
case IMGCFG_tracks: {
393398
char *p = opts.arg;
394399
int c_s, c_e, h_s, h_e, c, h;
395-
tag_add_layout(im, &t_layout, heap->no, nr_t);
400+
tag_add_layout(im, &heap->t_layout, nr_t);
396401
if (nr_t++ == 0)
397-
d_layout = t_layout;
398-
t_layout = d_layout;
402+
heap->d_layout = heap->t_layout;
403+
heap->t_layout = heap->d_layout;
399404
do {
400405
/* <cylinder>[-<cylinder>] */
401406
c_s = strtol(p, &p, 10);
@@ -423,7 +428,7 @@ static bool_t tag_open(struct image *im, char *tag)
423428
im->nr_sides = strtol(opts.arg, NULL, 10);
424429
break;
425430
case IMGCFG_secs:
426-
t_layout.nr_sectors = strtol(opts.arg, NULL, 10);
431+
heap->t_layout.s.nr_sectors = strtol(opts.arg, NULL, 10);
427432
break;
428433
case IMGCFG_step:
429434
im->step = strtol(opts.arg, NULL, 10);
@@ -441,50 +446,50 @@ static bool_t tag_open(struct image *im, char *tag)
441446
for (no = 0; no < 8; no++)
442447
if ((128u<<no) == sz)
443448
break;
444-
heap->no[i++] = no;
449+
heap->t_layout.no[i++] = no;
445450
}
446-
memset(&heap->no[i], no, sizeof(heap->no)-i);
451+
memset(&heap->t_layout.no[i], no, sizeof(heap->t_layout.no)-i);
447452
break;
448453
}
449454
case IMGCFG_id:
450-
t_layout.base[0] = strtol(opts.arg, NULL, 0);
455+
heap->t_layout.s.base[0] = strtol(opts.arg, NULL, 0);
451456
break;
452457
case IMGCFG_h:
453-
t_layout.head = (*opts.arg == 'a') ? 0
458+
heap->t_layout.s.head = (*opts.arg == 'a') ? 0
454459
: (strtol(opts.arg, NULL, 10) & 1) + 1;
455460
break;
456461
case IMGCFG_mode:
457-
t_layout.is_fm = !strcmp(opts.arg, "fm");
462+
heap->t_layout.s.is_fm = !strcmp(opts.arg, "fm");
458463
break;
459464
case IMGCFG_interleave:
460-
t_layout.interleave = strtol(opts.arg, NULL, 10);
465+
heap->t_layout.s.interleave = strtol(opts.arg, NULL, 10);
461466
break;
462467
case IMGCFG_cskew:
463-
t_layout.cskew = strtol(opts.arg, NULL, 10);
468+
heap->t_layout.s.cskew = strtol(opts.arg, NULL, 10);
464469
break;
465470
case IMGCFG_hskew:
466-
t_layout.hskew = strtol(opts.arg, NULL, 10);
471+
heap->t_layout.s.hskew = strtol(opts.arg, NULL, 10);
467472
break;
468473
case IMGCFG_rpm:
469-
t_layout.rpm = strtol(opts.arg, NULL, 10);
474+
heap->t_layout.s.rpm = strtol(opts.arg, NULL, 10);
470475
break;
471476
case IMGCFG_gap2:
472-
t_layout.gap2 = (*opts.arg == 'a') ? -1
477+
heap->t_layout.s.gap2 = (*opts.arg == 'a') ? -1
473478
: (uint8_t)strtol(opts.arg, NULL, 10);
474479
break;
475480
case IMGCFG_gap3:
476-
t_layout.gap3 = (*opts.arg == 'a') ? -1
481+
heap->t_layout.s.gap3 = (*opts.arg == 'a') ? -1
477482
: (uint8_t)strtol(opts.arg, NULL, 10);
478483
break;
479484
case IMGCFG_gap4a:
480-
t_layout.gap4a = (*opts.arg == 'a') ? -1
485+
heap->t_layout.s.gap4a = (*opts.arg == 'a') ? -1
481486
: (uint8_t)strtol(opts.arg, NULL, 10);
482487
break;
483488
case IMGCFG_iam:
484-
t_layout.has_iam = !strcmp(opts.arg, "yes");
489+
heap->t_layout.s.has_iam = !strcmp(opts.arg, "yes");
485490
break;
486491
case IMGCFG_rate:
487-
t_layout.data_rate = strtol(opts.arg, NULL, 10);
492+
heap->t_layout.s.data_rate = strtol(opts.arg, NULL, 10);
488493
break;
489494
case IMGCFG_file_layout: {
490495
char *p, *q;
@@ -509,7 +514,7 @@ static bool_t tag_open(struct image *im, char *tag)
509514
}
510515

511516
if (active) {
512-
tag_add_layout(im, &t_layout, heap->no, nr_t);
517+
tag_add_layout(im, &heap->t_layout, nr_t);
513518
finalise_track_map(im);
514519
}
515520

0 commit comments

Comments
 (0)