grub2: bring back build of aros-side grub2 tools
[AROS.git] / tools / adflib / Win32 / adf_nativ.c
bloba50066468503338a87ed3c05ee8b8f1e2df5579b
1 /* Win32/adf_nativ.c - Win32 specific drive-access routines for ADFLib
3 * Modified for Win32 by Dan Sutherland <dan@chromerhino.demon.co.uk>
4 */
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().
11 #include <windows.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "../adf_str.h"
16 #include "../adf_err.h"
18 #include "adf_nativ.h"
19 #include "nt4_dev.h"
21 extern struct Env adfEnv;
23 RETCODE Win32InitDevice(struct Device* dev, char* lpstrName, BOOL ro)
25 struct nativeDevice* nDev;
26 char strTempName[3];
28 nDev = (struct nativeDevice*)dev->nativeDev;
30 nDev = (struct nativeDevice*)malloc(sizeof(struct nativeDevice));
31 if (!nDev) {
32 (*adfEnv.eFct)("Win32InitDevice : malloc");
33 return FALSE;
36 /* convert device name to something usable by Win32 functions */
37 if (strlen(lpstrName) != 3) {
38 (*adfEnv.eFct)("Win32InitDevice : invalid drive specifier");
39 return FALSE;
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");
50 return FALSE;
53 dev->size = NT4GetDriveSize(nDev->hDrv);
55 dev->nativeDev = nDev;
57 return RC_OK;
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");
69 return FALSE;
72 return RC_OK;
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");
84 return FALSE;
87 return RC_OK;
91 RETCODE Win32ReleaseDevice(struct Device *dev)
93 struct nativeDevice* nDev;
95 nDev = (struct nativeDevice*)dev->nativeDev;
97 if (! NT4CloseDrive(nDev->hDrv))
98 return FALSE;
100 free(nDev);
102 return RC_OK;
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] == '|';