6 * Amiga Dump File specific routines
19 extern struct Env adfEnv
;
25 RETCODE
adfInitDumpDevice(struct Device
* dev
, char* name
, BOOL ro
)
27 struct nativeDevice
* nDev
;
30 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
32 nDev
= (struct nativeDevice
*)malloc(sizeof(struct nativeDevice
));
34 (*adfEnv
.eFct
)("adfInitDumpDevice : malloc");
37 dev
->nativeDev
= nDev
;
42 nDev
->fd
= fopen(name
,"rb+");
44 if (!nDev
->fd
&& (errno
==EACCES
|| errno
==EROFS
) ) {
45 nDev
->fd
= fopen(name
,"rb");
48 (*adfEnv
.wFct
)("myInitDevice : fopen, read-only mode forced");
52 /* read only requested */
53 nDev
->fd
= fopen(name
,"rb");
57 (*adfEnv
.eFct
)("myInitDevice : fopen");
62 fseek(nDev
->fd
, 0, SEEK_END
);
63 size
= ftell(nDev
->fd
);
64 fseek(nDev
->fd
, 0, SEEK_SET
);
76 RETCODE
adfReadDumpSector(struct Device
*dev
, long n
, int size
, unsigned char* buf
)
78 struct nativeDevice
* nDev
;
80 //puts("adfReadDumpSector");
81 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
82 r
= fseek(nDev
->fd
, 512*n
, SEEK_SET
);
83 //printf("nnn=%ld size=%d\n",n,size);
87 if ((r
=fread(buf
, 1, size
, nDev
->fd
))!=size
) {
88 //printf("rr=%d\n",r);
101 RETCODE
adfWriteDumpSector(struct Device
*dev
, long n
, int size
, unsigned char* buf
)
103 struct nativeDevice
* nDev
;
106 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
108 r
=fseek(nDev
->fd
, 512*n
, SEEK_SET
);
112 if ( fwrite(buf
, 1, size
, nDev
->fd
)!=(unsigned int)(size
) )
114 //puts("adfWriteDumpSector");
120 * adfReleaseDumpDevice
123 RETCODE
adfReleaseDumpDevice(struct Device
*dev
)
125 struct nativeDevice
* nDev
;
130 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
143 RETCODE
adfCreateHdFile(struct Device
* dev
, char* volName
, int volType
)
147 (*adfEnv
.eFct
)("adfCreateHdFile : dev==NULL");
150 dev
->volList
=(struct Volume
**) malloc(sizeof(struct Volume
*));
152 (*adfEnv
.eFct
)("adfCreateHdFile : unknown device type");
156 dev
->volList
[0] = adfCreateVol( dev
, 0L, (long)dev
->cylinders
, volName
, volType
);
157 if (dev
->volList
[0]==NULL
) {
163 dev
->devType
= DEVTYPE_HARDFILE
;
170 * adfCreateDumpDevice
172 * returns NULL if failed
175 adfCreateDumpDevice(char* filename
, long cylinders
, long heads
, long sectors
)
178 unsigned char buf
[LOGICAL_BLOCK_SIZE
];
179 struct nativeDevice
* nDev
;
183 dev
=(struct Device
*)malloc(sizeof(struct Device
));
185 (*adfEnv
.eFct
)("adfCreateDumpDevice : malloc dev");
188 nDev
= (struct nativeDevice
*)malloc(sizeof(struct nativeDevice
));
191 (*adfEnv
.eFct
)("adfCreateDumpDevice : malloc nDev");
194 dev
->nativeDev
= nDev
;
196 nDev
->fd
= (FILE*)fopen(filename
,"wb");
198 free(nDev
); free(dev
);
199 (*adfEnv
.eFct
)("adfCreateDumpDevice : fopen");
203 /* for(i=0; i<cylinders*heads*sectors; i++)
204 fwrite(buf, sizeof(unsigned char), 512 , nDev->fd);
206 r
=fseek(nDev
->fd
, ((cylinders
*heads
*sectors
)-1)*LOGICAL_BLOCK_SIZE
, SEEK_SET
);
208 fclose(nDev
->fd
); free(nDev
); free(dev
);
209 (*adfEnv
.eFct
)("adfCreateDumpDevice : fseek");
213 fwrite(buf
, LOGICAL_BLOCK_SIZE
, 1, nDev
->fd
);
217 nDev
->fd
=(FILE*)fopen(filename
,"rb+");
219 free(nDev
); free(dev
);
220 (*adfEnv
.eFct
)("adfCreateDumpDevice : fopen");
223 dev
->cylinders
= cylinders
;
225 dev
->sectors
= sectors
;
226 dev
->size
= cylinders
*heads
*sectors
* LOGICAL_BLOCK_SIZE
;
228 if (dev
->size
==80*11*2*LOGICAL_BLOCK_SIZE
)
229 dev
->devType
= DEVTYPE_FLOPDD
;
230 else if (dev
->size
==80*22*2*LOGICAL_BLOCK_SIZE
)
231 dev
->devType
= DEVTYPE_FLOPHD
;
233 dev
->devType
= DEVTYPE_HARDDISK
;
236 dev
->isNativeDev
= FALSE
;
237 dev
->readOnly
= FALSE
;
242 /*##################################################################################*/