annotate ffstools/tiffs-rd/tree.c @ 233:ae9ff2d1e3da

tiffs IVA: basic ls integrated
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 10:54:42 +0000
parents
children 024042383a26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This C module implements operations on the tree level.
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <stdio.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdlib.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <string.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <strings.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include "types.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "struct.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "globals.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "pathname.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 static void
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 visible_walk_dir(pathbuf_start, pathbuf_ptr, dirino, depth, callback)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *pathbuf_start, *pathbuf_ptr;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 void (*callback)();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 int ndepth = depth + 1;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 int child;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 struct inode_info *inf;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 if (depth > MAX_DIR_NEST) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 "error: max dir nesting exceeded at inode #%x\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 dirino);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 return;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 for (child = inode_info[dirino]->descend; child; child = inf->sibling) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (!validate_inode(child)) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 "error: walk of visible tree hit invalid inode #%x\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 child);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 return;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 inf = inode_info[child];
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 switch (inf->type) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 case 0x00:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 /* walking the *visible* tree: skip deleted objects */
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 continue;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 case 0xF4:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 "warning: directory #%x has child #%x of type segment (F4), skipping\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 dirino, child);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 continue;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 if (!validate_obj_name(child, 0)) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 "visible tree walk error: no valid name for inode #%x\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 child);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 continue;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 sprintf(pathbuf_ptr, "/%s", inf->dataptr);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 callback(pathbuf_start, child, ndepth);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (inf->type == 0xF2)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 visible_walk_dir(pathbuf_start,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 index(pathbuf_ptr, '\0'), child,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 ndepth, callback);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 traverse_visible_tree(callback)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 void (*callback)();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 char pathbuf[PATHNAME_BUF_SIZE];
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 visible_walk_dir(pathbuf, pathbuf, root_inode, 0, callback);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 }