Changeset 736c164 in mainline


Ignore:
Timestamp:
2008-03-30T22:30:32Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
94b0b63
Parents:
81c0171e
Message:

Make libfs_lookup() more generic.

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libfs/libfs.c

    r81c0171e r736c164  
    149149        void *par = NULL;
    150150        void *cur = ops->root_get();
    151         void *tmp = ops->child_get(cur);
     151        void *tmp;
    152152
    153153        if (ops->plb_get_char(next) == '/')
     
    156156        char component[NAME_MAX + 1];
    157157        int len = 0;
    158         while (tmp && next <= last) {
     158        while (ops->has_children(cur) && next <= last) {
    159159
    160160                /* collect the component */
     
    177177
    178178                /* match the component */
    179                 while (tmp && !ops->match(cur, tmp, component))
    180                         tmp = ops->sibling_get(tmp);
     179                tmp = ops->match(cur, component);
    181180
    182181                /* handle miss: match amongst siblings */
     
    229228                par = cur;
    230229                cur = tmp;
    231                 tmp = ops->child_get(tmp);
    232230        }
    233231
    234232        /* handle miss: excessive components */
    235         if (!tmp && next <= last) {
     233        if (!ops->has_children(cur) && next <= last) {
    236234                if (lflag & (L_CREATE | L_LINK)) {
    237235                        if (!ops->is_directory(cur)) {
  • uspace/lib/libfs/libfs.h

    r81c0171e r736c164  
    4343
    4444typedef struct {
    45         bool (* match)(void *, void *, const char *);
     45        void * (* match)(void *, const char *);
    4646        void * (* node_get)(fs_handle_t, dev_handle_t, fs_index_t);
    4747        void * (* create)(int);
     
    5252        size_t (* size_get)(void *);
    5353        unsigned (* lnkcnt_get)(void *);
    54         void *(* child_get)(void *);
    55         void *(* sibling_get)(void *);
     54        bool (* has_children)(void *);
    5655        void *(* root_get)(void);
    5756        char (* plb_get_char)(unsigned pos);   
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r81c0171e r736c164  
    7070
    7171/* Forward declarations of static functions. */
    72 static bool tmpfs_match(void *, void *, const char *);
     72static void *tmpfs_match(void *, const char *);
    7373static void *tmpfs_node_get(fs_handle_t, dev_handle_t, fs_index_t);
    7474static void *tmpfs_create_node(int);
     
    9393}
    9494
    95 static void *tmpfs_child_get(void *nodep)
    96 {
    97         return ((tmpfs_dentry_t *) nodep)->child;
    98 }
    99 
    100 static void *tmpfs_sibling_get(void *nodep)
    101 {
    102         return ((tmpfs_dentry_t *) nodep)->sibling;
     95static bool tmpfs_has_children(void *nodep)
     96{
     97        return ((tmpfs_dentry_t *) nodep)->child != NULL;
    10398}
    10499
     
    134129        .size_get = tmpfs_size_get,
    135130        .lnkcnt_get = tmpfs_lnkcnt_get,
    136         .child_get = tmpfs_child_get,
    137         .sibling_get = tmpfs_sibling_get,
     131        .has_children = tmpfs_has_children,
    138132        .root_get = tmpfs_root_get,
    139133        .plb_get_char = tmpfs_plb_get_char,
     
    244238/** Compare one component of path to a directory entry.
    245239 *
    246  * @param prnt          Node from which we descended.
    247  * @param chld          Node to compare the path component with.
     240 * @param parentp       Pointer to node from which we descended.
     241 * @param childp        Pointer to node to compare the path component with.
    248242 * @param component     Array of characters holding component name.
    249243 *
    250244 * @return              True on match, false otherwise.
    251245 */
    252 bool tmpfs_match(void *prnt, void *chld, const char *component)
    253 {
    254         tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;
    255         tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;
    256 
     246static bool
     247tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp,
     248    const char *component)
     249{
    257250        unsigned long key = (unsigned long) parentp;
    258251        link_t *hlp = hash_table_find(&childp->names, &key);
    259252        assert(hlp);
    260253        tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);
    261 
    262254        return !strcmp(namep->name, component);
     255}
     256
     257void *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;
    263266}
    264267
Note: See TracChangeset for help on using the changeset viewer.