Fixed AutoDoc indentation, spelling, grammar.
[AROS.git] / workbench / tools / HDToolBox / harddisks.c
bloba5178a57756aa5274343e85883ecfa659fc18e07
1 /*
2 Copyright © 1995-2008, 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 void w2strcpy(STRPTR name, UWORD *wstr, ULONG len)
26 while (len)
28 *((UWORD *)name) = AROS_BE2WORD(*wstr);
29 name += sizeof(UWORD);
30 len -= 2;
31 wstr++;
33 name -= 2;
34 while ((*name==0) || (*name==' '))
35 *name-- = 0;
38 BOOL identify(struct IOStdReq *ioreq, STRPTR name)
40 struct SCSICmd scsicmd;
41 UWORD data[256];
42 UBYTE cmd = 0xEC; /* identify */
44 D(bug("[HDToolBox] identify('%s')\n", name));
46 scsicmd.scsi_Data = data;
47 scsicmd.scsi_Length = 512;
48 scsicmd.scsi_Command = &cmd;
49 scsicmd.scsi_CmdLength = 1;
50 ioreq->io_Command = HD_SCSICMD;
51 ioreq->io_Data = &scsicmd;
52 ioreq->io_Length = sizeof(struct SCSICmd);
54 if (DoIO((struct IORequest *)ioreq))
55 return FALSE;
57 w2strcpy(name, &data[27], 40);
58 return TRUE;
61 void findHDs(struct HDTBDevice *parent)
63 struct IOStdReq *ioreq;
64 struct MsgPort *mp;
65 struct HDNode *node;
66 int i;
68 D(bug("[HDToolBox] findHDs()\n"));
70 mp = CreateMsgPort();
71 if (mp)
73 ioreq = (struct IOStdReq *)CreateIORequest(mp, sizeof(struct IOStdReq));
74 if (ioreq)
76 int maxunits = 8;
77 if (parent->maxunits > maxunits)
78 maxunits = parent->maxunits;
80 for (i=0;i<maxunits;i++)
82 node = AllocMem(sizeof(struct HDNode), MEMF_PUBLIC | MEMF_CLEAR);
83 if (node)
85 node->root_partition.listnode.ln.ln_Name = AllocVec(100, MEMF_PUBLIC | MEMF_CLEAR);
86 if (node->root_partition.listnode.ln.ln_Name)
88 if (InitListNode(&node->root_partition.listnode, (struct ListNode *)parent))
90 node->root_partition.listnode.ln.ln_Type = LNT_Harddisk;
91 node->unit = i;
92 if (OpenDevice(parent->listnode.ln.ln_Name, i, (struct IORequest *)ioreq, 0) == 0)
94 D(bug("[HDToolBox] findHDs: Opened %s:%d\n",parent->listnode.ln.ln_Name, i));
95 if (!identify(ioreq, node->root_partition.listnode.ln.ln_Name))
96 sprintf(node->root_partition.listnode.ln.ln_Name, "Unit %d", i);
97 CloseDevice((struct IORequest *)ioreq);
98 node->root_partition.ph = OpenRootPartition(parent->listnode.ln.ln_Name, node->unit);
99 if (node->root_partition.ph)
101 D(bug("[HDToolBox] - appending ROOT partition %p to list %p\n", &node->root_partition.listnode.ln, &parent->listnode.list));
102 D(bug("[HDToolBox] - first entry at %p\n", node->root_partition.listnode.list.lh_Head));
103 AddTail(&parent->listnode.list, &node->root_partition.listnode.ln);
104 if (findPartitionTable(&node->root_partition))
106 D(bug("[HDToolBox] - partition table found. searching for partitions\n"));
107 findPartitions(&node->root_partition.listnode, &node->root_partition);
108 node->root_partition.listnode.flags |= LNF_Listable;
110 else
112 D(bug("[HDToolBox] - partition table not found.\n"));
114 GetPartitionAttrsA
116 node->root_partition.ph,
117 PT_GEOMETRY, &node->root_partition.dg,
118 PT_DOSENVEC, &node->root_partition.de,
119 TAG_DONE
121 continue;
124 UninitListNode(&node->root_partition.listnode);
126 FreeVec(node->root_partition.listnode.ln.ln_Name);
128 FreeMem(node, sizeof(struct HDNode));
131 DeleteIORequest((struct IORequest *)ioreq);
133 DeleteMsgPort(mp);
135 D(bug("[HDToolBox] findHDs() successful\n"));
138 void freeHDList(struct List *list)
140 struct HDNode *node;
141 struct HDNode *next;
143 D(bug("[HDToolBox] freeHDList()\n"));
145 node = (struct HDNode *)list->lh_Head;
146 while (node->root_partition.listnode.ln.ln_Succ)
148 next = (struct HDNode *)node->root_partition.listnode.ln.ln_Succ;
149 if (node->root_partition.listnode.ln.ln_Type != LNT_Parent)
151 Remove(&node->root_partition.listnode.ln);
152 if (node->root_partition.table)
154 freePartitionList(&node->root_partition.listnode.list);
155 freePartitionTable(&node->root_partition);
157 CloseRootPartition(node->root_partition.ph);
158 UninitListNode(&node->root_partition.listnode);
159 FreeVec(node->root_partition.listnode.ln.ln_Name);
160 FreeMem(node, sizeof(struct HDNode));
162 node = next;