smbdircache.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. SmbDirCache *
  11. smbmkdircache(SmbTree *t, char *path)
  12. {
  13. int32_t n;
  14. SmbDirCache *c;
  15. Dir *buf;
  16. int fd;
  17. char *fullpath = nil;
  18. smbstringprint(&fullpath, "%s%s", t->serv->path, path);
  19. //smblogprintif(1, "smbmkdircache: path %s\n", fullpath);
  20. fd = open(fullpath, OREAD);
  21. free(fullpath);
  22. if (fd < 0)
  23. return nil;
  24. n = dirreadall(fd, &buf);
  25. close(fd);
  26. if (n < 0) {
  27. free(buf);
  28. return nil;
  29. }
  30. c = smbemalloc(sizeof(SmbDirCache));
  31. c->buf = buf;
  32. c->n = n;
  33. c->i = 0;
  34. return c;
  35. }
  36. void
  37. smbdircachefree(SmbDirCache **cp)
  38. {
  39. SmbDirCache *c;
  40. c = *cp;
  41. if (c) {
  42. free(c->buf);
  43. free(c);
  44. *cp = nil;
  45. }
  46. }