grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / HDTool / deviceio.c
blob9d013d15012ba13a1684f402ce2aee4a514146c1
1 #include <proto/exec.h>
2 #include <aros/debug.h>
3 #include <aros/macros.h>
4 #include <devices/scsidisk.h>
5 #include "deviceio.h"
7 BOOL openIO(struct DeviceIO *dio, STRPTR device, ULONG unit) {
9 dio->mp = CreateMsgPort();
10 if (dio->mp)
12 dio->iotd = (struct IOExtTD *)CreateIORequest(dio->mp, sizeof(struct IOExtTD));
13 if (dio->iotd)
15 if (OpenDevice(device, unit, (struct IORequest *)dio->iotd, 0)==0)
16 return TRUE;
17 DeleteIORequest((struct IORequest *)dio->iotd);
19 DeleteMsgPort(dio->mp);
21 return FALSE;
24 void closeIO(struct DeviceIO *dio) {
25 CloseDevice((struct IORequest *)dio->iotd);
26 DeleteIORequest((struct IORequest *)dio->iotd);
27 DeleteMsgPort(dio->mp);
30 BOOL iscorrectType(struct IOExtTD *iotd) {
31 BOOL retval = TRUE;
32 struct DriveGeometry dg;
34 iotd->iotd_Req.io_Command = TD_GETGEOMETRY;
35 iotd->iotd_Req.io_Data = &dg;
36 iotd->iotd_Req.io_Length = sizeof(struct DriveGeometry);
37 #if 0
38 if (DoIO((struct IORequest *)iotd) == 0)
40 if (dg.dg_DeviceType == DG_CDROM)
41 retval = FALSE;
42 // if (dg.dg_Flags & DGF_REMOVABLE)
43 // retval = FALSE;
45 #endif
46 return retval;
49 void w2strcpy(STRPTR name, UWORD *wstr, ULONG len) {
51 while (len)
53 *((UWORD *)name) = AROS_BE2WORD(*wstr);
54 name += sizeof(UWORD);
55 len -= 2;
56 wstr++;
58 name -= 2;
59 while ((*name==0) || (*name==' '))
60 *name-- = 0;
63 BOOL identify(struct IOExtTD *iotd, STRPTR id) {
64 struct SCSICmd scsicmd;
65 UWORD data[256];
66 UBYTE cmd=0xEC; /* identify */
68 scsicmd.scsi_Data = data;
69 scsicmd.scsi_Length = 512;
70 scsicmd.scsi_Command = &cmd;
71 scsicmd.scsi_CmdLength = 1;
72 iotd->iotd_Req.io_Command = HD_SCSICMD;
73 iotd->iotd_Req.io_Data = &scsicmd;
74 iotd->iotd_Req.io_Length = sizeof(struct SCSICmd);
75 if (DoIO((struct IORequest *)iotd))
76 return FALSE;
77 w2strcpy(id, &data[27], 40);
78 return TRUE;