FreeCalypso > hg > freecalypso-reveng
annotate pirollback/rollback.c @ 371:c7514c8b5b41
pirelli/headset: plug insertion detection figured out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Jun 2021 01:33:48 +0000 |
parents | e516128db432 |
children |
rev | line source |
---|---|
50
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <sys/types.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <sys/file.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <endian.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <stdio.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <string.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <strings.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <unistd.h> |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "types.h" |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "struct.h" |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "pathname.h" |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 extern char *imgfile; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 extern u8 image[0x480000]; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 extern struct inode_info inode[]; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 extern int last_inode; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 extern int journal_start_ino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
51
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
19 static void |
50
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 report_inode(ino) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 struct inode_info *inf = inode + ino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 char pathname[PATHNAME_BUF_SIZE]; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 int typechar; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 switch (inf->type) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 case 0xF1: |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 typechar = 'f'; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 break; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 case 0xF2: |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 typechar = 'd'; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 break; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 case 0xF4: |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 typechar = '.'; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 break; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 default: |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 fprintf(stderr, "inode #%x: unexpected type %02X\n", |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 ino, inf->type); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (pathname_of_inode(ino, pathname) < 0) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 strcpy(pathname, "-nopath-"); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 printf("reverting #%04X %c %s\n", ino, typechar, pathname); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 |
51
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
46 static void |
50
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 unlink_inode(oldino, newino, is_sibling) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 struct inode_info *inf = inode + oldino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 struct inode_flash *fl = inf->flash; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 u16 *flashp; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 if (is_sibling) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 flashp = &fl->sibling; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 else |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 flashp = &fl->descend; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (le16toh(*flashp) != newino) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 fprintf(stderr, |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 "fail: %s pointer of inode #%x does not point to #%x as expected\n", |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 is_sibling ? "sibling" : "descend", oldino, newino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 /* unprogram it! */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 *flashp = 0xFFFF; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 |
51
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
67 static void |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
68 resurrect_descend_chain(headino, ino) |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
69 { |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
70 struct inode_info *inf; |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
71 u8 *typebyte; |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
72 |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
73 for (; ino; ino = inf->descend) { |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
74 inf = inode + ino; |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
75 if (inf->type != 0xF4) { |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
76 fprintf(stderr, |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
77 "error: #%x, descendant of #%x, is not of type F4\n", |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
78 ino, headino); |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
79 exit(1); |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
80 } |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
81 typebyte = &inf->flash->type; |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
82 if (*typebyte) { |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
83 fprintf(stderr, |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
84 "inode #%x to be resurrected: not in deleted state\n", |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
85 ino); |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
86 exit(1); |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
87 } |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
88 /* undo the zeroing */ |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
89 *typebyte = 0xF4; |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
90 } |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
91 } |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
92 |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
93 static void |
50
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 resurrect_old_ver(oldino, newino) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 struct inode_info *old = inode + oldino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 struct inode_info *new = inode + newino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 u8 *typebyte; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 if (old->type != new->type || old->parent != new->parent || |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 strcmp(old->dataptr, new->dataptr)) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 fprintf(stderr, "inode #%x replacing #%x: mismatch error\n", |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 newino, oldino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 /* the item of interest is the old in-flash type byte */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 typebyte = &old->flash->type; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 if (*typebyte) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 fprintf(stderr, |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 "inode #%x to be resurrected: not in deleted state\n", |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 oldino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 /* undo the zeroing */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 *typebyte = old->type; |
51
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
116 /* |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
117 * Is there a descendant chain (file continuation chunks) |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
118 * to resurrect as well? |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
119 */ |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
120 if (!old->descend) |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
121 return; |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
122 if (old->type != 0xF1) { |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
123 fprintf(stderr, |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
124 "resurrecting inode #%x: unexpected descendant with type != F1\n", |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
125 oldino); |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
126 exit(1); |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
127 } |
e516128db432
pirollback: resurrect file descendant chains
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
50
diff
changeset
|
128 resurrect_descend_chain(oldino, old->descend); |
50
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 roll_back_inode(ino) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 struct inode_info *inf = inode + ino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 report_inode(ino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 if (!inf->flash->type) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 printf("NOTE: object is already in deleted state\n"); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 /* first order of business: unlink it */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 if (inf->j_unlink_ptr < 0) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 unlink_inode(-inf->j_unlink_ptr, ino, 0); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 else |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 unlink_inode(inf->j_unlink_ptr, ino, 1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 /* resurrect the previous version */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 if (inf->type != 0xF4) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 if (inf->j_oldver) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 resurrect_old_ver(inf->j_oldver, ino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 else |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 printf("NOTE: no previous version to resurrect\n"); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 } else if (inf->j_oldver) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 fprintf(stderr, |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 "error: unexpected oldver on inode #%x of type F4\n", |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 ino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 /* reblank the 3 flash areas programmed with this inode */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 memset(inf->flash, 0xFF, 16); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 memset(inf->jflash, 0xFF, 16); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 memset(inf->dataptr, 0xFF, inf->len); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 write_new_img(outfilename) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 char *outfilename; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 int fd, cc; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 fd = open(outfilename, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 if (fd < 0) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 perror(outfilename); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 cc = write(fd, image, sizeof image); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 close(fd); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 if (cc != sizeof image) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
174 fprintf(stderr, "error writing to %s\n", outfilename); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 main(argc, argv) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 char **argv; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 int ino, keep_ino; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 char *strtoul_endp; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 if (argc != 4) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 usage: fprintf(stderr, |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 "usage: %s ffs-image inode-to-keep new-image\n", |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 argv[0]); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 imgfile = argv[1]; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 keep_ino = strtoul(argv[2], &strtoul_endp, 16); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 if (!argv[2][0] || *strtoul_endp) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 goto usage; |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 read_img_file(); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 read_inodes(); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
198 walk_tree(); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 check_object_names(); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 parse_journal(); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 check_object_names(); /* rerun for "undeleted" objects */ |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 if (keep_ino < journal_start_ino || keep_ino > last_inode) { |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 fprintf(stderr, "%s: bad inode number specified\n", argv[0]); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 exit(1); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 } |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 for (ino = last_inode; ino > keep_ino; ino--) |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 roll_back_inode(ino); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 write_new_img(argv[3]); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 exit(0); |
40b1ae2ab2d7
pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 } |