smbtree.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "headers.h"
  10. typedef struct DisconnectData {
  11. SmbSession *s;
  12. SmbTree *t;
  13. } DisconnectData;
  14. static void
  15. smbtreefree(SmbTree **tp)
  16. {
  17. SmbTree *t = *tp;
  18. if (t) {
  19. smbserviceput(t->serv);
  20. free(t);
  21. *tp = nil;
  22. }
  23. }
  24. static void
  25. closesearch(void *magic, void *a)
  26. {
  27. SmbSearch *search = a;
  28. DisconnectData *d = magic;
  29. if (search->t == d->t)
  30. smbsearchclose(d->s, search);
  31. }
  32. static void
  33. closefile(void *magic, void *a)
  34. {
  35. SmbFile *f = a;
  36. DisconnectData *d = magic;
  37. if (f->t == d->t)
  38. smbfileclose(d->s, f);
  39. }
  40. void
  41. smbtreedisconnect(SmbSession *s, SmbTree *t)
  42. {
  43. if (t) {
  44. DisconnectData data;
  45. smblogprintif(smbglobals.log.tids, "smbtreedisconnect: 0x%.4x\n", t->id);
  46. data.s = s;
  47. data.t = t;
  48. smbserviceput(t->serv);
  49. smbidmapapply(s->sidmap, closesearch, &data);
  50. smbidmapapply(s->fidmap, closefile, &data);
  51. smbidmapremove(s->tidmap, t);
  52. smbtreefree(&t);
  53. }
  54. }
  55. void
  56. smbtreedisconnectbyid(SmbSession *s, uint16_t id)
  57. {
  58. smbtreedisconnect(s, smbidmapfind(s->tidmap, id));
  59. }
  60. SmbTree *
  61. smbtreeconnect(SmbSession *s, SmbService *serv)
  62. {
  63. SmbTree *t;
  64. if (s->tidmap == nil)
  65. s->tidmap = smbidmapnew();
  66. t = smbemallocz(sizeof(*t), 1);
  67. smbidmapadd(s->tidmap, t);
  68. t->serv = serv;
  69. smbserviceget(serv);
  70. smblogprintif(smbglobals.log.tids, "smbtreeconnect: 0x%.4x\n", t->id);
  71. return t;
  72. }