annotate target-utils/libmpffs/basicfind.c @ 101:7029fe8ae0bc

pirexplore: FFS find command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 02 Sep 2013 00:33:54 +0000
parents
children 7f75ffdd674f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <sys/types.h>
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 #include "types.h"
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 #include "struct.h"
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 #include "globals.h"
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include "macros.h"
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 extern char *index();
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 static u8 *
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 find_endofchunk(ino)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 struct inode *irec = mpffs_active_index + ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 u8 *p;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 int i;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 p = inode_to_dataptr(irec) + irec->len;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 for (i = 0; i < 16; i++) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 p--;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 if (!*p)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 return(p);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 if (*p != 0xFF)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 break;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 printf("Error: inode #%x has no valid termination\n", ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 return(p); /* XXX */
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 static
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 find_named_child(start, seekname)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 char *seekname;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 int ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 struct inode *irec;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 for (ino = start; ino != 0xFFFF; ino = irec->sibling) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 irec = mpffs_active_index + ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 if (!irec->type)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 continue;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 if (!strcmp(inode_to_dataptr(irec), seekname))
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 return(ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 return(0);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 mpffs_pathname_to_inode(pathname)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 char *pathname;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 int ino, stat;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 struct inode *irec;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 char *cur, *next;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 stat = mpffs_init();
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 if (stat < 0)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 return(stat);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 cur = pathname;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 if (*cur == '/')
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 cur++;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 for (ino = mpffs_root_ino; cur; cur = next) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (!*cur)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 break;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 next = index(cur, '/');
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 if (next == cur) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 printf("malformed pathname: multiple adjacent slashes\n");
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (next)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 *next++ = '\0';
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 irec = mpffs_active_index + ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (irec->type != OBJTYPE_DIR) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 printf("Error: non-terminal non-directory\n");
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 if (next)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 next[-1] = '/';
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 ino = find_named_child(irec->descend, cur);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 if (next)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 next[-1] = '/';
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 if (!ino) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 printf("Error: pathname component not found\n");
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 return(ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 mpffs_find_file(pathname, startret, sizeret, continue_ret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 char *pathname;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 u8 **startret;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 size_t *sizeret;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 int *continue_ret;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 int ino, cont;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 struct inode *irec;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 u8 *start, *end;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 size_t size;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 ino = mpffs_pathname_to_inode(pathname);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 if (ino <= 0)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 irec = mpffs_active_index + ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 if (irec->type != OBJTYPE_FILE) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 printf("Error: %s is not a regular file\n", pathname);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 start = inode_to_dataptr(irec);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 start += strlen(start) + 1;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 end = find_endofchunk(ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 size = end - start;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 if (size < 0)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 size = 0;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 cont = irec->descend;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 if (cont == 0xFFFF)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 cont = 0;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 if (startret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 *startret = start;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 if (sizeret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 *sizeret = size;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 if (continue_ret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 *continue_ret = cont;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 return(0);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 mpffs_get_segment(ino, startret, sizeret, continue_ret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 int ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 u8 **startret;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 size_t *sizeret;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 int *continue_ret;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 int cont;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 struct inode *irec;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 u8 *start, *end;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 size_t size;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 for (;;) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 irec = mpffs_active_index + ino;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 if (irec->type)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 break;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 if (irec->sibling == 0xFFFF) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 printf("Error: segment inode #%d: deleted and no sibling\n",
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 ino = irec->sibling;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 if (irec->type != OBJTYPE_SEGMENT) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 printf("Error: inode #%x is not a segment\n", ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 start = inode_to_dataptr(irec);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 end = find_endofchunk(ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 size = end - start;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 if (size <= 0) {
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 printf("Error: segment inode #%x: bad length\n", ino);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 return(-1);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 }
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 cont = irec->descend;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 if (cont == 0xFFFF)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 cont = 0;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 if (startret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 *startret = start;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 if (sizeret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 *sizeret = size;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 if (continue_ret)
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 *continue_ret = cont;
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 return(0);
7029fe8ae0bc pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 }