devtab.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Stub.
  11. */
  12. #include "u.h"
  13. #include "../port/lib.h"
  14. #include "mem.h"
  15. #include "dat.h"
  16. #include "fns.h"
  17. #include "../port/error.h"
  18. extern Dev* devtab[];
  19. void
  20. devtabreset(void)
  21. {
  22. int i;
  23. for(i = 0; devtab[i] != nil; i++) {
  24. devtab[i]->reset();
  25. }
  26. }
  27. void
  28. devtabinit(void)
  29. {
  30. int i;
  31. for(i = 0; devtab[i] != nil; i++) {
  32. devtab[i]->init();
  33. }
  34. }
  35. void
  36. devtabshutdown(void)
  37. {
  38. int i;
  39. /*
  40. * Shutdown in reverse order.
  41. */
  42. for(i = 0; devtab[i] != nil; i++)
  43. ;
  44. for(i--; i >= 0; i--)
  45. devtab[i]->shutdown();
  46. }
  47. Dev*
  48. devtabget(int dc, int user)
  49. {
  50. int i;
  51. for(i = 0; devtab[i] != nil; i++){
  52. if(devtab[i]->dc == dc)
  53. return devtab[i];
  54. }
  55. if(user == 0)
  56. panic("devtabget %C\n", dc);
  57. return nil;
  58. }
  59. int32_t
  60. devtabread(Chan* c, void* buf, int32_t n, int64_t off)
  61. {
  62. Proc *up = externup();
  63. int i;
  64. Dev *dev;
  65. char *alloc, *e, *p;
  66. alloc = malloc(READSTR);
  67. if(alloc == nil)
  68. error(Enomem);
  69. p = alloc;
  70. e = p + READSTR;
  71. for(i = 0; devtab[i] != nil; i++){
  72. dev = devtab[i];
  73. p = seprint(p, e, "#%C %s\n", dev->dc, dev->name);
  74. }
  75. if(waserror()){
  76. free(alloc);
  77. nexterror();
  78. }
  79. n = readstr(off, buf, n, alloc);
  80. free(alloc);
  81. poperror();
  82. return n;
  83. }