2 Copyright © 1995-2012, 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
)
30 *((UWORD
*)p
) = AROS_BE2WORD(*wstr
);
36 while (p
>= name
&& (*p
== 0 || *p
== ' '))
40 BOOL
identify(struct IOStdReq
*ioreq
, STRPTR name
)
42 struct SCSICmd scsicmd
= {0};
44 UBYTE cmd
= 0xEC; /* identify */
46 D(bug("[HDToolBox] identify('%s')\n", name
));
48 scsicmd
.scsi_Data
= data
;
49 scsicmd
.scsi_Length
= 512;
50 scsicmd
.scsi_Command
= &cmd
;
51 scsicmd
.scsi_CmdLength
= 1;
52 ioreq
->io_Command
= HD_SCSICMD
;
53 ioreq
->io_Data
= &scsicmd
;
54 ioreq
->io_Length
= sizeof(struct SCSICmd
);
56 if (DoIO((struct IORequest
*)ioreq
))
59 w2strcpy(name
, &data
[27], 40);
63 void findHDs(struct HDTBDevice
*parent
)
65 struct IOStdReq
*ioreq
;
70 D(bug("[HDToolBox] findHDs()\n"));
75 ioreq
= (struct IOStdReq
*)CreateIORequest(mp
, sizeof(struct IOStdReq
));
79 if (parent
->maxunits
> maxunits
)
80 maxunits
= parent
->maxunits
;
82 for (i
=0;i
<maxunits
;i
++)
84 node
= AllocMem(sizeof(struct HDNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
87 node
->root_partition
.listnode
.ln
.ln_Name
= AllocVec(100, MEMF_PUBLIC
| MEMF_CLEAR
);
88 if (node
->root_partition
.listnode
.ln
.ln_Name
)
90 if (InitListNode(&node
->root_partition
.listnode
, (struct ListNode
*)parent
))
92 node
->root_partition
.listnode
.ln
.ln_Type
= LNT_Harddisk
;
94 if (OpenDevice(parent
->listnode
.ln
.ln_Name
, i
, (struct IORequest
*)ioreq
, 0) == 0)
96 D(bug("[HDToolBox] findHDs: Opened %s:%d\n",parent
->listnode
.ln
.ln_Name
, i
));
97 if (!identify(ioreq
, node
->root_partition
.listnode
.ln
.ln_Name
))
98 sprintf(node
->root_partition
.listnode
.ln
.ln_Name
, "Unit %d", i
);
99 CloseDevice((struct IORequest
*)ioreq
);
100 node
->root_partition
.ph
= OpenRootPartition(parent
->listnode
.ln
.ln_Name
, node
->unit
);
101 if (node
->root_partition
.ph
)
103 D(bug("[HDToolBox] - appending ROOT partition %p to list %p\n", &node
->root_partition
.listnode
.ln
, &parent
->listnode
.list
));
104 D(bug("[HDToolBox] - first entry at %p\n", node
->root_partition
.listnode
.list
.lh_Head
));
105 AddTail(&parent
->listnode
.list
, &node
->root_partition
.listnode
.ln
);
106 if (findPartitionTable(&node
->root_partition
))
108 D(bug("[HDToolBox] - partition table found. searching for partitions\n"));
109 findPartitions(&node
->root_partition
.listnode
, &node
->root_partition
);
110 node
->root_partition
.listnode
.flags
|= LNF_Listable
;
114 D(bug("[HDToolBox] - partition table not found.\n"));
118 node
->root_partition
.ph
,
119 PT_GEOMETRY
, &node
->root_partition
.dg
,
120 PT_DOSENVEC
, &node
->root_partition
.de
,
126 UninitListNode(&node
->root_partition
.listnode
);
128 FreeVec(node
->root_partition
.listnode
.ln
.ln_Name
);
130 FreeMem(node
, sizeof(struct HDNode
));
133 DeleteIORequest((struct IORequest
*)ioreq
);
137 D(bug("[HDToolBox] findHDs() successful\n"));
140 void freeHDList(struct List
*list
)
145 D(bug("[HDToolBox] freeHDList(%p)\n", list
));
147 node
= (struct HDNode
*)list
->lh_Head
;
148 while (node
->root_partition
.listnode
.ln
.ln_Succ
)
150 next
= (struct HDNode
*)node
->root_partition
.listnode
.ln
.ln_Succ
;
151 if (node
->root_partition
.listnode
.ln
.ln_Type
!= LNT_Parent
)
153 Remove(&node
->root_partition
.listnode
.ln
);
154 if (node
->root_partition
.table
)
156 freePartitionList(&node
->root_partition
.listnode
.list
);
157 freePartitionTable(&node
->root_partition
);
159 CloseRootPartition(node
->root_partition
.ph
);
160 UninitListNode(&node
->root_partition
.listnode
);
161 FreeVec(node
->root_partition
.listnode
.ln
.ln_Name
);
162 FreeMem(node
, sizeof(struct HDNode
));