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