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, off_t offset)
30 this->secLength=secLength;
33 /* Must be an even multiple of sector size */
34 assert(offset%secLength==0);
37 this->geom.dg_secsize = secLength;
38 this->geom.dg_sectors = sectrk;
39 /* Did the autoprobe guess right about the number of sectors & cylinders? */
40 if (this->geom.dg_cylinders * this->geom.dg_heads == tracks) return;
41 /* Otherwise we guess: <= 43 tracks: single-sided. Else double. This
42 * fails for 80-track single-sided if there are any such beasts */
45 this->geom.dg_cylinders = tracks;
46 this->geom.dg_heads = 1;
50 this->geom.dg_cylinders = tracks/2;
51 this->geom.dg_heads = 2;
55 /* Device_close -- Close an image file */ /*{{{*/
56 const char *Device_close(struct Device *this)
60 e = dsk_close(&this->dev);
61 return (e?dsk_strerror(e):(const char*)0);
64 /* Device_readSector -- read a physical sector */ /*{{{*/
65 const char *Device_readSector(const struct Device *this, int track, int sector, char *buf)
68 e = dsk_lread(this->dev, &this->geom, buf, (track * this->sectrk) + sector + this->offset/this->secLength);
69 return (e?dsk_strerror(e):(const char*)0);
72 /* Device_writeSector -- write physical sector */ /*{{{*/
73 const char *Device_writeSector(const struct Device *this, int track, int sector, const char *buf)
76 e = dsk_lwrite(this->dev, &this->geom, buf, (track * this->sectrk) + sector + this->offset/this->secLength);
77 return (e?dsk_strerror(e):(const char*)0);