Skip to content

Commit 4db7668

Browse files
committed
IMG.CFG: Allow sector size to be specified per sector.
1 parent 96aeecc commit 4db7668

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

examples/IMG.CFG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ secs = 9
6969
# Mandatory if @secs is non-zero.
7070
bps = 512
7171

72+
# Alternative form in which bytes per sector is specified per sector.
73+
# The list is comma separated; no white space allowed.
74+
# bps = 512,512,512,512,512,512,512,512,256
75+
7276
# ID of first sector on each track (0-255). Default is 1.
7377
# Numbers may be expressed in hexadecimal with 0x prefix (eg. 0xab).
7478
# id = 1

src/image/img.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ static bool_t raw_type_open(struct image *im, const struct raw_type *type)
236236
}
237237

238238
static void tag_add_layout(
239-
struct image *im, const struct simple_layout *layout, unsigned int trk_idx)
239+
struct image *im, const struct simple_layout *layout,
240+
const uint8_t *no, unsigned int trk_idx)
240241
{
241242
struct raw_sec *sec;
242243
struct raw_trk *trk;
@@ -261,7 +262,7 @@ static void tag_add_layout(
261262
sec = &im->img.sec_info_base[trk->sec_off];
262263
for (i = 0; i < layout->nr_sectors; i++) {
263264
sec->r = i + layout->base[0];
264-
sec->n = layout->no;
265+
sec->n = no[i];
265266
sec++;
266267
}
267268
}
@@ -319,14 +320,17 @@ static bool_t tag_open(struct image *im, char *tag)
319320
FIL file;
320321
struct slot slot;
321322
char buf[512];
322-
} *heap = (void *)im->bufs.read_data.p;
323+
uint8_t no[256];
324+
} *heap = (void *)im->bufs.write_bc.p;
323325
struct opts opts = {
324326
.file = &heap->file,
325327
.opts = img_cfg_opts,
326328
.arg = heap->buf,
327329
.argmax = sizeof(heap->buf)-1
328330
};
329331

332+
ASSERT(sizeof(*heap) <= im->bufs.write_bc.len);
333+
330334
if (!get_img_cfg(&heap->slot))
331335
return FALSE;
332336

@@ -340,7 +344,7 @@ static bool_t tag_open(struct image *im, char *tag)
340344
char *p, *q;
341345
/* New section: Finalise any currently-active section. */
342346
if (active) {
343-
tag_add_layout(im, &t_layout, nr_t);
347+
tag_add_layout(im, &t_layout, heap->no, nr_t);
344348
finalise_track_map(im);
345349
active = 0;
346350
}
@@ -372,6 +376,7 @@ static bool_t tag_open(struct image *im, char *tag)
372376
match = active;
373377
reset_all_params(im);
374378
d_layout = t_layout = dfl_simple_layout;
379+
memset(heap->no, ~0, sizeof(heap->no));
375380
nr_t = 0;
376381
} else {
377382
/* Mark ourselves inactive for this section. */
@@ -387,7 +392,7 @@ static bool_t tag_open(struct image *im, char *tag)
387392
case IMGCFG_tracks: {
388393
char *p = opts.arg;
389394
int c_s, c_e, h_s, h_e, c, h;
390-
tag_add_layout(im, &t_layout, nr_t);
395+
tag_add_layout(im, &t_layout, heap->no, nr_t);
391396
if (nr_t++ == 0)
392397
d_layout = t_layout;
393398
t_layout = d_layout;
@@ -423,14 +428,24 @@ static bool_t tag_open(struct image *im, char *tag)
423428
case IMGCFG_step:
424429
im->step = strtol(opts.arg, NULL, 10);
425430
break;
426-
case IMGCFG_bps: {
427-
int no, sz = strtol(opts.arg, NULL, 10);
428-
for (no = 0; no < 8; no++)
429-
if ((128u<<no) == sz)
430-
break;
431-
t_layout.no = no;
431+
case IMGCFG_bps: {
432+
char *p, *q;
433+
int no = ~0, i = 0;
434+
for (p = opts.arg; *p != '\0'; p = q) {
435+
int sz;
436+
for (q = p; *q && *q != ','; q++)
437+
continue;
438+
if (*q == ',')
439+
*q++ = '\0';
440+
sz = strtol(p, NULL, 10);
441+
for (no = 0; no < 8; no++)
442+
if ((128u<<no) == sz)
443+
break;
444+
heap->no[i++] = no;
445+
}
446+
memset(&heap->no[i], no, sizeof(heap->no)-i);
432447
break;
433-
}
448+
}
434449
case IMGCFG_id:
435450
t_layout.base[0] = strtol(opts.arg, NULL, 0);
436451
break;
@@ -494,7 +509,7 @@ static bool_t tag_open(struct image *im, char *tag)
494509
}
495510

496511
if (active) {
497-
tag_add_layout(im, &t_layout, nr_t);
512+
tag_add_layout(im, &t_layout, heap->no, nr_t);
498513
finalise_track_map(im);
499514
}
500515

0 commit comments

Comments
 (0)