2 Copyright © 1995-2013, 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 static void strcatlen(STRPTR dst
, UBYTE
*src
, UBYTE maxlen
)
27 memcpy(dst
, src
, maxlen
);
28 while (maxlen
-- > 0) {
29 if (dst
[maxlen
] != ' ')
35 static BOOL
identify(struct IOStdReq
*ioreq
, STRPTR name
)
37 struct SCSICmd scsicmd
= {0};
39 UBYTE cmd
[6] = { 0x12, 0, 0, 0, 36, 0 }; /* inquiry */
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
))
59 strcatlen(name
, &data
[8], 8);
62 strcatlen(name
, &data
[16], 16);
66 strcatlen(name
, &data
[32], 4);
71 void findHDs(struct HDTBDevice
*parent
)
73 struct IOStdReq
*ioreq
;
78 D(bug("[HDToolBox] findHDs()\n"));
83 ioreq
= (struct IOStdReq
*)CreateIORequest(mp
, sizeof(struct IOStdReq
));
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
);
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
;
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
;
122 D(bug("[HDToolBox] - partition table not found.\n"));
126 node
->root_partition
.ph
,
127 PT_GEOMETRY
, &node
->root_partition
.dg
,
128 PT_DOSENVEC
, &node
->root_partition
.de
,
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
);
145 D(bug("[HDToolBox] findHDs() successful\n"));
148 void freeHDList(struct List
*list
)
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
));