convM2D.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "lib.h"
  2. #include <string.h>
  3. #include "sys9.h"
  4. #include "dir.h"
  5. #define nil ((void*)0)
  6. static char nullstring[] = "";
  7. uint
  8. _convM2D(uchar *buf, uint nbuf, Dir *d, char *strs)
  9. {
  10. uchar *p, *ebuf;
  11. char *sv[4];
  12. int i, ns, nsv[4];
  13. p = buf;
  14. ebuf = buf + nbuf;
  15. p += BIT16SZ; /* ignore size */
  16. d->type = GBIT16(p);
  17. p += BIT16SZ;
  18. d->dev = GBIT32(p);
  19. p += BIT32SZ;
  20. d->qid.type = GBIT8(p);
  21. p += BIT8SZ;
  22. d->qid.vers = GBIT32(p);
  23. p += BIT32SZ;
  24. d->qid.path = GBIT64(p);
  25. p += BIT64SZ;
  26. d->mode = GBIT32(p);
  27. p += BIT32SZ;
  28. d->atime = GBIT32(p);
  29. p += BIT32SZ;
  30. d->mtime = GBIT32(p);
  31. p += BIT32SZ;
  32. d->length = GBIT64(p);
  33. p += BIT64SZ;
  34. d->name = nil;
  35. d->uid = nil;
  36. d->gid = nil;
  37. d->muid = nil;
  38. for(i = 0; i < 4; i++){
  39. if(p + BIT16SZ > ebuf)
  40. return 0;
  41. ns = GBIT16(p);
  42. p += BIT16SZ;
  43. if(p + ns > ebuf)
  44. return 0;
  45. if(strs){
  46. nsv[i] = ns;
  47. sv[i] = strs;
  48. memmove(strs, p, ns);
  49. strs += ns;
  50. *strs++ = '\0';
  51. }
  52. p += ns;
  53. }
  54. if(strs){
  55. d->name = sv[0];
  56. d->uid = sv[1];
  57. d->gid = sv[2];
  58. d->muid = sv[3];
  59. }else{
  60. d->name = nullstring;
  61. d->uid = nullstring;
  62. d->gid = nullstring;
  63. d->muid = nullstring;
  64. }
  65. return p - buf;
  66. }