1 /* #includes */ /*{{{C}}}*//*{{{*/
3 #define _POSIX_SOURCE 1
5 #define _POSIX_C_SOURCE 2
19 /* Device_open -- Open an image file */ /*{{{*/
20 const char *Device_open(struct Device *this, const char *filename, int mode, const char *deviceOpts)
22 dsk_err_t e = dsk_open(&this->dev, filename, deviceOpts, NULL);
24 if (e) return dsk_strerror(e);
26 dsk_getgeom(this->dev, &this->geom);
30 /* Device_setGeometry -- Set disk geometry */ /*{{{*/
31 void Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks)
33 this->secLength=secLength;
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);
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);
77 return (e?dsk_strerror(e):(const char*)0);