alsa.audio: add debug logs
[AROS.git] / workbench / tools / HDToolBox / harddisks.c
blob58d3a6e1698302b4c49f7a10ed74bd3d11aeab2c
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/partition.h>
9 #include <devices/scsidisk.h>
10 #include <exec/io.h>
11 #include <exec/memory.h>
13 #include <stdio.h>
15 #define DEBUG 0
16 #include "debug.h"
18 #include "harddisks.h"
19 #include "hdtoolbox_support.h"
20 #include "platform.h"
22 extern struct GUIGadgets gadgets;
24 static void strcatlen(STRPTR dst, UBYTE *src, UBYTE maxlen)
26 dst += strlen(dst);
27 memcpy(dst, src, maxlen);
28 while (maxlen-- > 0) {
29 if (dst[maxlen] != ' ')
30 break;
31 dst[maxlen] = 0;
35 static BOOL identify(struct IOStdReq *ioreq, STRPTR name)
37 struct SCSICmd scsicmd = {0};
38 UBYTE data[36 + 1];
39 UBYTE cmd[6] = { 0x12, 0, 0, 0, 36, 0 }; /* inquiry */
40 WORD i;
42 D(bug("[HDToolBox] inquiry('%s')\n", name));
44 scsicmd.scsi_Data = (UWORD*)data;
45 scsicmd.scsi_Length = 36;
46 scsicmd.scsi_Command = cmd;
47 scsicmd.scsi_CmdLength = sizeof cmd;
48 scsicmd.scsi_Flags = SCSIF_READ;
49 ioreq->io_Command = HD_SCSICMD;
50 ioreq->io_Data = &scsicmd;
51 ioreq->io_Length = sizeof(struct SCSICmd);
53 if (DoIO((struct IORequest *)ioreq))
54 return FALSE;
56 name[0] = 0;
57 i = 4 + data[4];
58 if (i >= 16)
59 strcatlen(name, &data[8], 8);
60 if (i >= 32) {
61 strcat(name, " ");
62 strcatlen(name, &data[16], 16);
64 if (i >= 36) {
65 strcat(name, " ");
66 strcatlen(name, &data[32], 4);
68 return TRUE;
71 void findHDs(struct HDTBDevice *parent)
73 struct IOStdReq *ioreq;
74 struct MsgPort *mp;
75 struct HDNode *node;
76 int i;
78 D(bug("[HDToolBox] findHDs()\n"));
80 mp = CreateMsgPort();
81 if (mp)
83 ioreq = (struct IOStdReq *)CreateIORequest(mp, sizeof(struct IOStdReq));
84 if (ioreq)
86 int maxunits = 8;
87 if (parent->maxunits > maxunits)
88 maxunits = parent->maxunits;
90 for (i=0;i<maxunits;i++)
92 node = AllocMem(sizeof(struct HDNode), MEMF_PUBLIC | MEMF_CLEAR);
93 if (node)
95 node->root_partition.listnode.ln.ln_Name = AllocVec(100, MEMF_PUBLIC | MEMF_CLEAR);
96 if (node->root_partition.listnode.ln.ln_Name)
98 if (InitListNode(&node->root_partition.listnode, (struct ListNode *)parent))
100 node->root_partition.listnode.ln.ln_Type = LNT_Harddisk;
101 node->unit = i;
102 if (OpenDevice(parent->listnode.ln.ln_Name, i, (struct IORequest *)ioreq, 0) == 0)
104 D(bug("[HDToolBox] findHDs: Opened %s:%d\n",parent->listnode.ln.ln_Name, i));
105 if (!identify(ioreq, node->root_partition.listnode.ln.ln_Name))
106 sprintf(node->root_partition.listnode.ln.ln_Name, "Unit %d", i);
107 CloseDevice((struct IORequest *)ioreq);
108 node->root_partition.ph = OpenRootPartition(parent->listnode.ln.ln_Name, node->unit);
109 if (node->root_partition.ph)
111 D(bug("[HDToolBox] - appending ROOT partition %p to list %p\n", &node->root_partition.listnode.ln, &parent->listnode.list));
112 D(bug("[HDToolBox] - first entry at %p\n", node->root_partition.listnode.list.lh_Head));
113 AddTail(&parent->listnode.list, &node->root_partition.listnode.ln);
114 if (findPartitionTable(&node->root_partition))
116 D(bug("[HDToolBox] - partition table found. searching for partitions\n"));
117 findPartitions(&node->root_partition.listnode, &node->root_partition);
118 node->root_partition.listnode.flags |= LNF_Listable;
120 else
122 D(bug("[HDToolBox] - partition table not found.\n"));
124 GetPartitionAttrsA
126 node->root_partition.ph,
127 PT_GEOMETRY, &node->root_partition.dg,
128 PT_DOSENVEC, &node->root_partition.de,
129 TAG_DONE
131 continue;
134 UninitListNode(&node->root_partition.listnode);
136 FreeVec(node->root_partition.listnode.ln.ln_Name);
138 FreeMem(node, sizeof(struct HDNode));
141 DeleteIORequest((struct IORequest *)ioreq);
143 DeleteMsgPort(mp);
145 D(bug("[HDToolBox] findHDs() successful\n"));
148 void freeHDList(struct List *list)
150 struct HDNode *node;
151 struct HDNode *next;
153 D(bug("[HDToolBox] freeHDList(%p)\n", list));
155 node = (struct HDNode *)list->lh_Head;
156 while (node->root_partition.listnode.ln.ln_Succ)
158 next = (struct HDNode *)node->root_partition.listnode.ln.ln_Succ;
159 if (node->root_partition.listnode.ln.ln_Type != LNT_Parent)
161 Remove(&node->root_partition.listnode.ln);
162 if (node->root_partition.table)
164 freePartitionList(&node->root_partition.listnode.list);
165 freePartitionTable(&node->root_partition);
167 CloseRootPartition(node->root_partition.ph);
168 UninitListNode(&node->root_partition.listnode);
169 FreeVec(node->root_partition.listnode.ln.ln_Name);
170 FreeMem(node, sizeof(struct HDNode));
172 node = next;