/* #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 */ /*{{{*/
}
/*}}}*/
/* 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? */
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);
}
/*}}}*/
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);
}
/*}}}*/