2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
6 #include <proto/exec.h>
7 #include <exec/memory.h>
14 #include "harddisks.h"
19 extern struct GUIGadgets gadgets
;
23 struct HDTBDevice
*addDevice(struct ListNode
*parent
, STRPTR name
)
25 struct HDTBDevice
*ln
;
26 STRPTR seppoint
= NULL
;
29 D(bug("[HDToolBox] addDevice('%s')\n", name
));
31 seppoint
= strstr(name
, ":");
34 devnamelen
= (int)(seppoint
- name
);
36 devnamelen
= strlen(name
);
38 ln
= AllocMem(sizeof(struct HDTBDevice
), MEMF_PUBLIC
| MEMF_CLEAR
);
41 ln
->listnode
.ln
.ln_Name
= AllocVec(devnamelen
+1, MEMF_PUBLIC
| MEMF_CLEAR
);
42 if (ln
->listnode
.ln
.ln_Name
)
44 if (InitListNode(&ln
->listnode
, parent
))
46 ln
->listnode
.ln
.ln_Type
= LNT_Device
;
47 CopyMem(name
, ln
->listnode
.ln
.ln_Name
, devnamelen
);
48 D(bug("[HDToolBox] addDevice: device '%s'\n", ln
->listnode
.ln
.ln_Name
));
52 ln
->maxunits
= atoi(name
+ devnamelen
+ 1);
53 D(bug("[HDToolBox] addDevice: maxunits %d\n", ln
->maxunits
));
59 * check if device carries at least one element (empty partition?)
61 if (ln
->listnode
.list
.lh_Head
->ln_Succ
->ln_Succ
)
62 ln
->listnode
.flags
|= LNF_Listable
;
65 * add device to the list
67 InsertList(gadgets
.leftlv
, &ln
->listnode
);
68 AddTail(&parent
->list
, &ln
->listnode
.ln
);
71 FreeVec(ln
->listnode
.ln
.ln_Name
);
73 FreeMem(ln
, sizeof(struct HDTBDevice
));
78 struct HDTBDevice
*addDeviceName(STRPTR name
)
80 D(bug("[HDToolBox] addDeviceName('%s')\n", name
));
82 return addDevice(&root
, name
);
85 void freeDeviceNode(struct HDTBDevice
*node
)
87 D(bug("[HDToolBox] freeDeviceNode()\n"));
89 freeHDList(&node
->listnode
.list
);
90 FreeVec(node
->listnode
.ln
.ln_Name
);
91 FreeMem(node
, sizeof(struct HDTBDevice
));
94 void freeDeviceList(void)
96 struct HDTBDevice
*node
;
97 struct HDTBDevice
*next
;
99 D(bug("[HDToolBox] freeDeviceList()\n"));
101 node
= (struct HDTBDevice
*)root
.list
.lh_Head
;
102 while (node
->listnode
.ln
.ln_Succ
)
104 next
= (struct HDTBDevice
*)node
->listnode
.ln
.ln_Succ
;
105 if (node
->listnode
.ln
.ln_Type
!= LNT_Parent
)
107 Remove(&node
->listnode
.ln
);
108 freeDeviceNode(node
);
112 UninitListNode(&root
);