_dirconv.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "lib.h"
  2. #include <string.h>
  3. #include "sys9.h"
  4. #include "dir.h"
  5. #define CHAR(x) *p++ = f->x
  6. #define SHORT(x) p[0] = f->x; p[1] = f->x>>8; p += 2
  7. #define LONG(x) p[0] = f->x; p[1] = f->x>>8; p[2] = f->x>>16; p[3] = f->x>>24; p += 4
  8. #define VLONG(x) p[0] = f->x; p[1] = f->x>>8; p[2] = f->x>>16; p[3] = f->x>>24;\
  9. p[4] = 0; p[5] = 0; p[6] = 0; p[7] = 0; p += 8
  10. #define STRING(x,n) memcpy(p, f->x, n); p += n
  11. int
  12. convD2M(Dir *f, char *ap)
  13. {
  14. unsigned char *p;
  15. p = (unsigned char*)ap;
  16. STRING(name, sizeof(f->name));
  17. STRING(uid, sizeof(f->uid));
  18. STRING(gid, sizeof(f->gid));
  19. LONG(qid.path);
  20. LONG(qid.vers);
  21. LONG(mode);
  22. LONG(atime);
  23. LONG(mtime);
  24. VLONG(length);
  25. SHORT(type);
  26. SHORT(dev);
  27. return p - (unsigned char*)ap;
  28. }
  29. #undef CHAR
  30. #undef SHORT
  31. #undef LONG
  32. #undef VLONG
  33. #undef STRING
  34. #define CHAR(x) f->x = *p++
  35. #define SHORT(x) f->x = (p[0] | (p[1]<<8)); p += 2
  36. #define LONG(x) f->x = (p[0] | (p[1]<<8) |\
  37. (p[2]<<16) | (p[3]<<24)); p += 4
  38. #define VLONG(x) f->x = (p[0] | (p[1]<<8) |\
  39. (p[2]<<16) | (p[3]<<24)); p += 8
  40. #define STRING(x,n) memcpy(f->x, p, n); p += n
  41. int
  42. convM2D(char *ap, Dir *f)
  43. {
  44. unsigned char *p;
  45. p = (unsigned char*)ap;
  46. STRING(name, sizeof(f->name));
  47. STRING(uid, sizeof(f->uid));
  48. STRING(gid, sizeof(f->gid));
  49. LONG(qid.path);
  50. LONG(qid.vers);
  51. LONG(mode);
  52. LONG(atime);
  53. LONG(mtime);
  54. VLONG(length);
  55. SHORT(type);
  56. SHORT(dev);
  57. return p - (unsigned char*)ap;
  58. }