1 /* VTreeFS - path.c - by Alen Stojanov and David van Moolenbroek */ 2 3 #include "inc.h" 4 5 /*===========================================================================* 6 * fs_lookup * 7 *===========================================================================*/ 8 int fs_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node_details, 9 int *is_mountpt) 10 { 11 /* Resolve a path string to an inode. 12 */ 13 struct inode *node, *child; 14 int r; 15 16 if ((node = find_inode(dir_nr)) == NULL) 17 return EINVAL; 18 19 if (!S_ISDIR(node->i_stat.mode)) 20 return ENOTDIR; 21 22 if (strlen(name) > PNAME_MAX) 23 return ENAMETOOLONG; 24 25 if (!strcmp(name, ".")) { 26 /* Stay in the given directory. */ 27 child = node; 28 } else if (!strcmp(name, "..")) { 29 /* Progress into the parent directory. */ 30 if ((child = get_parent_inode(node)) == NULL) 31 return ENOENT; /* deleted? should not be possible */ 32 } else { 33 /* Progress into a directory entry. Call the lookup hook, if 34 * present, before doing the actual lookup. 35 */ 36 if (!is_inode_deleted(node) && 37 vtreefs_hooks->lookup_hook != NULL) { 38 r = vtreefs_hooks->lookup_hook(node, name, 39 get_inode_cbdata(node)); 40 if (r != OK) return r; 41 } 42 43 if ((child = get_inode_by_name(node, name)) == NULL) 44 return ENOENT; 45 } 46 47 /* On success, open the resulting file and return its details. */ 48 ref_inode(child); 49 50 node_details->fn_ino_nr = get_inode_number(child); 51 node_details->fn_mode = child->i_stat.mode; 52 node_details->fn_size = child->i_stat.size; 53 node_details->fn_uid = child->i_stat.uid; 54 node_details->fn_gid = child->i_stat.gid; 55 node_details->fn_dev = child->i_stat.dev; 56 57 *is_mountpt = FALSE; 58 59 return OK; 60 } 61