comparison target-utils/libtiffs/basicfind.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 87cb03b35f77
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 #include <sys/types.h>
2 #include "types.h"
3 #include "struct.h"
4 #include "globals.h"
5 #include "macros.h"
6
7 extern char *index();
8
9 static
10 find_named_child(start, seekname)
11 char *seekname;
12 {
13 int ino;
14 struct inode *irec;
15
16 for (ino = start; ino != 0xFFFF; ino = irec->sibling) {
17 irec = mpffs_active_index + ino;
18 if (!irec->type)
19 continue;
20 if (!strcmp(inode_to_dataptr(irec), seekname))
21 return(ino);
22 }
23 return(0);
24 }
25
26 mpffs_pathname_to_inode(pathname)
27 char *pathname;
28 {
29 int ino, stat;
30 struct inode *irec;
31 char *cur, *next;
32
33 stat = mpffs_init();
34 if (stat < 0)
35 return(stat);
36 cur = pathname;
37 if (*cur == '/')
38 cur++;
39 for (ino = mpffs_root_ino; cur; cur = next) {
40 if (!*cur)
41 break;
42 next = index(cur, '/');
43 if (next == cur) {
44 printf("malformed pathname: multiple adjacent slashes\n");
45 return(-1);
46 }
47 if (next)
48 *next++ = '\0';
49 irec = mpffs_active_index + ino;
50 if (irec->type != OBJTYPE_DIR) {
51 printf("Error: non-terminal non-directory\n");
52 if (next)
53 next[-1] = '/';
54 return(-1);
55 }
56 ino = find_named_child(irec->descend, cur);
57 if (next)
58 next[-1] = '/';
59 if (!ino) {
60 printf("Error: pathname component not found\n");
61 return(-1);
62 }
63 }
64 return(ino);
65 }