annotate pirollback/rollback.c @ 50:40b1ae2ab2d7

pirollback: actual rollback utility implemented, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 24 Jul 2013 19:50:24 +0000
parents
children e516128db432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 report_inode(ino)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 struct inode_info *inf = inode + ino;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 char pathname[PATHNAME_BUF_SIZE];
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 int typechar;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 switch (inf->type) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 case 0xF1:
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 typechar = 'f';
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 break;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 case 0xF2:
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 typechar = 'd';
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 break;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 case 0xF4:
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 typechar = '.';
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 break;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 default:
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 fprintf(stderr, "inode #%x: unexpected type %02X\n",
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 ino, inf->type);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 if (pathname_of_inode(ino, pathname) < 0)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 strcpy(pathname, "-nopath-");
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 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
43 }
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 unlink_inode(oldino, newino, is_sibling)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 struct inode_info *inf = inode + oldino;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 struct inode_flash *fl = inf->flash;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 u16 *flashp;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 if (is_sibling)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 flashp = &fl->sibling;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 else
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 flashp = &fl->descend;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (le16toh(*flashp) != newino) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 fprintf(stderr,
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 "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
58 is_sibling ? "sibling" : "descend", oldino, newino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 /* unprogram it! */
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 *flashp = 0xFFFF;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 resurrect_old_ver(oldino, newino)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 struct inode_info *old = inode + oldino;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 struct inode_info *new = inode + newino;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 u8 *typebyte;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 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
72 strcmp(old->dataptr, new->dataptr)) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 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
74 newino, oldino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 /* 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
78 typebyte = &old->flash->type;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 if (*typebyte) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 fprintf(stderr,
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 "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
82 oldino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 /* undo the zeroing */
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 *typebyte = old->type;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 roll_back_inode(ino)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 struct inode_info *inf = inode + ino;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 report_inode(ino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 if (!inf->flash->type)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 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
96 /* first order of business: unlink it */
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 if (inf->j_unlink_ptr < 0)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 unlink_inode(-inf->j_unlink_ptr, ino, 0);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 else
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 unlink_inode(inf->j_unlink_ptr, ino, 1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 /* resurrect the previous version */
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 if (inf->type != 0xF4) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 if (inf->j_oldver)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 resurrect_old_ver(inf->j_oldver, ino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 else
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 printf("NOTE: no previous version to resurrect\n");
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 } else if (inf->j_oldver) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 fprintf(stderr,
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 "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
110 ino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 /* 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
114 memset(inf->flash, 0xFF, 16);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 memset(inf->jflash, 0xFF, 16);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 memset(inf->dataptr, 0xFF, inf->len);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 write_new_img(outfilename)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 char *outfilename;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 int fd, cc;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 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
125 if (fd < 0) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 perror(outfilename);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 cc = write(fd, image, sizeof image);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 close(fd);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 if (cc != sizeof image) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 fprintf(stderr, "error writing to %s\n", outfilename);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 exit(1);
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 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 main(argc, argv)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 char **argv;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 int ino, keep_ino;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 char *strtoul_endp;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 if (argc != 4) {
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 usage: fprintf(stderr,
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 "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
146 argv[0]);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 exit(1);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 }
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 imgfile = argv[1];
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 keep_ino = strtoul(argv[2], &strtoul_endp, 16);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 if (!argv[2][0] || *strtoul_endp)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 goto usage;
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 read_img_file();
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 read_inodes();
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 walk_tree();
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 check_object_names();
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 parse_journal();
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 check_object_names(); /* rerun for "undeleted" objects */
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 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
161 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
162 exit(1);
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 for (ino = last_inode; ino > keep_ino; ino--)
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 roll_back_inode(ino);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 write_new_img(argv[3]);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 exit(0);
40b1ae2ab2d7 pirollback: actual rollback utility implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 }