ft_dump.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* $MirOS: contrib/hosted/fwcf/ft_dump.c,v 1.5 2006/09/23 23:21:04 tg Exp $ */
  2. /*-
  3. * Copyright (c) 2006
  4. * Thorsten Glaser <tg@mirbsd.de>
  5. *
  6. * Licensee is hereby permitted to deal in this work without restric-
  7. * tion, including unlimited rights to use, publicly perform, modify,
  8. * merge, distribute, sell, give away or sublicence, provided all co-
  9. * pyright notices above, these terms and the disclaimer are retained
  10. * in all redistributions or reproduced in accompanying documentation
  11. * or other materials provided with binary redistributions.
  12. *
  13. * Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
  14. * express, or implied, to the maximum extent permitted by applicable
  15. * law, without malicious intent or gross negligence; in no event may
  16. * licensor, an author or contributor be held liable for any indirect
  17. * or other damage, or direct damage except proven a consequence of a
  18. * direct error of said person and intended use of this work, loss or
  19. * other issues arising in any way out of its use, even if advised of
  20. * the possibility of such damage or existence of a defect.
  21. */
  22. #include <sys/param.h>
  23. #include <err.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <unistd.h>
  28. #include "defs.h"
  29. #include "pack.h"
  30. __RCSID("$MirOS: contrib/hosted/fwcf/ft_dump.c,v 1.5 2006/09/23 23:21:04 tg Exp $");
  31. static int ft_dumpfile(char *);
  32. void
  33. ft_dump(char *buf)
  34. {
  35. while (*buf)
  36. buf += ft_dumpfile(buf);
  37. }
  38. static int
  39. ft_dumpfile(char *buf)
  40. {
  41. uint8_t c;
  42. int i, type = 0, size = 0;
  43. uint8_t *p;
  44. uint32_t x;
  45. i = strlen(buf) + 1;
  46. printf("\nNAME=%s\n", buf);
  47. p = (uint8_t *)buf + i;
  48. while (*p)
  49. switch (c = *p++) {
  50. case 0x01:
  51. printf("BLOCK\n");
  52. type = 1;
  53. break;
  54. case 0x02:
  55. printf("CHARACTER\n");
  56. type = 1;
  57. break;
  58. case 0x03:
  59. printf("SYMLINK\n");
  60. type = 2;
  61. break;
  62. case 0x04:
  63. printf("HARDLINK\n");
  64. type = 1;
  65. break;
  66. case 0x05:
  67. printf("DIRECTORY\n");
  68. type = 1;
  69. break;
  70. case 0x10:
  71. {
  72. time_t y = LOADD(p);
  73. p += 4;
  74. printf("MTIME=%d -> %s", (int)y, ctime(&y));
  75. break;
  76. }
  77. case 'g':
  78. case 'G':
  79. case 'u':
  80. case 'U':
  81. x = (c & 0x20) ? *p : LOADD(p);
  82. p += (c & 0x20) ? 1 : 4;
  83. printf("%cID=%d\n", c & ~0x20, x);
  84. break;
  85. case 'i':
  86. case 'I':
  87. x = (c == 'i') ? *p : LOADW(p);
  88. p += (c == 'i') ? 1 : 2;
  89. printf("INODE=%d\n", x);
  90. break;
  91. case 'm':
  92. case 'M':
  93. x = (c == 'm') ? LOADW(p) : LOADD(p);
  94. p += (c == 'm') ? 2 : 4;
  95. printf("MODE=0%o\n", x);
  96. break;
  97. case 's':
  98. case 'S':
  99. x = (c == 's') ? *p : LOADT(p);
  100. p += (c == 's') ? 1 : 3;
  101. printf("SIZE=%d\n", size = x);
  102. break;
  103. default:
  104. errx(1, "unknown attribute %02Xh", c);
  105. }
  106. ++p;
  107. if (type == 2) {
  108. char *target;
  109. if ((target = malloc(size + 1)) == NULL)
  110. err(1, "malloc");
  111. memcpy(target, p, size);
  112. target[size] = '\0';
  113. printf("LINK_TARGET=%s\n", target);
  114. free(target);
  115. } else if (type == 1) {
  116. if (size)
  117. printf("WARN: size not allowed, ignoring\n");
  118. size = 0;
  119. } else {
  120. printf("BEGIN DATA\n");
  121. fflush(stdout);
  122. write(STDOUT_FILENO, p, size);
  123. printf("\nEND DATA\n");
  124. }
  125. return ((p - (uint8_t *)buf) + size);
  126. }