Changeset b5553a2 in mainline


Ignore:
Timestamp:
2008-02-16T11:23:19Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f17667a
Parents:
8ccd2ea
Message:

Introduce the notion of VFS node link counts.

Location:
uspace/srv
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r8ccd2ea rb5553a2  
    5959#define DENTRIES_BUCKETS        256
    6060
     61#define TMPFS_GET_INDEX(x)      (((tmpfs_dentry_t *)(x))->index)
     62#define TMPFS_GET_LNKCNT(x)     1
     63
    6164/*
    6265 * Hash table of all directory entries.
     
    128131/** Compare one component of path to a directory entry.
    129132 *
    130  * @param dentry        Directory entry to compare the path component with.
     133 * @param nodep         Node to compare the path component with.
    131134 * @param component     Array of characters holding component name.
    132135 *
    133136 * @return              True on match, false otherwise.
    134137 */
    135 static bool match_component(tmpfs_dentry_t *dentry, const char *component)
    136 {
     138static bool match_component(void *nodep, const char *component)
     139{
     140        tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;
     141
    137142        return !strcmp(dentry->name, component);
    138143}
    139144
    140 static unsigned long create_node(tmpfs_dentry_t *dentry,
     145static void *create_node(void *nodep,
    141146    const char *component, int lflag)
    142147{
     148        tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;
     149
    143150        assert(dentry->type == TMPFS_DIRECTORY);
    144151        assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
     
    146153        tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));
    147154        if (!node)
    148                 return 0;
     155                return NULL;
    149156        size_t len = strlen(component);
    150157        char *name = malloc(len + 1);
    151158        if (!name) {
    152159                free(node);
    153                 return 0;
     160                return NULL;
    154161        }
    155162        strcpy(name, component);
     
    176183        /* Insert the new node into the dentry hash table. */
    177184        hash_table_insert(&dentries, &node->index, &node->dh_link);
    178         return node->index;
    179 }
    180 
    181 static int destroy_component(tmpfs_dentry_t *dentry)
     185        return (void *) node;
     186}
     187
     188static int destroy_component(void *nodeptr)
    182189{
    183190        return EPERM;
     
    242249                                        return;
    243250                                }
    244                                 unsigned long index = create_node(dcur,
     251                                void *nodep = create_node(dcur,
    245252                                    component, lflag);
    246                                 if (index > 0) {
    247                                         ipc_answer_4(rid, EOK,
     253                                if (nodep) {
     254                                        ipc_answer_5(rid, EOK,
    248255                                            tmpfs_reg.fs_handle, dev_handle,
    249                                             index, 0);
     256                                            TMPFS_GET_INDEX(nodep), 0,
     257                                            TMPFS_GET_LNKCNT(nodep));
    250258                                } else {
    251259                                        ipc_answer_0(rid, ENOSPC);
     
    289297                        len = 0;
    290298                               
    291                         unsigned long index;
    292                         index = create_node(dcur, component, lflag);
    293                         if (index) {
    294                                 ipc_answer_4(rid, EOK, tmpfs_reg.fs_handle,
    295                                     dev_handle, index, 0);
     299                        void *nodep = create_node(dcur, component, lflag);
     300                        if (nodep) {
     301                                ipc_answer_5(rid, EOK, tmpfs_reg.fs_handle,
     302                                    dev_handle, TMPFS_GET_INDEX(nodep), 0,
     303                                    TMPFS_GET_LNKCNT(nodep));
    296304                        } else {
    297305                                ipc_answer_0(rid, ENOSPC);
     
    322330        }
    323331
    324         ipc_answer_4(rid, EOK, tmpfs_reg.fs_handle, dev_handle, dcur->index,
    325             dcur->size);
     332        ipc_answer_5(rid, EOK, tmpfs_reg.fs_handle, dev_handle, dcur->index,
     333            dcur->size, TMPFS_GET_LNKCNT(dcur));
    326334}
    327335
  • uspace/srv/vfs/vfs.h

    r8ccd2ea rb5553a2  
    174174        vfs_triplet_t triplet;
    175175        size_t size;
     176        unsigned lnkcnt;
    176177} vfs_lookup_res_t;
    177178
     
    182183typedef struct {
    183184        VFS_TRIPLET;            /**< Identity of the node. */
    184         unsigned refcnt;        /**< Usage counter. */
     185
     186        /**
     187         * Usage counter.  This includes, but is not limited to, all vfs_file_t
     188         * structures that reference this node.
     189         */
     190        unsigned refcnt;
     191       
     192        /** Number of names this node has in the file system namespace. */
     193        unsigned lnkcnt;
     194
    185195        link_t nh_link;         /**< Node hash-table link. */
    186196        size_t size;            /**< Cached size of the file. */
  • uspace/srv/vfs/vfs_lookup.c

    r8ccd2ea rb5553a2  
    169169                result->triplet.index = (int) IPC_GET_ARG3(answer);
    170170                result->size = (size_t) IPC_GET_ARG4(answer);
     171                result->lnkcnt = (unsigned) IPC_GET_ARG5(answer);
    171172        }
    172173
  • uspace/srv/vfs/vfs_node.c

    r8ccd2ea rb5553a2  
    149149                node->index = result->triplet.index;
    150150                node->size = result->size;
     151                node->lnkcnt = result->lnkcnt;
    151152                link_initialize(&node->nh_link);
    152153                rwlock_initialize(&node->contents_rwlock);
     
    157158
    158159        assert(node->size == result->size);
     160        assert(node->lnkcnt == result->lnkcnt);
    159161
    160162        _vfs_node_addref(node);
Note: See TracChangeset for help on using the changeset viewer.