1 /* This file provides path-to-inode lookup functionality.
3 * The entry points into this file are:
4 * do_lookup perform the LOOKUP file system call
7 * April 2009 (D.C. van Moolenbroek)
12 /*===========================================================================*
14 *===========================================================================*/
16 char path
[PATH_MAX
], /* path to take the last part from */
17 struct inode
*ino
, /* inode of the current directory */
18 struct inode
**res_ino
, /* place to store resulting inode */
19 struct sffs_attr
*attr
/* place to store inode attributes */
22 /* Given an inode, progress into the parent directory.
29 parent
= ino
->i_parent
;
30 assert(parent
!= NULL
);
32 if ((r
= verify_path(path
, parent
, attr
, NULL
)) != OK
)
42 /*===========================================================================*
44 *===========================================================================*/
46 char path
[PATH_MAX
], /* path to add the name to */
47 struct inode
*parent
, /* inode of the current directory */
48 char *name
, /* name of the directory entry */
49 struct inode
**res_ino
, /* place to store resulting inode */
50 struct sffs_attr
*attr
/* place to store inode attributes */
53 /* Given a directory inode and a name, progress into a directory entry.
58 if ((r
= push_path(path
, name
)) != OK
)
61 dprintf(("%s: go_down: name '%s', path now '%s'\n", sffs_name
, name
, path
));
63 ino
= lookup_dentry(parent
, name
);
65 dprintf(("%s: lookup_dentry('%s') returned %p\n", sffs_name
, name
, ino
));
68 r
= verify_path(path
, ino
, attr
, &stale
);
70 r
= sffs_table
->t_getattr(path
, attr
);
72 dprintf(("%s: path query returned %d\n", sffs_name
, r
));
85 dprintf(("%s: name '%s'\n", sffs_name
, name
));
88 if ((ino
= get_free_inode()) == NULL
)
91 dprintf(("%s: inode %p ref %d\n", sffs_name
, ino
, ino
->i_ref
));
93 ino
->i_flags
= MODE_TO_DIRFLAG(attr
->a_mode
);
95 add_dentry(parent
, name
, ino
);
102 /*===========================================================================*
104 *===========================================================================*/
105 int do_lookup(ino_t dir_nr
, char *name
, struct fsdriver_node
*node
,
108 /* Resolve a path string to an inode.
110 struct inode
*dir_ino
, *ino
= NULL
;
111 struct sffs_attr attr
;
115 dprintf(("%s: lookup: got query for %"PRIu64
", '%s'\n",
116 sffs_name
, dir_nr
, name
));
118 if ((dir_ino
= find_inode(dir_nr
)) == NULL
)
121 attr
.a_mask
= SFFS_ATTR_MODE
| SFFS_ATTR_SIZE
;
123 if ((r
= verify_inode(dir_ino
, path
, &attr
)) != OK
)
126 if (!IS_DIR(dir_ino
))
130 if (!strcmp(name
, "."))
131 get_inode(ino
= dir_ino
);
132 else if (!strcmp(name
, ".."))
133 r
= go_up(path
, dir_ino
, &ino
, &attr
);
135 r
= go_down(path
, dir_ino
, name
, &ino
, &attr
);
140 node
->fn_ino_nr
= INODE_NR(ino
);
141 node
->fn_mode
= get_mode(ino
, attr
.a_mode
);
142 node
->fn_size
= attr
.a_size
;
143 node
->fn_uid
= sffs_params
->p_uid
;
144 node
->fn_gid
= sffs_params
->p_gid
;
145 node
->fn_dev
= NO_DEV
;