FreeCalypso > hg > freecalypso-sw
diff 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 |
line wrap: on
line diff
--- a/ffstools/tiffs-rd/tree.c Sun Jan 26 19:03:33 2014 +0000 +++ b/ffstools/tiffs-rd/tree.c Sun Jan 26 21:12:15 2014 +0000 @@ -67,3 +67,101 @@ visible_walk_dir(pathbuf, pathbuf, root_inode, 0, callback); } + +/* + * The following function iterates through the descendants of a directory + * object looking for a specific directory-member filename. + * + * Arguments: + * - inode # of the parent directory + * - inode # of the first descendant (descendant pointer from the dir object) + * - filename to search for + * + * Returns: inode # of the sought descendant object if found, 0 otherwise. + */ +find_dir_member(dirino, first_descend, srchname) + char *srchname; +{ + int ino; + struct inode_info *inf; + + for (ino = first_descend; ino; ino = inf->sibling) { + if (!validate_inode(ino)) { + fprintf(stderr, + "error: pathname search hit invalid inode #%x\n", + ino); + exit(1); + } + inf = inode_info[ino]; + switch (inf->type) { + case 0x00: + /* walking the *visible* tree: skip deleted objects */ + continue; + case 0xF4: + fprintf(stderr, + "warning: directory #%x has child #%x of type segment (F4), skipping\n", + dirino, ino); + continue; + } + if (!validate_obj_name(ino, 0)) { + fprintf(stderr, + "visible tree walk error: no valid name for inode #%x\n", + ino); + continue; + } + if (!strcmp(inf->dataptr, srchname)) + return(ino); + } + return(0); +} + +/* + * The following function searches for a pathname from the root down. + * Returns the inode # if found, otherwise exits with an error message + * indicating which step failed. + * + * Warning: the pathname in the argument buffer will be destroyed: + * 0s put in place of the slashes. + */ +find_pathname(pathname) + char *pathname; +{ + char *cur, *next; + int ino; + struct inode_info *inf; + + cur = pathname; + if (*cur == '/') + cur++; + else { + fprintf(stderr, + "bad pathname \"%s\": TIFFS pathnames must be absolute\n", + pathname); + exit(1); + } + for (ino = root_inode; cur; cur = next) { + if (!*cur) + break; + next = index(cur, '/'); + if (next == cur) { + fprintf(stderr, + "malformed pathname: multiple adjacent slashes\n"); + exit(1); + } + if (next) + *next++ = '\0'; + inf = inode_info[ino]; + if (inf->type != 0xF2) { + fprintf(stderr, + "pathname search error: encountered a non-directory\n"); + exit(1); + } + ino = find_dir_member(ino, inf->descend, cur); + if (!ino) { + fprintf(stderr, + "pathname search error: component name not found\n"); + exit(1); + } + } + return(ino); +}