devtab.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. void
  27. devtabinit(void)
  28. {
  29. int i;
  30. for(i = 0; devtab[i] != nil; i++)
  31. devtab[i]->init();
  32. }
  33. void
  34. devtabshutdown(void)
  35. {
  36. int i;
  37. /*
  38. * Shutdown in reverse order.
  39. */
  40. for(i = 0; devtab[i] != nil; i++)
  41. ;
  42. for(i--; i >= 0; i--)
  43. devtab[i]->shutdown();
  44. }
  45. Dev*
  46. devtabget(int dc, int user)
  47. {
  48. int i;
  49. for(i = 0; devtab[i] != nil; i++){
  50. if(devtab[i]->dc == dc)
  51. return devtab[i];
  52. }
  53. if(user == 0)
  54. panic("devtabget %C\n", dc);
  55. return nil;
  56. }
  57. int32_t
  58. devtabread(Chan*, void* buf, int32_t n, int64_t off)
  59. {
  60. int i;
  61. Dev *dev;
  62. char *alloc, *e, *p;
  63. alloc = malloc(READSTR);
  64. if(alloc == nil)
  65. error(Enomem);
  66. p = alloc;
  67. e = p + READSTR;
  68. for(i = 0; devtab[i] != nil; i++){
  69. dev = devtab[i];
  70. p = seprint(p, e, "#%C %s\n", dev->dc, dev->name);
  71. }
  72. if(waserror()){
  73. free(alloc);
  74. nexterror();
  75. }
  76. n = readstr(off, buf, n, alloc);
  77. free(alloc);
  78. poperror();
  79. return n;
  80. }