Imported Upstream version 2.17
[debian/cpmtools] / device_libdsk.c
index b0d58b5651f4c8c2dcb921c2cb730d854b919931..739a3acb14b3c07315795a6af0459695eb264921 100644 (file)
@@ -25,12 +25,15 @@ const char *Device_open(struct Device *this, const char *filename, int mode, con
 }
 /*}}}*/
 /* Device_setGeometry    -- Set disk geometry                       */ /*{{{*/
-void Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks)
+void Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks, off_t offset)
 {
   this->secLength=secLength;
   this->sectrk=sectrk;
   this->tracks=tracks;
-
+  /* Must be an even multiple of sector size */
+  assert(offset%secLength==0);
+  this->offset=offset;
+  
   this->geom.dg_secsize   = secLength;
   this->geom.dg_sectors   = sectrk;
   /* Did the autoprobe guess right about the number of sectors & cylinders? */
@@ -62,7 +65,7 @@ const char *Device_close(struct Device *this)
 const char *Device_readSector(const struct Device *this, int track, int sector, char *buf)
 {
   dsk_err_t e;
-  e = dsk_lread(this->dev, &this->geom, buf, (track * this->sectrk) + sector);
+  e = dsk_lread(this->dev, &this->geom, buf, (track * this->sectrk) + sector + this->offset/this->secLength);
   return (e?dsk_strerror(e):(const char*)0);
 }
 /*}}}*/
@@ -70,7 +73,7 @@ const char *Device_readSector(const struct Device *this, int track, int sector,
 const char *Device_writeSector(const struct Device *this, int track, int sector, const char *buf)
 {
   dsk_err_t e;
-  e = dsk_lwrite(this->dev, &this->geom, buf, (track * this->sectrk) + sector);
+  e = dsk_lwrite(this->dev, &this->geom, buf, (track * this->sectrk) + sector + this->offset/this->secLength);
   return (e?dsk_strerror(e):(const char*)0);
 }
 /*}}}*/