annotate mpffs/ls.c @ 32:0bf037ba4149

mpffs-ls: report the full chunk length of the /.journal file
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 30 Jun 2013 07:16:01 +0000
parents 3cca8070ef0f
children 9bc7f0e03fa8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the main function and other code specific to mpffs-ls
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <ctype.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <unistd.h>
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "types.h"
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "struct.h"
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern char *imgfile;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 extern struct objinfo root;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern int verbose;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 char workpath[512];
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
31
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
21 size_t
30
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 get_file_size(head)
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 struct objinfo *head;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
31
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
25 int ent;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
26 struct objinfo ch;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
27 struct chunkinfo chi;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
28 size_t accum;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
29
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
30 size_head_chunk(head, &chi);
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
31 accum = chi.len;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
32 for (ent = head->descend; ent != 0xFFFF; ent = ch.descend) {
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
33 ch.entryno = ent;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
34 get_index_entry(&ch);
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
35 if (ch.type != 0xF4) {
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
36 fprintf(stderr,
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
37 "file continuation object at index %x: type %02X != expected F4\n",
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
38 ent, ch.type);
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
39 break;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
40 }
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
41 validate_chunk(&ch);
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
42 size_extra_chunk(&ch, &chi);
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
43 accum += chi.len;
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
44 if (ch.sibling != 0xFFFF)
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
45 fprintf(stderr,
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
46 "warning: file continuation object (index %x) has a non-nil sibling pointer\n",
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
47 ent);
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
48 }
3cca8070ef0f mpffs-ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 30
diff changeset
49 return(accum);
30
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 }
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 dump_dir(firstent, path_prefix)
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 {
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 int ent;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 struct objinfo obj;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 u_long size;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 for (ent = firstent; ent != 0xFFFF; ent = obj.sibling) {
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 obj.entryno = ent;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 get_index_entry(&obj);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 if (!obj.type) /* skip deleted objects w/o further validation */
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 continue;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 validate_chunk(&obj);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 validate_obj_name(&obj);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 if (path_prefix + strlen(obj.dataptr) + 2 > sizeof workpath) {
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 fprintf(stderr,
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 "handling object at index %x, name \"%s\": path buffer overflow\n",
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 obj.entryno, (char *)obj.dataptr);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 exit(1);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 }
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 sprintf(workpath + path_prefix, "/%s", (char *)obj.dataptr);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 switch (obj.type) {
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 case 0xF2:
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 /* directory */
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 printf("d %s\n", workpath);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 dump_dir(obj.descend, strlen(workpath));
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 continue;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 case 0xF1:
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 /* regular file */
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 size = get_file_size(&obj);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 printf("- %7lu %s\n", size, workpath);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 continue;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 case 0xE1:
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 /* special .journal file */
32
0bf037ba4149 mpffs-ls: report the full chunk length of the /.journal file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 31
diff changeset
85 printf("j %7lu %s\n", (u_long) obj.len, workpath);
30
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 continue;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 default:
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 printf("%s (index entry #%x): unexpected type %02X; skipping\n",
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 workpath, obj.entryno, obj.type);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 continue;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 }
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 }
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 usage()
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 {
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 fprintf(stderr, "usage: mpffs-ls [options] ffs-image\n");
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 exit(1);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 }
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 main(argc, argv)
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 char **argv;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 {
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 extern int optind;
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 parse_cmdline_options(argc, argv);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 if (argc - optind != 1)
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 usage();
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 imgfile = argv[optind];
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 preliminaries();
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 dump_dir(root.descend, 0);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 exit(0);
9c3c5a572b57 mpffs-ls works with the length code stubbed out
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 }