Rev 2770 | Rev 2792 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2770 | Rev 2791 | ||
---|---|---|---|
Line 67... | Line 67... | ||
67 | /* |
67 | /* |
68 | * Implementation of the libfs interface. |
68 | * Implementation of the libfs interface. |
69 | */ |
69 | */ |
70 | 70 | ||
71 | /* Forward declarations of static functions. */ |
71 | /* Forward declarations of static functions. */ |
72 | static bool tmpfs_match(void *, void *, const char *); |
72 | static void *tmpfs_match(void *, const char *); |
73 | static void *tmpfs_node_get(fs_handle_t, dev_handle_t, fs_index_t); |
73 | static void *tmpfs_node_get(fs_handle_t, dev_handle_t, fs_index_t); |
74 | static void *tmpfs_create_node(int); |
74 | static void *tmpfs_create_node(int); |
75 | static bool tmpfs_link_node(void *, void *, const char *); |
75 | static bool tmpfs_link_node(void *, void *, const char *); |
76 | static int tmpfs_unlink_node(void *, void *); |
76 | static int tmpfs_unlink_node(void *, void *); |
77 | static void tmpfs_destroy_node(void *); |
77 | static void tmpfs_destroy_node(void *); |
Line 90... | Line 90... | ||
90 | static unsigned tmpfs_lnkcnt_get(void *nodep) |
90 | static unsigned tmpfs_lnkcnt_get(void *nodep) |
91 | { |
91 | { |
92 | return ((tmpfs_dentry_t *) nodep)->lnkcnt; |
92 | return ((tmpfs_dentry_t *) nodep)->lnkcnt; |
93 | } |
93 | } |
94 | 94 | ||
95 | static void *tmpfs_child_get(void *nodep) |
95 | static bool tmpfs_has_children(void *nodep) |
96 | { |
96 | { |
97 | return ((tmpfs_dentry_t *) nodep)->child; |
97 | return ((tmpfs_dentry_t *) nodep)->child != NULL; |
98 | } |
- | |
99 | - | ||
100 | static void *tmpfs_sibling_get(void *nodep) |
- | |
101 | { |
- | |
102 | return ((tmpfs_dentry_t *) nodep)->sibling; |
- | |
103 | } |
98 | } |
104 | 99 | ||
105 | static void *tmpfs_root_get(void) |
100 | static void *tmpfs_root_get(void) |
106 | { |
101 | { |
107 | return root; |
102 | return root; |
Line 131... | Line 126... | ||
131 | .link = tmpfs_link_node, |
126 | .link = tmpfs_link_node, |
132 | .unlink = tmpfs_unlink_node, |
127 | .unlink = tmpfs_unlink_node, |
133 | .index_get = tmpfs_index_get, |
128 | .index_get = tmpfs_index_get, |
134 | .size_get = tmpfs_size_get, |
129 | .size_get = tmpfs_size_get, |
135 | .lnkcnt_get = tmpfs_lnkcnt_get, |
130 | .lnkcnt_get = tmpfs_lnkcnt_get, |
136 | .child_get = tmpfs_child_get, |
131 | .has_children = tmpfs_has_children, |
137 | .sibling_get = tmpfs_sibling_get, |
- | |
138 | .root_get = tmpfs_root_get, |
132 | .root_get = tmpfs_root_get, |
139 | .plb_get_char = tmpfs_plb_get_char, |
133 | .plb_get_char = tmpfs_plb_get_char, |
140 | .is_directory = tmpfs_is_directory, |
134 | .is_directory = tmpfs_is_directory, |
141 | .is_file = tmpfs_is_file |
135 | .is_file = tmpfs_is_file |
142 | }; |
136 | }; |
Line 241... | Line 235... | ||
241 | return true; |
235 | return true; |
242 | } |
236 | } |
243 | 237 | ||
244 | /** Compare one component of path to a directory entry. |
238 | /** Compare one component of path to a directory entry. |
245 | * |
239 | * |
246 | * @param prnt Node from which we descended. |
240 | * @param parentp Pointer to node from which we descended. |
247 | * @param chld Node to compare the path component with. |
241 | * @param childp Pointer to node to compare the path component with. |
248 | * @param component Array of characters holding component name. |
242 | * @param component Array of characters holding component name. |
249 | * |
243 | * |
250 | * @return True on match, false otherwise. |
244 | * @return True on match, false otherwise. |
251 | */ |
245 | */ |
- | 246 | static bool |
|
252 | bool tmpfs_match(void *prnt, void *chld, const char *component) |
247 | tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp, |
- | 248 | const char *component) |
|
253 | { |
249 | { |
254 | tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; |
- | |
255 | tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld; |
- | |
256 | - | ||
257 | unsigned long key = (unsigned long) parentp; |
250 | unsigned long key = (unsigned long) parentp; |
258 | link_t *hlp = hash_table_find(&childp->names, &key); |
251 | link_t *hlp = hash_table_find(&childp->names, &key); |
259 | assert(hlp); |
252 | assert(hlp); |
260 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
253 | tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); |
261 | - | ||
262 | return !strcmp(namep->name, component); |
254 | return !strcmp(namep->name, component); |
263 | } |
255 | } |
264 | 256 | ||
- | 257 | void *tmpfs_match(void *prnt, const char *component) |
|
- | 258 | { |
|
- | 259 | tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; |
|
- | 260 | tmpfs_dentry_t *childp = parentp->child; |
|
- | 261 | ||
- | 262 | while (childp && !tmpfs_match_one(parentp, childp, component)) |
|
- | 263 | childp = childp->sibling; |
|
- | 264 | ||
- | 265 | return (void *) childp; |
|
- | 266 | } |
|
- | 267 | ||
265 | void * |
268 | void * |
266 | tmpfs_node_get(fs_handle_t fs_handle, dev_handle_t dev_handle, fs_index_t index) |
269 | tmpfs_node_get(fs_handle_t fs_handle, dev_handle_t dev_handle, fs_index_t index) |
267 | { |
270 | { |
268 | unsigned long key = index; |
271 | unsigned long key = index; |
269 | link_t *lnk = hash_table_find(&dentries, &key); |
272 | link_t *lnk = hash_table_find(&dentries, &key); |