revert between 56095 -> 55830 in arch
[AROS.git] / workbench / c / DevList.c
blobd04f7c262902658bab80eac10f84fb505a383321
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 /******************************************************************************
12 NAME
14 DevList
16 SYNOPSIS
18 (N/A)
20 LOCATION
24 FUNCTION
26 Prints a list of all devices.
28 INPUTS
30 RESULT
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
40 INTERNALS
42 HISTORY
44 ******************************************************************************/
46 #include <exec/memory.h>
47 #include <exec/tasks.h>
48 #include <exec/execbase.h>
49 #include <exec/devices.h>
50 #include <proto/exec.h>
51 #include <dos/dosextens.h>
52 #include <proto/dos.h>
54 #if defined(__AROSPLATFORM_SMP__)
55 #include <aros/types/spinlock_s.h>
56 #include <proto/execlock.h>
57 #include <resources/execlock.h>
58 #endif
60 const TEXT version[] = "$VER: DevList 41.1 (14.3.1997)\n";
62 struct dev
64 STRPTR name;
65 APTR address;
66 WORD version;
67 WORD revision;
68 ULONG flags;
69 WORD opencnt;
72 static int adddev(struct Device *dev, struct dev **l, STRPTR *e)
74 STRPTR s1, s2;
76 (*l)->address = dev;
77 (*l)->version = dev->dd_Library.lib_Version;
78 (*l)->revision = dev->dd_Library.lib_Revision;
79 (*l)->opencnt = dev->dd_Library.lib_OpenCnt;
80 (*l)->flags = dev->dd_Library.lib_Flags;
82 s1 = dev->dd_Library.lib_Node.ln_Name;
84 if(s1!=NULL)
86 s2=s1;
87 while(*s2++)
89 while(s2>s1)
91 if(*e<=(STRPTR)(*l+2))
92 return 0;
93 *--(*e)=*--s2;
96 if((STRPTR)(*l+2)>*e)
97 return 0;
99 (*l)->name=*e;
100 ++*l;
102 return 1;
105 static int fillbuffer(struct dev **buffer, IPTR size)
107 STRPTR end=(STRPTR)*buffer+size;
108 struct Device *dev;
109 #if defined(__AROSPLATFORM_SMP__)
110 void *ExecLockBase = OpenResource("execlock.resource");
111 #endif
113 #if defined(__AROSPLATFORM_SMP__)
114 if (ExecLockBase)
115 ObtainSystemLock(&SysBase->DeviceList, SPINLOCK_MODE_READ, LOCKF_FORBID);
116 else
117 Forbid();
118 #else
119 Forbid();
120 #endif
121 for(dev=(struct Device *)SysBase->DeviceList.lh_Head;
122 dev->dd_Library.lib_Node.ln_Succ!=NULL;
123 dev=(struct Device *)dev->dd_Library.lib_Node.ln_Succ)
124 if(!adddev(dev,buffer,&end))
126 #if defined(__AROSPLATFORM_SMP__)
127 if (ExecLockBase)
128 ReleaseSystemLock(&SysBase->DeviceList, LOCKF_FORBID);
129 else
130 Permit();
131 #else
132 Permit();
133 #endif
134 return 0;
136 #if defined(__AROSPLATFORM_SMP__)
137 if (ExecLockBase)
138 ReleaseSystemLock(&SysBase->DeviceList, LOCKF_FORBID);
139 else
140 Permit();
141 #else
142 Permit();
143 #endif
144 return 1;
147 int __nocommandline = 1;
149 int main(void)
151 IPTR size;
152 struct dev *buffer,*devs,*devs2;
153 LONG error=RETURN_OK;
155 for(size=2048;;size+=2048)
157 buffer=AllocVec(size,MEMF_ANY);
158 if(buffer==NULL)
160 FPuts(Output(),"Not Enough memory for device buffer\n");
161 return 20;
163 devs=buffer;
164 if(fillbuffer(&devs,size))
166 #if (__WORDSIZE == 64)
167 FPuts(Output()," Address Version Rev OpenCnt Flags Name\n");
168 #else
169 FPuts(Output()," Address Version Rev OpenCnt Flags Name\n");
170 #endif
171 for(devs2=buffer;devs2<devs;devs2++)
173 #if (__WORDSIZE == 64)
174 Printf("0x%012.ix %7ld %4ld %7ld 0x%02lx %s\n",
175 #else
176 Printf("0x%08.ix %7ld %4ld %7ld 0x%02lx %s\n",
177 #endif
178 devs2->address, devs2->version,
179 devs2->revision, devs2->opencnt,
180 devs2->flags, devs2->name);
181 if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
183 error = RETURN_FAIL;
184 SetIoErr(ERROR_BREAK);
185 break;
188 FreeVec(buffer);
189 break;
191 FreeVec(buffer);
193 if (error != RETURN_OK)
195 PrintFault(IoErr(), NULL);
197 return(error);