2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
6 #include <proto/exec.h>
7 #include <proto/partition.h>
9 #include <devices/scsidisk.h>
11 #include <exec/memory.h>
18 #include "harddisks.h"
19 #include "hdtoolbox_support.h"
22 extern struct GUIGadgets gadgets
;
24 void w2strcpy(STRPTR name
, UWORD
*wstr
, ULONG len
)
28 *((UWORD
*)name
) = AROS_BE2WORD(*wstr
);
29 name
+= sizeof(UWORD
);
34 while ((*name
==0) || (*name
==' '))
38 BOOL
identify(struct IOStdReq
*ioreq
, STRPTR name
)
40 struct SCSICmd scsicmd
;
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
))
57 w2strcpy(name
, &data
[27], 40);
61 void findHDs(struct HDTBDevice
*parent
)
63 struct IOStdReq
*ioreq
;
68 D(bug("[HDToolBox] findHDs()\n"));
73 ioreq
= (struct IOStdReq
*)CreateIORequest(mp
, sizeof(struct IOStdReq
));
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
);
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
;
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
;
112 D(bug("[HDToolBox] - partition table not found.\n"));
116 node
->root_partition
.ph
,
117 PT_GEOMETRY
, &node
->root_partition
.dg
,
118 PT_DOSENVEC
, &node
->root_partition
.de
,
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
);
135 D(bug("[HDToolBox] findHDs() successful\n"));
138 void freeHDList(struct List
*list
)
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
));