annotate ffstools/tiffs-rd/tree.c @ 275:cedf09b6b5ac

started laying the foundation for fc-fsio host utility
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Feb 2014 20:27:15 +0000
parents 190121a34b3b
children
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
234
024042383a26 tiffs IVA: ls reports file sizes
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 233
diff changeset
5 #include <sys/types.h>
233
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "types.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "struct.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "globals.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "pathname.h"
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 static void
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 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
17 char *pathbuf_start, *pathbuf_ptr;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 void (*callback)();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 int ndepth = depth + 1;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 int child;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 struct inode_info *inf;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 if (depth > MAX_DIR_NEST) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 "error: max dir nesting exceeded at inode #%x\n",
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 dirino);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 return;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 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
31 if (!validate_inode(child)) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 "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
34 child);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 return;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 inf = inode_info[child];
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 switch (inf->type) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 case 0x00:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 /* walking the *visible* tree: skip deleted objects */
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 continue;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 case 0xF4:
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 "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
45 dirino, child);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 continue;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (!validate_obj_name(child, 0)) {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 fprintf(stderr,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 "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
51 child);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 continue;
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 }
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 sprintf(pathbuf_ptr, "/%s", inf->dataptr);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 callback(pathbuf_start, child, ndepth);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 if (inf->type == 0xF2)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 visible_walk_dir(pathbuf_start,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 index(pathbuf_ptr, '\0'), child,
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 ndepth, callback);
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
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 traverse_visible_tree(callback)
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 void (*callback)();
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 {
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 char pathbuf[PATHNAME_BUF_SIZE];
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 visible_walk_dir(pathbuf, pathbuf, root_inode, 0, callback);
ae9ff2d1e3da tiffs IVA: basic ls integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 }
237
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
70
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
71 /*
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
72 * The following function iterates through the descendants of a directory
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
73 * object looking for a specific directory-member filename.
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
74 *
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
75 * Arguments:
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
76 * - inode # of the parent directory
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
77 * - inode # of the first descendant (descendant pointer from the dir object)
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
78 * - filename to search for
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
79 *
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
80 * Returns: inode # of the sought descendant object if found, 0 otherwise.
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
81 */
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
82 find_dir_member(dirino, first_descend, srchname)
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
83 char *srchname;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
84 {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
85 int ino;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
86 struct inode_info *inf;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
87
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
88 for (ino = first_descend; ino; ino = inf->sibling) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
89 if (!validate_inode(ino)) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
90 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
91 "error: pathname search hit invalid inode #%x\n",
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
92 ino);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
93 exit(1);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
94 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
95 inf = inode_info[ino];
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
96 switch (inf->type) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
97 case 0x00:
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
98 /* walking the *visible* tree: skip deleted objects */
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
99 continue;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
100 case 0xF4:
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
101 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
102 "warning: directory #%x has child #%x of type segment (F4), skipping\n",
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
103 dirino, ino);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
104 continue;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
105 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
106 if (!validate_obj_name(ino, 0)) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
107 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
108 "visible tree walk error: no valid name for inode #%x\n",
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
109 ino);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
110 continue;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
111 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
112 if (!strcmp(inf->dataptr, srchname))
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
113 return(ino);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
114 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
115 return(0);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
116 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
117
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
118 /*
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
119 * The following function searches for a pathname from the root down.
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
120 * Returns the inode # if found, otherwise exits with an error message
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
121 * indicating which step failed.
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
122 *
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
123 * Warning: the pathname in the argument buffer will be destroyed:
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
124 * 0s put in place of the slashes.
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
125 */
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
126 find_pathname(pathname)
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
127 char *pathname;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
128 {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
129 char *cur, *next;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
130 int ino;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
131 struct inode_info *inf;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
132
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
133 cur = pathname;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
134 if (*cur == '/')
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
135 cur++;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
136 else {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
137 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
138 "bad pathname \"%s\": TIFFS pathnames must be absolute\n",
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
139 pathname);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
140 exit(1);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
141 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
142 for (ino = root_inode; cur; cur = next) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
143 if (!*cur)
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
144 break;
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
145 next = index(cur, '/');
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
146 if (next == cur) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
147 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
148 "malformed pathname: multiple adjacent slashes\n");
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
149 exit(1);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
150 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
151 if (next)
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
152 *next++ = '\0';
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
153 inf = inode_info[ino];
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
154 if (inf->type != 0xF2) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
155 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
156 "pathname search error: encountered a non-directory\n");
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
157 exit(1);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
158 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
159 ino = find_dir_member(ino, inf->descend, cur);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
160 if (!ino) {
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
161 fprintf(stderr,
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
162 "pathname search error: component name not found\n");
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
163 exit(1);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
164 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
165 }
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
166 return(ino);
317936902be4 tiffs IVA: regular ls fully implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 234
diff changeset
167 }
238
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
168
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
169 /*
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
170 * treewalk_all() walks the entire inode tree from the root down, without
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
171 * regard to object types, including deleted objects and even reclaimed ones.
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
172 * The output is the filling of the parent and nparents fields in the inode
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
173 * info array.
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
174 */
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
175
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
176 static void
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
177 treewalk_all_node(parent)
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
178 {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
179 int child;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
180 struct inode_info *inf;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
181
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
182 for (child = inode_info[parent]->descend; child; child = inf->sibling) {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
183 if (!validate_inode(child)) {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
184 fprintf(stderr,
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
185 "error: walk of complete tree hit invalid inode #%x\n",
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
186 child);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
187 return;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
188 }
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
189 inf = inode_info[child];
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
190 inf->parent = parent;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
191 inf->nparents++;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
192 if (inf->nparents >= inode_limit) {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
193 fprintf(stderr,
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
194 "error: detected loop in inode tree at #%x, child of #%x\n",
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
195 child, parent);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
196 return;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
197 }
247
190121a34b3b TIFFS IVA: treewalk_all(): smarter handling of multiple parents
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 238
diff changeset
198 if (inf->nparents == 1)
190121a34b3b TIFFS IVA: treewalk_all(): smarter handling of multiple parents
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 238
diff changeset
199 treewalk_all_node(child);
238
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
200 }
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
201 }
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
202
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
203 treewalk_all()
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
204 {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
205 treewalk_all_node(root_inode);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
206 }
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
207
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
208 pathname_of_inode(ino, pnbuf)
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
209 char *pnbuf;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
210 {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
211 int level;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
212 char *revpath[MAX_DIR_NEST+1];
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
213 struct inode_info *inf;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
214 char *op;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
215
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
216 for (level = 0; ino != root_inode; ino = inf->parent) {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
217 if (!validate_obj_name(ino, 0))
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
218 return(-1);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
219 inf = inode_info[ino];
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
220 if (!inf->parent)
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
221 return(-1);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
222 if (level > MAX_DIR_NEST)
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
223 return(-1);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
224 revpath[level++] = (char *) inf->dataptr;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
225 }
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
226 op = pnbuf;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
227 if (!level)
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
228 *op++ = '/';
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
229 while (level) {
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
230 level--;
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
231 *op++ = '/';
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
232 strcpy(op, revpath[level]);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
233 op = index(op, '\0');
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
234 }
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
235 *op = '\0';
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
236 return(0);
0b13839f782c tiffs IVA: lsino (non-specific) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 237
diff changeset
237 }