Imported Upstream version 4.0.43
[platform/upstream/mtools.git] / offset.c
index dedf098..889e51b 100644 (file)
--- a/offset.c
+++ b/offset.c
  */
 
 #include "sysincludes.h"
-#include "msdos.h"
 #include "mtools.h"
 #include "offset.h"
 
 typedef struct Offset_t {
-       struct Class_t *Class;
-       int refs;
-       struct Stream_t *Next;
-       struct Stream_t *Buffer;
+       struct Stream_t head;
 
        mt_off_t offset;
 } Offset_t;
 
-static ssize_t offset_read(Stream_t *Stream, char *buf,
-                         mt_off_t start, size_t len)
+static ssize_t offset_pread(Stream_t *Stream, char *buf,
+                           mt_off_t start, size_t len)
 {
        DeclareThis(Offset_t);
-       return READS(This->Next, buf, start+This->offset, len);
+       return PREADS(This->head.Next, buf, start+This->offset, len);
 }
 
-static ssize_t offset_write(Stream_t *Stream, char *buf,
-                          mt_off_t start, size_t len)
+static ssize_t offset_pwrite(Stream_t *Stream, char *buf,
+                            mt_off_t start, size_t len)
 {
        DeclareThis(Offset_t);
-       return WRITES(This->Next, buf, start+This->offset, len);
+       return PWRITES(This->head.Next, buf, start+This->offset, len);
 }
 
 static Class_t OffsetClass = {
-       offset_read,
-       offset_write,
+       0,
+       0,
+       offset_pread,
+       offset_pwrite,
        0, /* flush */
        0, /* free */
        set_geom_pass_through, /* set_geom */
@@ -58,7 +56,7 @@ static Class_t OffsetClass = {
 };
 
 Stream_t *OpenOffset(Stream_t *Next, struct device *dev, off_t offset,
-                    char *errmsg, mt_size_t *maxSize) {
+                    char *errmsg, mt_off_t *maxSize) {
        Offset_t *This;
 
        This = New(Offset_t);
@@ -67,26 +65,24 @@ Stream_t *OpenOffset(Stream_t *Next, struct device *dev, off_t offset,
                return 0;
        }
        memset((void*)This, 0, sizeof(Offset_t));
-       This->Class = &OffsetClass;
-       This->refs = 1;
-       This->Next = Next;
+       init_head(&This->head, &OffsetClass, Next);
 
        This->offset = offset;
 
        if(maxSize) {
-               if(This->offset > (mt_off_t) *maxSize) {
+               if(This->offset > *maxSize) {
                        if(errmsg)
                                sprintf(errmsg,"init: Big disks not supported");
                        goto exit_0;
                }
 
-               *maxSize -= (mt_size_t) This->offset;
+               *maxSize -= This->offset;
        }
 
        if(adjust_tot_sectors(dev, This->offset, errmsg) < 0)
                goto exit_0;
 
-       return (Stream_t *) This;
+       return &This->head;
  exit_0:
        Free(This);
        return NULL;