Skip to content

Commit 5be461f

Browse files
committed
IMG.CFG: New per-track parameter "img_bps"
Specifies bytes occupied per sector in the IMG image file. Allows padding of short sectors for uniformly-indexed fiels. Refs #751
1 parent 13d743d commit 5be461f

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

examples/IMG.CFG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ bps = 512
7373
# The list is comma separated; no white space allowed.
7474
# bps = 512,512,512,512,512,512,512,512,256
7575

76+
# Bytes per sector within the IMG file. Smaller sectors will be padded.
77+
# The default is 0: Sectors occupy precisely their data size; No padding.
78+
# Supported values: 0, 128, 256, 512, 1024, 2048, 4096, 8192.
79+
# img_bps = 0
80+
7681
# ID of first sector on each track (0-255). Default is 1.
7782
# Numbers may be expressed in hexadecimal with 0x prefix (eg. 0xab).
7883
# id = 1

inc/floppy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct raw_trk {
9191
uint16_t sec_off;
9292
uint16_t data_rate;
9393
uint16_t rpm;
94+
uint16_t img_bps; /* could squeeze this field into uint8_t or bitfield */
9495
int16_t gap_2, gap_3, gap_4a;
9596
uint8_t interleave, cskew, hskew;
9697
uint8_t has_iam:1, is_fm:1, invert_data:1;

src/image/img.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ static bool_t raw_type_open(struct image *im, const struct raw_type *type)
237237

238238
struct tag_layout {
239239
struct simple_layout s;
240+
uint16_t img_bps;
240241
uint8_t no[256];
241242
};
242243

@@ -262,6 +263,7 @@ static void tag_add_layout(
262263
trk->cskew = layout->s.cskew;
263264
trk->hskew = layout->s.hskew;
264265
trk->head = layout->s.head;
266+
trk->img_bps = layout->img_bps;
265267

266268
sec = &im->img.sec_info_base[trk->sec_off];
267269
for (i = 0; i < layout->s.nr_sectors; i++) {
@@ -280,6 +282,7 @@ static bool_t tag_open(struct image *im, char *tag)
280282
IMGCFG_step,
281283
IMGCFG_secs,
282284
IMGCFG_bps,
285+
IMGCFG_img_bps,
283286
IMGCFG_id,
284287
IMGCFG_h,
285288
IMGCFG_mode,
@@ -303,6 +306,7 @@ static bool_t tag_open(struct image *im, char *tag)
303306
[IMGCFG_step] = { "step" },
304307
[IMGCFG_secs] = { "secs" },
305308
[IMGCFG_bps] = { "bps" },
309+
[IMGCFG_img_bps] = { "img_bps" },
306310
[IMGCFG_id] = { "id" },
307311
[IMGCFG_h] = { "h" },
308312
[IMGCFG_mode] = { "mode" },
@@ -380,6 +384,7 @@ static bool_t tag_open(struct image *im, char *tag)
380384
match = active;
381385
reset_all_params(im);
382386
heap->d_layout.s = dfl_simple_layout;
387+
heap->d_layout.img_bps = 0;
383388
memset(heap->d_layout.no, ~0, sizeof(heap->d_layout.no));
384389
heap->t_layout = heap->d_layout;
385390
nr_t = 0;
@@ -451,6 +456,9 @@ static bool_t tag_open(struct image *im, char *tag)
451456
memset(&heap->t_layout.no[i], no, sizeof(heap->t_layout.no)-i);
452457
break;
453458
}
459+
case IMGCFG_img_bps:
460+
heap->t_layout.img_bps = strtol(opts.arg, NULL, 0);
461+
break;
454462
case IMGCFG_id:
455463
heap->t_layout.s.base[0] = strtol(opts.arg, NULL, 0);
456464
break;
@@ -1763,10 +1771,14 @@ static void raw_seek_track(
17631771
if (file_idx(im, i, j) >= idx)
17641772
continue;
17651773
trk = &im->img.trk_info[im->img.trk_map[i*im->nr_sides + j]];
1766-
sec = &im->img.sec_info_base[trk->sec_off];
1767-
for (k = 0; k < trk->nr_sectors; k++) {
1768-
off += sec_sz(sec->n);
1769-
sec++;
1774+
if (trk->img_bps != 0) {
1775+
off += trk->nr_sectors * trk->img_bps;
1776+
} else {
1777+
sec = &im->img.sec_info_base[trk->sec_off];
1778+
for (k = 0; k < trk->nr_sectors; k++) {
1779+
off += sec_sz(sec->n);
1780+
sec++;
1781+
}
17701782
}
17711783
}
17721784
}
@@ -2041,9 +2053,12 @@ static bool_t raw_write_track(struct image *im)
20412053

20422054
if (im->img.file_sec_offsets) {
20432055
off = im->img.file_sec_offsets[sec_nr];
2056+
} else if (trk->img_bps != 0) {
2057+
off = sec_nr * trk->img_bps;
20442058
} else {
2059+
off = 0;
20452060
sec = im->img.sec_info;
2046-
for (i = off = 0; i < sec_nr; i++)
2061+
for (i = 0; i < sec_nr; i++)
20472062
off += sec_sz(sec++->n);
20482063
}
20492064
F_lseek(&im->fp, im->img.trk_off + off);
@@ -2101,7 +2116,7 @@ static void raw_dump_info(struct image *im)
21012116
im->ticks_per_cell, im->write_bc_ticks, trk->has_iam);
21022117
printk(" interleave: %u, cskew %u, hskew %u\n ",
21032118
trk->interleave, trk->cskew, trk->hskew);
2104-
printk(" file-layout: %x\n", im->img.layout);
2119+
printk(" file_layout: %x, img_bps: %u\n", im->img.layout, trk->img_bps);
21052120
for (i = 0; i < trk->nr_sectors; i++) {
21062121
struct raw_sec *sec = &im->img.sec_info[im->img.sec_map[i]];
21072122
int hd = trk->head ? trk->head-1 : im->cur_track&1;
@@ -2114,19 +2129,22 @@ static void raw_dump_info(struct image *im)
21142129
static void img_fetch_data(struct image *im)
21152130
{
21162131
struct image_buf *rd = &im->bufs.read_data;
2132+
struct raw_trk *trk = im->img.trk;
21172133
uint8_t *buf = rd->p;
21182134
struct raw_sec *sec, *s;
21192135
uint8_t sec_i;
21202136
uint16_t off, len;
21212137

2122-
if ((im->img.trk->nr_sectors == 0) || (rd->prod != rd->cons))
2138+
if ((trk->nr_sectors == 0) || (rd->prod != rd->cons))
21232139
return;
21242140

21252141
sec_i = im->img.sec_map[im->img.trk_sec];
21262142
sec = &im->img.sec_info[sec_i];
21272143

21282144
if (im->img.file_sec_offsets) {
21292145
off = im->img.file_sec_offsets[sec_i];
2146+
} else if (trk->img_bps != 0) {
2147+
off = sec_i * trk->img_bps;
21302148
} else {
21312149
off = 0;
21322150
for (s = im->img.sec_info; s != sec; s++)
@@ -2143,7 +2161,7 @@ static void img_fetch_data(struct image *im)
21432161
im->img.rd_sec_pos++;
21442162
} else {
21452163
im->img.rd_sec_pos = 0;
2146-
if (++im->img.trk_sec >= im->img.trk->nr_sectors)
2164+
if (++im->img.trk_sec >= trk->nr_sectors)
21472165
im->img.trk_sec = 0;
21482166
}
21492167

0 commit comments

Comments
 (0)