FreeCalypso > hg > freecalypso-sw
annotate target-utils/libtiffs/basicfind.c @ 857:2768b4339275
a flash chip init/reset function added to Application_Initialize(),
see the comments in gsm-fw/bsp/flashchipinit.S
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Fri, 01 May 2015 16:27:59 +0000 |
parents | 2900fe603f8a |
children |
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 |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 find_named_child(start, seekname) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 char *seekname; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 int ino; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 struct inode *irec; |
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 for (ino = start; ino != 0xFFFF; ino = irec->sibling) { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 irec = mpffs_active_index + ino; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 if (!irec->type) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 continue; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 if (!strcmp(inode_to_dataptr(irec), seekname)) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 return(ino); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 } |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 return(0); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 } |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 mpffs_pathname_to_inode(pathname) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 char *pathname; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 int ino, stat; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 struct inode *irec; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 char *cur, *next; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 stat = mpffs_init(); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 if (stat < 0) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 return(stat); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 cur = pathname; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 if (*cur == '/') |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 cur++; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 for (ino = mpffs_root_ino; cur; cur = next) { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 if (!*cur) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 break; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 next = index(cur, '/'); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 if (next == cur) { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 printf("malformed pathname: multiple adjacent slashes\n"); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 return(-1); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 if (next) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 *next++ = '\0'; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 irec = mpffs_active_index + ino; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 if (irec->type != OBJTYPE_DIR) { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 printf("Error: non-terminal non-directory\n"); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 if (next) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 next[-1] = '/'; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 return(-1); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 } |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 ino = find_named_child(irec->descend, cur); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (next) |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 next[-1] = '/'; |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 if (!ino) { |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 printf("Error: pathname component not found\n"); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 return(-1); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 } |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 } |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 return(ino); |
7029fe8ae0bc
pirexplore: FFS find command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 } |