alsa.audio: add debug logs
[AROS.git] / workbench / tools / HDToolBox / devices.c
blob4f1ccebe26970afd20f8e69e0c267a7c20a25896
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <exec/memory.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include "devices.h"
13 #include "gui.h"
14 #include "harddisks.h"
16 #define DEBUG 0
17 #include "debug.h"
19 extern struct GUIGadgets gadgets;
21 struct ListNode root;
23 struct HDTBDevice *addDevice(struct ListNode *parent, STRPTR name)
25 struct HDTBDevice *ln;
26 STRPTR seppoint = NULL;
27 int devnamelen = 0;
29 D(bug("[HDToolBox] addDevice('%s')\n", name));
31 seppoint = strstr(name, ":");
33 if (seppoint != NULL)
34 devnamelen = (int)(seppoint - name);
35 else
36 devnamelen = strlen(name);
38 ln = AllocMem(sizeof(struct HDTBDevice), MEMF_PUBLIC | MEMF_CLEAR);
39 if (ln)
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));
50 if (seppoint != NULL)
52 ln->maxunits = atoi(name + devnamelen + 1);
53 D(bug("[HDToolBox] addDevice: maxunits %d\n", ln->maxunits));
56 findHDs(ln);
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);
69 return ln;
71 FreeVec(ln->listnode.ln.ln_Name);
73 FreeMem(ln, sizeof(struct HDTBDevice));
75 return NULL;
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);
110 node = next;
112 UninitListNode(&root);