1 /* #includes */ /*{{{C}}}*//*{{{*/
13 /* Device_open -- Open an image file */ /*{{{*/
14 const char *Device_open(struct Device *this, const char *filename, int mode, const char *deviceOpts)
16 if (deviceOpts != NULL)
18 return "POSIX driver accepts no options (build compiled without libdsk)";
20 this->fd=open(filename,mode);
21 this->opened=(this->fd==-1?0:1);
22 return ((this->fd==-1)?strerror(errno):(const char*)0);
25 /* Device_setGeometry -- Set disk geometry */ /*{{{*/
26 const char *Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks, off_t offset, const char *libdskGeometry)
28 this->secLength=secLength;
35 /* Device_close -- Close an image file */ /*{{{*/
36 const char *Device_close(struct Device *this)
39 return ((close(this->fd)==-1)?strerror(errno):(const char*)0);
42 /* Device_readSector -- read a physical sector */ /*{{{*/
43 const char *Device_readSector(const struct Device *this, int track, int sector, char *buf)
49 assert(sector<this->sectrk);
51 assert(track<this->tracks);
53 if (lseek(this->fd,(off_t)(((sector+track*this->sectrk)*this->secLength)+this->offset),SEEK_SET)==-1)
55 return strerror(errno);
57 if ((res=read(this->fd, buf, this->secLength)) != this->secLength)
61 return strerror(errno);
65 printf("len %d\n",this->secLength-res);
66 memset(buf+res,0,this->secLength-res); /* hit end of disk image */
69 return (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 assert(sector<this->sectrk);
78 assert(track<this->tracks);
79 if (lseek(this->fd,(off_t)(((sector+track*this->sectrk)*this->secLength)+this->offset),SEEK_SET)==-1)
81 return strerror(errno);
83 if (write(this->fd, buf, this->secLength) == this->secLength) return (const char*)0;
84 return strerror(errno);