comparison ffstools/tiffs-rd/tree.c @ 237:317936902be4

tiffs IVA: regular ls fully implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 21:12:15 +0000
parents 024042383a26
children 0b13839f782c
comparison
equal deleted inserted replaced
236:254de9560ef3 237:317936902be4
65 { 65 {
66 char pathbuf[PATHNAME_BUF_SIZE]; 66 char pathbuf[PATHNAME_BUF_SIZE];
67 67
68 visible_walk_dir(pathbuf, pathbuf, root_inode, 0, callback); 68 visible_walk_dir(pathbuf, pathbuf, root_inode, 0, callback);
69 } 69 }
70
71 /*
72 * The following function iterates through the descendants of a directory
73 * object looking for a specific directory-member filename.
74 *
75 * Arguments:
76 * - inode # of the parent directory
77 * - inode # of the first descendant (descendant pointer from the dir object)
78 * - filename to search for
79 *
80 * Returns: inode # of the sought descendant object if found, 0 otherwise.
81 */
82 find_dir_member(dirino, first_descend, srchname)
83 char *srchname;
84 {
85 int ino;
86 struct inode_info *inf;
87
88 for (ino = first_descend; ino; ino = inf->sibling) {
89 if (!validate_inode(ino)) {
90 fprintf(stderr,
91 "error: pathname search hit invalid inode #%x\n",
92 ino);
93 exit(1);
94 }
95 inf = inode_info[ino];
96 switch (inf->type) {
97 case 0x00:
98 /* walking the *visible* tree: skip deleted objects */
99 continue;
100 case 0xF4:
101 fprintf(stderr,
102 "warning: directory #%x has child #%x of type segment (F4), skipping\n",
103 dirino, ino);
104 continue;
105 }
106 if (!validate_obj_name(ino, 0)) {
107 fprintf(stderr,
108 "visible tree walk error: no valid name for inode #%x\n",
109 ino);
110 continue;
111 }
112 if (!strcmp(inf->dataptr, srchname))
113 return(ino);
114 }
115 return(0);
116 }
117
118 /*
119 * The following function searches for a pathname from the root down.
120 * Returns the inode # if found, otherwise exits with an error message
121 * indicating which step failed.
122 *
123 * Warning: the pathname in the argument buffer will be destroyed:
124 * 0s put in place of the slashes.
125 */
126 find_pathname(pathname)
127 char *pathname;
128 {
129 char *cur, *next;
130 int ino;
131 struct inode_info *inf;
132
133 cur = pathname;
134 if (*cur == '/')
135 cur++;
136 else {
137 fprintf(stderr,
138 "bad pathname \"%s\": TIFFS pathnames must be absolute\n",
139 pathname);
140 exit(1);
141 }
142 for (ino = root_inode; cur; cur = next) {
143 if (!*cur)
144 break;
145 next = index(cur, '/');
146 if (next == cur) {
147 fprintf(stderr,
148 "malformed pathname: multiple adjacent slashes\n");
149 exit(1);
150 }
151 if (next)
152 *next++ = '\0';
153 inf = inode_info[ino];
154 if (inf->type != 0xF2) {
155 fprintf(stderr,
156 "pathname search error: encountered a non-directory\n");
157 exit(1);
158 }
159 ino = find_dir_member(ino, inf->descend, cur);
160 if (!ino) {
161 fprintf(stderr,
162 "pathname search error: component name not found\n");
163 exit(1);
164 }
165 }
166 return(ino);
167 }