1 /* Win32/adf_nativ.c - Win32 specific drive-access routines for ADFLib
3 * Modified for Win32 by Dan Sutherland <dan@chromerhino.demon.co.uk>
6 // Modified 29/8/00 by Gary Harris.
7 // - Added a third, Boolean argument to Win32InitDevice() to avoid a compilation warning
8 // caused by the mismatch with the number of arguments in ADFLib's adfInitDevice().
15 #include "../adf_str.h"
16 #include "../adf_err.h"
18 #include "adf_nativ.h"
21 extern struct Env adfEnv
;
23 RETCODE
Win32InitDevice(struct Device
* dev
, char* lpstrName
, BOOL ro
)
25 struct nativeDevice
* nDev
;
28 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
30 nDev
= (struct nativeDevice
*)malloc(sizeof(struct nativeDevice
));
32 (*adfEnv
.eFct
)("Win32InitDevice : malloc");
36 /* convert device name to something usable by Win32 functions */
37 if (strlen(lpstrName
) != 3) {
38 (*adfEnv
.eFct
)("Win32InitDevice : invalid drive specifier");
42 strTempName
[0] = lpstrName
[1];
43 strTempName
[1] = lpstrName
[2];
44 strTempName
[2] = '\0';
46 nDev
->hDrv
= NT4OpenDrive(strTempName
);
48 if (nDev
->hDrv
== NULL
) {
49 (*adfEnv
.eFct
)("Win32InitDevice : NT4OpenDrive");
53 dev
->size
= NT4GetDriveSize(nDev
->hDrv
);
55 dev
->nativeDev
= nDev
;
61 RETCODE
Win32ReadSector(struct Device
*dev
, long n
, int size
, unsigned char* buf
)
63 struct nativeDevice
* tDev
;
65 tDev
= (struct nativeDevice
*)dev
->nativeDev
;
67 if (! NT4ReadSector(tDev
->hDrv
, n
, size
, buf
)) {
68 (*adfEnv
.eFct
)("Win32InitDevice : NT4ReadSector");
76 RETCODE
Win32WriteSector(struct Device
*dev
, long n
, int size
, unsigned char* buf
)
78 struct nativeDevice
* tDev
;
80 tDev
= (struct nativeDevice
*)dev
->nativeDev
;
82 if (! NT4WriteSector(tDev
->hDrv
, n
, size
, buf
)) {
83 (*adfEnv
.eFct
)("Win32InitDevice : NT4WriteSector");
91 RETCODE
Win32ReleaseDevice(struct Device
*dev
)
93 struct nativeDevice
* nDev
;
95 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
97 if (! NT4CloseDrive(nDev
->hDrv
))
106 void adfInitNativeFct()
108 struct nativeFunctions
*nFct
;
110 nFct
= (struct nativeFunctions
*)adfEnv
.nativeFct
;
112 nFct
->adfInitDevice
= Win32InitDevice
;
113 nFct
->adfNativeReadSector
= Win32ReadSector
;
114 nFct
->adfNativeWriteSector
= Win32WriteSector
;
115 nFct
->adfReleaseDevice
= Win32ReleaseDevice
;
116 nFct
->adfIsDevNative
= Win32IsDevNative
;
120 BOOL
Win32IsDevNative(char *devName
)
122 return devName
[0] == '|';