// Add a MountInfo structure to a MountTree in the place pointed // to by 'path'. // returns the MountTree for the location at the end of the path uio_MountTree * uio_mountTreeAddMountInfo(uio_Repository *repository, uio_MountTree *mountTree, uio_MountInfo *mountInfo, const char *path, uio_MountLocation location, const uio_MountInfo *relative) { const char *start, *end; getFirstPath0Component(path, &start, &end); return uio_mountTreeAddMountInfoRecTree(repository, mountTree, mountInfo, start, end, NULL, location, relative); }
// resTree may point to top // pPath may point to path void uio_findMountTree(uio_MountTree *top, const char *path, uio_MountTree **resTree, const char **pPath) { const char *start, *end, *pathFromTree; uio_MountTree *tree, *sub; uio_PathComp *comp; getFirstPath0Component(path, &start, &end); tree = top; while(1) { if (*start == '\0') { *resTree = tree; *pPath = start; return; } pathFromTree = start; sub = tree->subTrees; while(1) { if (sub == NULL) { // No matching sub Dirs found. So we report back the current // dir. *resTree = tree; *pPath = pathFromTree; return; } comp = sub->comps; if (strncmp(comp->name, start, end - start) == 0 && comp->name[end - start] == '\0') break; sub = sub->next; } // Found a Sub dir which matches at least partially. while (1) { getNextPath0Component(&start, &end); comp = comp->next; if (comp == NULL) break; if (*start == '\0' || strncmp(comp->name, start, end - start) != 0 || comp->name[end - start] != '\0') { // either the path ends here, or the path in the tree does. // either way, the last Tree is the one we want. *resTree = tree; *pPath = pathFromTree; return; } } // all components matched until the next MountTree tree = sub; } }
// make a list of uio_PathComps from a path string uio_PathComp * uio_makePathComps(const char *path, uio_PathComp *upComp) { const char *start, *end; char *str; uio_PathComp *result; uio_PathComp **compPtr; // Where to put the next PathComp compPtr = &result; getFirstPath0Component(path, &start, &end); while (*start != '\0') { str = uio_malloc(end - start + 1); memcpy(str, start, end - start); str[end - start] = '\0'; *compPtr = uio_PathComp_new(str, end - start, upComp); upComp = *compPtr; compPtr = &(*compPtr)->next; getNextPath0Component(&start, &end); } *compPtr = NULL; return result; }