annotate target-utils/libtiffs/findfile.c @ 1034:405b5469abc4 default tip

top README: repository change notice
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 Jun 2016 19:06:34 +0000
parents 2900fe603f8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
103
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <sys/types.h>
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 #include "types.h"
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 #include "struct.h"
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 #include "globals.h"
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include "macros.h"
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 static u8 *
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 find_endofchunk(ino)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 struct inode *irec = mpffs_active_index + ino;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 u8 *p;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 int i;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 p = inode_to_dataptr(irec) + irec->len;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 for (i = 0; i < 16; i++) {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 p--;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 if (!*p)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 return(p);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 if (*p != 0xFF)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 break;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 printf("Error: inode #%x has no valid termination\n", ino);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 return(p); /* XXX */
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 mpffs_find_file(pathname, startret, sizeret, continue_ret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 char *pathname;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 u8 **startret;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 size_t *sizeret;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 int *continue_ret;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 int ino, cont;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 struct inode *irec;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 u8 *start, *end;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 int size;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 ino = mpffs_pathname_to_inode(pathname);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 if (ino <= 0)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 return(-1);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 irec = mpffs_active_index + ino;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 if (irec->type != OBJTYPE_FILE) {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 printf("Error: %s is not a regular file\n", pathname);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 return(-1);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 start = inode_to_dataptr(irec);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 start += strlen(start) + 1;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 end = find_endofchunk(ino);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 size = end - start;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (size < 0)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 size = 0;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 cont = irec->descend;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 if (cont == 0xFFFF)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 cont = 0;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 if (startret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 *startret = start;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 if (sizeret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 *sizeret = size;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 if (continue_ret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 *continue_ret = cont;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 return(0);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 mpffs_get_segment(ino, startret, sizeret, continue_ret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 int ino;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 u8 **startret;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 size_t *sizeret;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 int *continue_ret;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 int cont;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 struct inode *irec;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 u8 *start, *end;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 int size;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 for (;;) {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 irec = mpffs_active_index + ino;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 if (irec->type)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 break;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 if (irec->sibling == 0xFFFF) {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 printf("Error: segment inode #%d: deleted and no sibling\n",
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 ino);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 return(-1);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 ino = irec->sibling;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 if (irec->type != OBJTYPE_SEGMENT) {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 printf("Error: inode #%x is not a segment\n", ino);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 return(-1);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 start = inode_to_dataptr(irec);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 end = find_endofchunk(ino);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 size = end - start;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 if (size <= 0) {
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 printf("Error: segment inode #%x: bad length\n", ino);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 return(-1);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 }
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 cont = irec->descend;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 if (cont == 0xFFFF)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 cont = 0;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 if (startret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 *startret = start;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 if (sizeret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 *sizeret = size;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 if (continue_ret)
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 *continue_ret = cont;
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 return(0);
ac310ee73788 target-utils/libmpffs: minor refactoring, read into RAM implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 }