annotate ffstools/tiffs-rd/ls.c @ 236:254de9560ef3

tiffs ls -v implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 19:03:33 +0000
parents e17bb8818318
children 317936902be4
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
236
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
40 static void
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
41 segment_ls_callback(inf, opaque)
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
42 struct inode_info *inf;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
43 u_long opaque;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
44 {
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
45 struct chunkinfo chi;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
46
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
47 size_extra_chunk(inf, &chi);
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
48 printf("seg #%04x length=%lu\n", inf->ino, (u_long) chi.len);
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
49 }
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
50
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
51 ls_seg_file(seghead_ino, deleted)
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
52 {
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
53 struct inode_info *inf = inode_info[seghead_ino];
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
54 struct chunkinfo chi;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
55
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
56 size_head_chunk(inf, &chi);
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
57 printf("%lu bytes in seghead\n", (u_long) chi.len);
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
58 iterate_seg_file(seghead_ino, segment_ls_callback, 0L, deleted);
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
59 }
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
60
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 void
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 ls_callback(pathname, ino, depth)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 char *pathname;
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 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
66 u_long size;
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
67 char readonly;
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
69 if (inf->type & 0x10)
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
70 readonly = ' ';
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
71 else
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
72 readonly = 'r';
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 switch (inf->type) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 case 0xE1:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 case 0xF1:
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
76 size = get_file_size(ino, 0);
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
77 printf("f%c %7lu %s\n", readonly, size, pathname);
236
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
78 if (verbose2)
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
79 ls_seg_file(ino, 0);
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
80 return;
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
81 case 0xE2:
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 case 0xF2:
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
83 printf("d%c %s\n", readonly, pathname);
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
84 return;
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
85 case 0xE3:
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 case 0xF3:
235
e17bb8818318 tiffs ls: show read-only file flag
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
87 printf("l%c %s\n", readonly, pathname);
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
88 return;
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 default:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 "BUG: bad inode byte %02X reached ls_callback()\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 inf->type);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 exit(1);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96
236
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
97 ls_visible_tree()
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 read_ffs_image();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 find_inode_block();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 alloc_inode_table();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 find_root_inode();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 traverse_visible_tree(ls_callback);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 exit(0);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 }
236
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
106
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
107 cmd_ls(argc, argv)
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
108 char **argv;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
109 {
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
110 char **ap;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
111
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
112 ap = argv + 1;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
113 if (*ap && !strcmp(*ap, "-v")) {
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
114 verbose2++;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
115 ap++;
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
116 }
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
117 if (!*ap)
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
118 return ls_visible_tree();
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
119 fprintf(stderr, "ls of individual files not yet implemented\n");
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
120 exit(1);
254de9560ef3 tiffs ls -v implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 235
diff changeset
121 }