FreeCalypso > hg > freecalypso-sw
annotate ffstools/tiffs-rd/cat.c @ 563:a418c48046ad
L1: l1_init.c compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 08 Aug 2014 02:28:45 +0000 |
parents | c95efd27fb2e |
children |
rev | line source |
---|---|
240
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This C module implements the cat and catino commands. |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <unistd.h> |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "types.h" |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "struct.h" |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "globals.h" |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "pathname.h" |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 int cat_mode; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 static u8 hex_buf[16]; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 static int hex_fill; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 static u32 hex_offset; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 cat_hex_flush() |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 int i, c; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 printf("%08X: ", hex_offset); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 for (i = 0; i < 16; i++) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 if (i < hex_fill) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 printf("%02X ", hex_buf[i]); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 else |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 fputs(" ", stdout); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (i == 7 || i == 15) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 putchar(' '); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 for (i = 0; i < hex_fill; i++) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 c = hex_buf[i]; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 if (c < ' ' || c > '~') |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 c = '.'; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 putchar(c); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 putchar('\n'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 cat_hex_byte(inb) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 hex_buf[hex_fill++] = inb; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 if (hex_fill >= 16) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 cat_hex_flush(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 hex_offset += hex_fill; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 hex_fill = 0; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 void |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 cat_chunk(ch) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 struct chunkinfo *ch; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 u8 *p; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 int c; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 if (!ch->len) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 return; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 switch (cat_mode) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 case 0: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 write(1, ch->start, ch->len); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 return; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 case 1: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 for (p = ch->start; p < ch->end; p++) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 c = *p; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 if (c >= ' ' && c <= '~' || c == '\n') |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 putchar(c); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 else { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (c & 0x80) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 putchar('M'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 putchar('-'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 c &= 0x7F; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 putchar('^'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (c == 0x7F) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 putchar('?'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 else |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 putchar(c + '@'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 return; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 case 2: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 for (p = ch->start; p < ch->end; p++) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 cat_hex_byte(*p); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 return; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 void |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 cat_finish() |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 switch (cat_mode) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 case 1: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 putchar('\n'); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 return; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 case 2: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 if (hex_fill) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 cat_hex_flush(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 return; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 static void |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 segment_cat_callback(inf, opaque) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 struct inode_info *inf; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 u_long opaque; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 struct chunkinfo chi; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 size_extra_chunk(inf, &chi); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 cat_chunk(&chi); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 cmd_cat(argc, argv) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 char **argv; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 extern int optind; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 int c, headino; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 struct inode_info *inf; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 struct chunkinfo chi; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 optind = 0; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 while ((c = getopt(argc, argv, "hv")) != EOF) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 switch (c) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 case 'h': |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 cat_mode = 2; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 continue; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 case 'v': |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 cat_mode = 1; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 continue; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 default: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 usage: fprintf(stderr, "usage: cat [-v|-h] pathname\n"); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 exit(1); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 if (argc != optind + 1) |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 goto usage; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 read_ffs_image(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 find_inode_block(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 alloc_inode_table(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 find_root_inode(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 headino = find_pathname(argv[optind]); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 inf = inode_info[headino]; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 switch (inf->type) { |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 case 0xE1: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 case 0xF1: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 break; |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 case 0xF2: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 fprintf(stderr, "error: the requested object is a directory\n"); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 exit(1); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 case 0xF3: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 fprintf(stderr, |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 "error: the requested object is a symlink; use readlink instead of cat\n"); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 exit(1); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 default: |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 fprintf(stderr, "error: unexpected object type %02X\n", |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 inf->type); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 exit(1); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 } |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 size_head_chunk(inf, &chi); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 cat_chunk(&chi); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 iterate_seg_file(headino, segment_cat_callback, 0L, 0, 0); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 cat_finish(); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 exit(0); |
acedd4c88d2e
tiffs cat command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 } |
241
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
171 |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
172 cmd_catino(argc, argv) |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
173 char **argv; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
174 { |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
175 extern int optind; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
176 int c, headino; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
177 struct inode_info *inf; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
178 struct chunkinfo chi; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
179 |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
180 optind = 0; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
181 while ((c = getopt(argc, argv, "hv")) != EOF) |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
182 switch (c) { |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
183 case 'h': |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
184 cat_mode = 2; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
185 continue; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
186 case 'v': |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
187 cat_mode = 1; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
188 continue; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
189 default: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
190 usage: fprintf(stderr, "usage: catino [-v|-h] ino\n"); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
191 exit(1); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
192 } |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
193 if (argc != optind + 1) |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
194 goto usage; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
195 headino = strtoul(argv[optind], 0, 16); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
196 |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
197 read_ffs_image(); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
198 find_inode_block(); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
199 alloc_inode_table(); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
200 if (!validate_inode(headino)) { |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
201 fprintf(stderr, "catino: specified inode number is invalid\n"); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
202 exit(1); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
203 } |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
204 inf = inode_info[headino]; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
205 switch (inf->type) { |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
206 case 0x00: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
207 case 0xE1: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
208 case 0xF1: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
209 case 0xF3: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
210 break; |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
211 case 0xF2: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
212 fprintf(stderr, "error: the requested object is a directory\n"); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
213 exit(1); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
214 default: |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
215 fprintf(stderr, "error: unexpected object type %02X\n", |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
216 inf->type); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
217 exit(1); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
218 } |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
219 if (!inf->len) { |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
220 fprintf(stderr, "error: requested inode has been reclaimed\n"); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
221 exit(1); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
222 } |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
223 if (!validate_obj_name(headino, 0)) { |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
224 fprintf(stderr, |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
225 "error: no valid name at the beginning of the requested seghead chunk\n"); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
226 exit(1); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
227 } |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
228 size_head_chunk(inf, &chi); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
229 cat_chunk(&chi); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
230 iterate_seg_file(headino, segment_cat_callback, 0L, !inf->type, 0); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
231 cat_finish(); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
232 exit(0); |
c95efd27fb2e
tiffs catino implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
240
diff
changeset
|
233 } |