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