comparison ffstools/tiffs-rd/ls.c @ 919:1f27fc13eab7

tiffs: add support for extended filenames found in SE K2x0 FFS
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 31 Dec 2022 09:27:01 +0000
parents e7502631a0f9
children
comparison
equal deleted inserted replaced
918:0c33e24ff935 919:1f27fc13eab7
11 #include "struct.h" 11 #include "struct.h"
12 #include "globals.h" 12 #include "globals.h"
13 #include "pathname.h" 13 #include "pathname.h"
14 14
15 static void 15 static void
16 print_ext_obj_name(inf, desc)
17 struct inode_info *inf;
18 {
19 u8 *p;
20 int c;
21
22 printf("%s: ", desc);
23 p = inf->dataptr;
24 while (c = *p++) {
25 if (c == '\\') {
26 putchar('\\');
27 putchar('\\');
28 } else if (c >= ' ' && c <= '~')
29 putchar(c);
30 else
31 printf("\\x%02X", c);
32 }
33 putchar('\n');
34 }
35
36 static int
37 obj_name_heuristic(inf)
38 struct inode_info *inf;
39 {
40 u8 *p;
41 int c, n;
42
43 p = inf->dataptr;
44 while (c = *p++) {
45 if (n >= MAX_FN_COMPONENT)
46 return(0);
47 if (c < ' ' || c > '~')
48 return(0);
49 n++;
50 }
51 if (n)
52 return(1);
53 else
54 return(0);
55 }
56
57 static void
16 segment_size_callback(inf, opaque) 58 segment_size_callback(inf, opaque)
17 struct inode_info *inf; 59 struct inode_info *inf;
18 u_long opaque; 60 u_long opaque;
19 { 61 {
20 size_t *accump = (size_t *) opaque; 62 size_t *accump = (size_t *) opaque;
66 iterate_seg_file(seghead_ino, segment_ls_callback, 0L, deleted, 108 iterate_seg_file(seghead_ino, segment_ls_callback, 0L, deleted,
67 verbose2 > 1); 109 verbose2 > 1);
68 } 110 }
69 111
70 void 112 void
71 ls_tree_callback(pathname, ino, depth) 113 ls_tree_callback(pathname, ino, depth, bogonym_flag)
72 char *pathname; 114 char *pathname;
73 { 115 {
74 struct inode_info *inf = inode_info[ino]; 116 struct inode_info *inf = inode_info[ino];
75 u_long size; 117 u_long size;
76 char readonly; 118 char readonly;
82 switch (inf->type) { 124 switch (inf->type) {
83 case 0xE1: 125 case 0xE1:
84 case 0xF1: 126 case 0xF1:
85 size = get_file_size(ino, 0); 127 size = get_file_size(ino, 0);
86 printf("f%c %7lu %s\n", readonly, size, pathname); 128 printf("f%c %7lu %s\n", readonly, size, pathname);
129 if (bogonym_flag)
130 print_ext_obj_name(inf, "actual name");
87 if (verbose2) 131 if (verbose2)
88 ls_seg_file(ino, 0); 132 ls_seg_file(ino, 0);
89 return; 133 return;
90 case 0xE2: 134 case 0xE2:
91 case 0xF2: 135 case 0xF2:
92 printf("d%c %s\n", readonly, pathname); 136 printf("d%c %s\n", readonly, pathname);
137 if (bogonym_flag)
138 print_ext_obj_name(inf, "actual name");
93 return; 139 return;
94 case 0xE3: 140 case 0xE3:
95 case 0xF3: 141 case 0xF3:
96 printf("l%c %s\n", readonly, pathname); 142 printf("l%c %s\n", readonly, pathname);
143 if (bogonym_flag)
144 print_ext_obj_name(inf, "actual name");
97 return; 145 return;
98 default: 146 default:
99 fprintf(stderr, 147 fprintf(stderr,
100 "BUG: bad inode byte %02X reached ls_tree_callback()\n", 148 "BUG: bad inode byte %02X reached ls_tree_callback()\n",
101 inf->type); 149 inf->type);
285 printf("object type %02X (%s)\n", inf->type, type); 333 printf("object type %02X (%s)\n", inf->type, type);
286 if (!inf->len) { 334 if (!inf->len) {
287 printf("This inode has been reclaimed\n\n"); 335 printf("This inode has been reclaimed\n\n");
288 return; 336 return;
289 } 337 }
290 if (validate_obj_name(ino, 1)) 338 switch (inf->type) {
291 printf("object name: %s\n", inf->dataptr); 339 case 0x00:
292 else { 340 if (object_name_mincheck(ino) &&
293 printf("No valid object name in the chunk\n\n"); 341 (assume_file || obj_name_heuristic(inf)))
294 return; 342 print_ext_obj_name(inf, "object name");
295 } 343 else {
296 if (inf->type == 0xF1 || inf->type == 0xE1 || 344 no_name: printf("No valid object name in the chunk\n\n");
297 !inf->type && assume_file) { 345 return;
346 }
347 if (!assume_file)
348 break;
298 printf("total size: %lu bytes\n", 349 printf("total size: %lu bytes\n",
299 (u_long) get_file_size(ino, !inf->type)); 350 (u_long) get_file_size(ino, 1));
300 if (verbose2) 351 if (verbose2)
301 ls_seg_file(ino, !inf->type); 352 ls_seg_file(ino, 1);
353 break;
354 case 0xE1:
355 case 0xF1:
356 if (object_name_mincheck(ino))
357 print_ext_obj_name(inf, "object name");
358 else
359 goto no_name;
360 printf("total size: %lu bytes\n",
361 (u_long) get_file_size(ino, 0));
362 if (verbose2)
363 ls_seg_file(ino, 0);
364 break;
365 case 0xF2:
366 case 0xF3:
367 if (object_name_mincheck(ino))
368 print_ext_obj_name(inf, "object name");
369 else
370 goto no_name;
371 break;
302 } 372 }
303 putchar('\n'); 373 putchar('\n');
304 } 374 }
305 375
306 cmd_lsino(argc, argv) 376 cmd_lsino(argc, argv)