comparison ffstools/tiffs-rd/ls.c @ 234:024042383a26

tiffs IVA: ls reports file sizes
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 11:47:13 +0000
parents ae9ff2d1e3da
children e17bb8818318
comparison
equal deleted inserted replaced
233:ae9ff2d1e3da 234:024042383a26
1 /* 1 /*
2 * This C module implements the ls command. 2 * This C module implements the ls command.
3 */ 3 */
4 4
5 #include <sys/types.h>
5 #include <stdio.h> 6 #include <stdio.h>
6 #include <stdlib.h> 7 #include <stdlib.h>
7 #include <string.h> 8 #include <string.h>
8 #include <strings.h> 9 #include <strings.h>
9 #include "types.h" 10 #include "types.h"
10 #include "struct.h" 11 #include "struct.h"
11 #include "globals.h" 12 #include "globals.h"
12 #include "pathname.h" 13 #include "pathname.h"
13 14
15 static void
16 segment_size_callback(inf, opaque)
17 struct inode_info *inf;
18 u_long opaque;
19 {
20 size_t *accump = (size_t *) opaque;
21 struct chunkinfo chi;
22
23 size_extra_chunk(inf, &chi);
24 *accump += chi.len;
25 }
26
27 size_t
28 get_file_size(seghead_ino, deleted)
29 {
30 struct chunkinfo chi;
31 size_t accum;
32
33 size_head_chunk(inode_info[seghead_ino], &chi);
34 accum = chi.len;
35 iterate_seg_file(seghead_ino, segment_size_callback, (u_long) &accum,
36 deleted);
37 return(accum);
38 }
39
14 void 40 void
15 ls_callback(pathname, ino, depth) 41 ls_callback(pathname, ino, depth)
16 char *pathname; 42 char *pathname;
17 { 43 {
18 struct inode_info *inf = inode_info[ino]; 44 struct inode_info *inf = inode_info[ino];
19 char type; 45 u_long size;
20 46
21 switch (inf->type) { 47 switch (inf->type) {
22 case 0xE1: 48 case 0xE1:
23 case 0xF1: 49 case 0xF1:
24 type = 'f'; 50 size = get_file_size(ino, 0);
25 break; 51 printf("f %7lu %s\n", size, pathname);
52 return;
26 case 0xF2: 53 case 0xF2:
27 type = 'd'; 54 printf("d %s\n", pathname);
28 break; 55 return;
29 case 0xF3: 56 case 0xF3:
30 type = 'l'; 57 printf("l %s\n", pathname);
31 break; 58 return;
32 default: 59 default:
33 fprintf(stderr, 60 fprintf(stderr,
34 "BUG: bad inode byte %02X reached ls_callback()\n", 61 "BUG: bad inode byte %02X reached ls_callback()\n",
35 inf->type); 62 inf->type);
36 exit(1); 63 exit(1);
37 } 64 }
38 printf("%c %s\n", type, pathname);
39 } 65 }
40 66
41 cmd_ls() 67 cmd_ls()
42 { 68 {
43 read_ffs_image(); 69 read_ffs_image();