1 /* #includes */ /*{{{C}}}*//*{{{*/
16 /* Device_open -- Open an image file */ /*{{{*/
17 const char *Device_open(struct Device *this, const char *filename, int mode, const char *deviceOpts)
19 dsk_err_t e = dsk_open(&this->dev, filename, deviceOpts, NULL);
21 if (e) return dsk_strerror(e);
23 dsk_getgeom(this->dev, &this->geom);
27 /* Device_setGeometry -- Set disk geometry */ /*{{{*/
28 void Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks)
30 this->secLength=secLength;
34 this->geom.dg_secsize = secLength;
35 this->geom.dg_sectors = sectrk;
36 /* Did the autoprobe guess right about the number of sectors & cylinders? */
37 if (this->geom.dg_cylinders * this->geom.dg_heads == tracks) return;
38 /* Otherwise we guess: <= 43 tracks: single-sided. Else double. This
39 * fails for 80-track single-sided if there are any such beasts */
42 this->geom.dg_cylinders = tracks;
43 this->geom.dg_heads = 1;
47 this->geom.dg_cylinders = tracks/2;
48 this->geom.dg_heads = 2;
52 /* Device_close -- Close an image file */ /*{{{*/
53 const char *Device_close(struct Device *this)
57 e = dsk_close(&this->dev);
58 return (e?dsk_strerror(e):(const char*)0);
61 /* Device_readSector -- read a physical sector */ /*{{{*/
62 const char *Device_readSector(const struct Device *this, int track, int sector, char *buf)
65 e = dsk_lread(this->dev, &this->geom, buf, (track * this->sectrk) + sector);
66 return (e?dsk_strerror(e):(const char*)0);
69 /* Device_writeSector -- write physical sector */ /*{{{*/
70 const char *Device_writeSector(const struct Device *this, int track, int sector, const char *buf)
73 e = dsk_lwrite(this->dev, &this->geom, buf, (track * this->sectrk) + sector);
74 return (e?dsk_strerror(e):(const char*)0);