6 * Amiga Dump File specific routines
9 #define _FILE_OFFSET_BITS 64
18 #include "adf_nativ.h"
21 extern struct Env adfEnv
;
27 RETCODE
adfInitDumpDevice(struct Device
* dev
, char* name
, BOOL ro
)
29 struct nativeDevice
* nDev
;
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
);
66 /* Let's make some guesses about geometry...
69 if (size
<= (11 * 80 * 512 * 2)) {
76 dev
->cylinders
= dev
->size
/ 512 / dev
->sectors
/ dev
->heads
;
86 RETCODE
adfReadDumpSector(struct Device
*dev
, SECTNUM n
, int size
, unsigned char* buf
)
88 struct nativeDevice
* nDev
;
90 long seek
= 512 * (long)n
;
92 // printf("R 0x%08lx\n", seek);
93 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
94 r
= fseek(nDev
->fd
, seek
, SEEK_SET
);
95 //printf("nnn=%ld size=%d\n",n,size);
99 if ((r
=fread(buf
, 1, size
, nDev
->fd
))!=size
) {
100 //printf("rr=%d\n",r);
113 RETCODE
adfWriteDumpSector(struct Device
*dev
, SECTNUM n
, int size
, unsigned char* buf
)
115 struct nativeDevice
* nDev
;
117 long seek
= 512 * (long)n
;
119 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
121 // printf("W 0x%08lx\n", seek);
122 r
=fseek(nDev
->fd
, seek
, SEEK_SET
);
126 if ( fwrite(buf
, 1, size
, nDev
->fd
)!=(unsigned int)(size
) )
134 * adfReleaseDumpDevice
137 RETCODE
adfReleaseDumpDevice(struct Device
*dev
)
139 struct nativeDevice
* nDev
;
144 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
157 RETCODE
adfCreateHdFile(struct Device
* dev
, char* volName
, int volType
)
161 (*adfEnv
.eFct
)("adfCreateHdFile : dev==NULL");
164 dev
->volList
=(struct Volume
**) malloc(sizeof(struct Volume
*));
166 (*adfEnv
.eFct
)("adfCreateHdFile : unknown device type");
170 dev
->volList
[0] = adfCreateVol( dev
, 0L, (long)dev
->cylinders
, 2, volName
, volType
);
171 if (dev
->volList
[0]==NULL
) {
177 dev
->devType
= DEVTYPE_HARDFILE
;
184 * adfCreateDumpDevice
186 * returns NULL if failed
189 adfCreateDumpDevice(char* filename
, long cylinders
, long heads
, long sectors
)
192 unsigned char buf
[LOGICAL_BLOCK_SIZE
];
193 struct nativeDevice
* nDev
;
197 dev
=(struct Device
*)malloc(sizeof(struct Device
));
199 (*adfEnv
.eFct
)("adfCreateDumpDevice : malloc dev");
202 nDev
= (struct nativeDevice
*)malloc(sizeof(struct nativeDevice
));
205 (*adfEnv
.eFct
)("adfCreateDumpDevice : malloc nDev");
208 dev
->nativeDev
= nDev
;
210 nDev
->fd
= (FILE*)fopen(filename
,"wb");
212 free(nDev
); free(dev
);
213 (*adfEnv
.eFct
)("adfCreateDumpDevice : fopen");
217 /* for(i=0; i<cylinders*heads*sectors; i++)
218 fwrite(buf, sizeof(unsigned char), 512 , nDev->fd);
220 r
=fseek(nDev
->fd
, ((cylinders
*heads
*sectors
)-1)*LOGICAL_BLOCK_SIZE
, SEEK_SET
);
222 fclose(nDev
->fd
); free(nDev
); free(dev
);
223 (*adfEnv
.eFct
)("adfCreateDumpDevice : fseek");
227 fwrite(buf
, LOGICAL_BLOCK_SIZE
, 1, nDev
->fd
);
231 nDev
->fd
=(FILE*)fopen(filename
,"rb+");
233 free(nDev
); free(dev
);
234 (*adfEnv
.eFct
)("adfCreateDumpDevice : fopen");
237 dev
->cylinders
= cylinders
;
239 dev
->sectors
= sectors
;
240 dev
->size
= cylinders
*heads
*sectors
* LOGICAL_BLOCK_SIZE
;
242 if (dev
->size
==80*11*2*LOGICAL_BLOCK_SIZE
)
243 dev
->devType
= DEVTYPE_FLOPDD
;
244 else if (dev
->size
==80*22*2*LOGICAL_BLOCK_SIZE
)
245 dev
->devType
= DEVTYPE_FLOPHD
;
247 dev
->devType
= DEVTYPE_HARDDISK
;
250 dev
->isNativeDev
= FALSE
;
251 dev
->readOnly
= FALSE
;
256 /*##################################################################################*/