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 this->fd=open(filename,mode);
20 this->opened=(this->fd==-1?0:1);
21 return ((this->fd==-1)?strerror(errno):(const char*)0);
24 /* Device_setGeometry -- Set disk geometry */ /*{{{*/
25 void Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks)
27 this->secLength=secLength;
32 /* Device_close -- Close an image file */ /*{{{*/
33 const char *Device_close(struct Device *this)
36 return ((close(this->fd)==-1)?strerror(errno):(const char*)0);
39 /* Device_readSector -- read a physical sector */ /*{{{*/
40 const char *Device_readSector(const struct Device *this, int track, int sector, char *buf)
45 assert(sector<this->sectrk);
47 assert(track<this->tracks);
48 if (lseek(this->fd,(off_t)(sector+track*this->sectrk)*this->secLength,SEEK_SET)==-1)
50 return strerror(errno);
52 if ((res=read(this->fd, buf, this->secLength)) != this->secLength)
56 return strerror(errno);
58 else memset(buf+res,0,this->secLength-res); /* hit end of disk image */
60 return (const char*)0;
63 /* Device_writeSector -- write physical sector */ /*{{{*/
64 const char *Device_writeSector(const struct Device *this, int track, int sector, const char *buf)
67 assert(sector<this->sectrk);
69 assert(track<this->tracks);
70 if (lseek(this->fd,(off_t)(sector+track*this->sectrk)*this->secLength, SEEK_SET)==-1)
72 return strerror(errno);
74 if (write(this->fd, buf, this->secLength) == this->secLength) return (const char*)0;
75 return strerror(errno);