FreeCalypso > hg > freecalypso-sw
comparison ffstools/tiffs-rd/ls.c @ 237:317936902be4
tiffs IVA: regular ls fully implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 26 Jan 2014 21:12:15 +0000 |
parents | 254de9560ef3 |
children | 0b13839f782c |
comparison
equal
deleted
inserted
replaced
236:254de9560ef3 | 237:317936902be4 |
---|---|
31 size_t accum; | 31 size_t accum; |
32 | 32 |
33 size_head_chunk(inode_info[seghead_ino], &chi); | 33 size_head_chunk(inode_info[seghead_ino], &chi); |
34 accum = chi.len; | 34 accum = chi.len; |
35 iterate_seg_file(seghead_ino, segment_size_callback, (u_long) &accum, | 35 iterate_seg_file(seghead_ino, segment_size_callback, (u_long) &accum, |
36 deleted); | 36 deleted, 0); |
37 return(accum); | 37 return(accum); |
38 } | 38 } |
39 | 39 |
40 static void | 40 static void |
41 segment_ls_callback(inf, opaque) | 41 segment_ls_callback(inf, opaque) |
43 u_long opaque; | 43 u_long opaque; |
44 { | 44 { |
45 struct chunkinfo chi; | 45 struct chunkinfo chi; |
46 | 46 |
47 size_extra_chunk(inf, &chi); | 47 size_extra_chunk(inf, &chi); |
48 printf("seg #%04x length=%lu\n", inf->ino, (u_long) chi.len); | 48 if (verbose2 > 1) |
49 printf("seg #%04x @%08x length=%lu\n", inf->ino, inf->offset, | |
50 (u_long) chi.len); | |
51 else | |
52 printf("seg #%04x length=%lu\n", inf->ino, (u_long) chi.len); | |
49 } | 53 } |
50 | 54 |
51 ls_seg_file(seghead_ino, deleted) | 55 ls_seg_file(seghead_ino, deleted) |
52 { | 56 { |
53 struct inode_info *inf = inode_info[seghead_ino]; | 57 struct inode_info *inf = inode_info[seghead_ino]; |
54 struct chunkinfo chi; | 58 struct chunkinfo chi; |
55 | 59 |
56 size_head_chunk(inf, &chi); | 60 size_head_chunk(inf, &chi); |
57 printf("%lu bytes in seghead\n", (u_long) chi.len); | 61 printf("%lu bytes in seghead", (u_long) chi.len); |
58 iterate_seg_file(seghead_ino, segment_ls_callback, 0L, deleted); | 62 if (verbose2 > 1) |
63 printf(", starting at offset %lx", | |
64 (u_long)(inf->byte_after_name - image)); | |
65 putchar('\n'); | |
66 iterate_seg_file(seghead_ino, segment_ls_callback, 0L, deleted, | |
67 verbose2 > 1); | |
59 } | 68 } |
60 | 69 |
61 void | 70 void |
62 ls_callback(pathname, ino, depth) | 71 ls_tree_callback(pathname, ino, depth) |
63 char *pathname; | 72 char *pathname; |
64 { | 73 { |
65 struct inode_info *inf = inode_info[ino]; | 74 struct inode_info *inf = inode_info[ino]; |
66 u_long size; | 75 u_long size; |
67 char readonly; | 76 char readonly; |
92 inf->type); | 101 inf->type); |
93 exit(1); | 102 exit(1); |
94 } | 103 } |
95 } | 104 } |
96 | 105 |
97 ls_visible_tree() | 106 ls_by_pathname(pathname) |
107 char *pathname; | |
98 { | 108 { |
99 read_ffs_image(); | 109 int ino; |
100 find_inode_block(); | 110 struct inode_info *inf; |
101 alloc_inode_table(); | 111 char *type; |
102 find_root_inode(); | 112 |
103 traverse_visible_tree(ls_callback); | 113 printf("%s\n", pathname); |
104 exit(0); | 114 ino = find_pathname(pathname); |
115 printf("inode #%x\n", ino); | |
116 inf = inode_info[ino]; | |
117 switch (inf->type) { | |
118 case 0xE1: | |
119 type = "read-only file"; | |
120 break; | |
121 case 0xF1: | |
122 type = "file"; | |
123 break; | |
124 case 0xF2: | |
125 type = "directory"; | |
126 break; | |
127 case 0xF3: | |
128 type = "symlink"; | |
129 break; | |
130 default: | |
131 type = "???"; | |
132 } | |
133 printf("object type %02X (%s)\n", inf->type, type); | |
134 if (!validate_obj_name(ino, ino == root_inode)) { | |
135 printf("No valid object name in the chunk!\n"); | |
136 exit(1); | |
137 } | |
138 printf("object name: %s\n", inf->dataptr); | |
139 if (inf->type == 0xF1 || inf->type == 0xE1) { | |
140 printf("total size: %lu bytes\n", | |
141 (u_long) get_file_size(ino, 0)); | |
142 if (verbose2) | |
143 ls_seg_file(ino, 0); | |
144 } | |
145 putchar('\n'); | |
105 } | 146 } |
106 | 147 |
107 cmd_ls(argc, argv) | 148 cmd_ls(argc, argv) |
108 char **argv; | 149 char **argv; |
109 { | 150 { |
110 char **ap; | 151 extern int optind; |
152 int c; | |
111 | 153 |
112 ap = argv + 1; | 154 read_ffs_image(); |
113 if (*ap && !strcmp(*ap, "-v")) { | 155 find_inode_block(); |
114 verbose2++; | 156 alloc_inode_table(); |
115 ap++; | 157 find_root_inode(); |
158 | |
159 optind = 0; | |
160 while ((c = getopt(argc, argv, "v")) != EOF) | |
161 switch (c) { | |
162 case 'v': | |
163 verbose2++; | |
164 continue; | |
165 default: | |
166 fprintf(stderr, "usage: ls [-v[v]] [pathname...]\n"); | |
167 exit(1); | |
168 } | |
169 if (optind >= argc) { | |
170 traverse_visible_tree(ls_tree_callback); | |
171 exit(0); | |
116 } | 172 } |
117 if (!*ap) | 173 for (; optind < argc; optind++) |
118 return ls_visible_tree(); | 174 ls_by_pathname(argv[optind]); |
119 fprintf(stderr, "ls of individual files not yet implemented\n"); | 175 exit(0); |
120 exit(1); | |
121 } | 176 } |