annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This C module implements the ls command.
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
5 #include <sys/types.h>
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "types.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "struct.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "globals.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "pathname.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
15 static void
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
16 segment_size_callback(inf, opaque)
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
17 struct inode_info *inf;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
18 u_long opaque;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
19 {
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
20 size_t *accump = (size_t *) opaque;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
21 struct chunkinfo chi;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
22
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
23 size_extra_chunk(inf, &chi);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
24 *accump += chi.len;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
25 }
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
26
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
27 size_t
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
28 get_file_size(seghead_ino, deleted)
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
29 {
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
30 struct chunkinfo chi;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
31 size_t accum;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
32
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
33 size_head_chunk(inode_info[seghead_ino], &chi);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
34 accum = chi.len;
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
35 iterate_seg_file(seghead_ino, segment_size_callback, (u_long) &accum,
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
36 deleted);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
37 return(accum);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
38 }
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
39
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 void
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 ls_callback(pathname, ino, depth)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 char *pathname;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 struct inode_info *inf = inode_info[ino];
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
45 u_long size;
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 switch (inf->type) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 case 0xE1:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 case 0xF1:
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
50 size = get_file_size(ino, 0);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
51 printf("f %7lu %s\n", size, pathname);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
52 return;
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 case 0xF2:
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
54 printf("d %s\n", pathname);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
55 return;
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 case 0xF3:
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
57 printf("l %s\n", pathname);
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
58 return;
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 default:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 "BUG: bad inode byte %02X reached ls_callback()\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 inf->type);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 exit(1);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 cmd_ls()
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 read_ffs_image();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 find_inode_block();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 alloc_inode_table();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 find_root_inode();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 traverse_visible_tree(ls_callback);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 exit(0);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 }