Imported Upstream version 2.17
[debian/cpmtools] / device_libdsk.c
index 54d4087e623c664aa85345bdd46e679b4c273909..739a3acb14b3c07315795a6af0459695eb264921 100644 (file)
@@ -1,19 +1,16 @@
 /* #includes */ /*{{{C}}}*//*{{{*/
-#undef  _POSIX_SOURCE
-#define _POSIX_SOURCE   1
-#undef  _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 2
-
-#ifdef DMALLOC
-#include "dmalloc.h"
-#endif
+#include "config.h"
 
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
-#include "config.h"
+
 #include "device.h"
+
+#ifdef USE_DMALLOC
+#include <dmalloc.h>
+#endif
 /*}}}*/
 
 /* Device_open           -- Open an image file                      */ /*{{{*/
@@ -28,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? */
@@ -65,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);
 }
 /*}}}*/
@@ -73,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);
 }
 /*}}}*/