info.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include <fcall.h>
  5. #include <thread.h>
  6. #include <9p.h>
  7. #include "cifs.h"
  8. struct {
  9. char *name;
  10. int (*func)(Fmt *f);
  11. char *buf;
  12. int len;
  13. } Infdir[] = {
  14. { "Users", userinfo },
  15. { "Groups", groupinfo },
  16. { "Shares", shareinfo },
  17. { "Connection", conninfo },
  18. { "Sessions", sessioninfo },
  19. { "Dfsroot", dfsrootinfo },
  20. { "Dfscache", dfscacheinfo },
  21. { "Domains", domaininfo },
  22. { "Openfiles", openfileinfo },
  23. { "Workstations", workstationinfo },
  24. { "Filetable", filetableinfo },
  25. };
  26. int
  27. walkinfo(char *name)
  28. {
  29. int i;
  30. for(i = 0; i < nelem(Infdir); i++)
  31. if(strcmp(Infdir[i].name, name) == 0)
  32. return(i);
  33. return -1;
  34. }
  35. int
  36. numinfo(void)
  37. {
  38. return nelem(Infdir);
  39. }
  40. int
  41. dirgeninfo(int slot, Dir *d)
  42. {
  43. if(slot < 0 || slot > nelem(Infdir))
  44. return -1;
  45. memset(d, 0, sizeof(Dir));
  46. d->type = 'N';
  47. d->dev = 99;
  48. d->name = estrdup9p(Infdir[slot].name);
  49. d->uid = estrdup9p("other");
  50. d->muid = estrdup9p("other");
  51. d->gid = estrdup9p("other");
  52. d->mode = 0666;
  53. d->atime = time(0);
  54. d->mtime = d->atime;
  55. d->qid = mkqid(Infdir[slot].name, 0, 1, Pinfo, slot);
  56. d->qid.vers = 1;
  57. d->qid.path = slot;
  58. d->qid.type = 0;
  59. return 0;
  60. }
  61. int
  62. makeinfo(int path)
  63. {
  64. Fmt f;
  65. if(path < 0 || path > nelem(Infdir))
  66. return -1;
  67. if(Infdir[path].buf != nil)
  68. return 0;
  69. fmtstrinit(&f);
  70. if((*Infdir[path].func)(&f) == -1l)
  71. return -1;
  72. Infdir[path].buf = fmtstrflush(&f);
  73. Infdir[path].len = strlen(Infdir[path].buf);
  74. return 0;
  75. }
  76. int
  77. readinfo(int path, char *buf, int len, int off)
  78. {
  79. if(path < 0 || path > nelem(Infdir))
  80. return -1;
  81. if(off > Infdir[path].len)
  82. return 0;
  83. if(len + off > Infdir[path].len)
  84. len = Infdir[path].len - off;
  85. memmove(buf, Infdir[path].buf + off, len);
  86. return len;
  87. }
  88. void
  89. freeinfo(int path)
  90. {
  91. if(path < 0 || path > nelem(Infdir))
  92. return;
  93. free(Infdir[path].buf);
  94. Infdir[path].buf = nil;
  95. }