info.c 2.2 KB

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