Changeset 1dff985 in mainline for uspace/srv/vfs/vfs_node.c


Ignore:
Timestamp:
2017-03-03T21:32:38Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c577a9a
Parents:
5b46ec8 (diff), b8dbe2f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~zarevucky-jiri/helenos/vfs-2.5 up to revision 1926

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_node.c

    r5b46ec8 r1dff985  
    4545#include <async.h>
    4646#include <errno.h>
     47#include <macros.h>
    4748
    4849/** Mutex protecting the VFS node hash table. */
     
    106107void vfs_node_delref(vfs_node_t *node)
    107108{
    108         bool free_vfs_node = false;
    109         bool free_fs_node = false;
    110        
    111         fibril_mutex_lock(&nodes_mutex);
    112        
    113         if (node->refcnt-- == 1) {
     109        bool free_node = false;
     110       
     111        fibril_mutex_lock(&nodes_mutex);
     112       
     113        node->refcnt--;
     114        if (node->refcnt == 0) {
    114115               
    115116                /*
     
    119120               
    120121                hash_table_remove_item(&nodes, &node->nh_link);
    121                 free_vfs_node = true;
    122                
    123                 if (!node->lnkcnt)
    124                         free_fs_node = true;
    125         }
    126        
    127         fibril_mutex_unlock(&nodes_mutex);
    128        
    129         if (free_fs_node) {
    130                
     122                free_node = true;
     123        }
     124       
     125        fibril_mutex_unlock(&nodes_mutex);
     126       
     127        if (free_node) {
    131128                /*
    132                  * The node is not visible in the file system namespace.
    133                  * Free up its resources.
     129                 * DESTROY will free up the file's resources if there are no more hard links.
    134130                 */
    135131               
    136132                async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
    137                 sysarg_t rc = async_req_2_0(exch, VFS_OUT_DESTROY,
    138                     (sysarg_t) node->service_id, (sysarg_t)node->index);
    139                
    140                 assert(rc == EOK);
     133                async_msg_2(exch, VFS_OUT_DESTROY,
     134                        (sysarg_t) node->service_id, (sysarg_t)node->index);
    141135                vfs_exchange_release(exch);
    142         }
    143        
    144         if (free_vfs_node)
     136
    145137                free(node);
     138        }
    146139}
    147140
     
    190183                node->index = result->triplet.index;
    191184                node->size = result->size;
    192                 node->lnkcnt = result->lnkcnt;
    193185                node->type = result->type;
    194186                fibril_rwlock_initialize(&node->contents_rwlock);
     
    196188        } else {
    197189                node = hash_table_get_inst(tmp, vfs_node_t, nh_link);
    198                 if (node->type == VFS_NODE_UNKNOWN &&
    199                     result->type != VFS_NODE_UNKNOWN) {
    200                         /* Upgrade the node type. */
    201                         node->type = result->type;
    202                 }
    203         }
    204 
    205         assert(node->size == result->size || node->type != VFS_NODE_FILE);
    206         assert(node->lnkcnt == result->lnkcnt);
    207         assert(node->type == result->type || result->type == VFS_NODE_UNKNOWN);
     190        }
    208191
    209192        _vfs_node_addref(node);
     193        fibril_mutex_unlock(&nodes_mutex);
     194
     195        return node;
     196}
     197
     198vfs_node_t *vfs_node_peek(vfs_lookup_res_t *result)
     199{
     200        vfs_node_t *node = NULL;
     201
     202        fibril_mutex_lock(&nodes_mutex);
     203        ht_link_t *tmp = hash_table_find(&nodes, &result->triplet);
     204        if (tmp) {
     205                node = hash_table_get_inst(tmp, vfs_node_t, nh_link);
     206        }
    210207        fibril_mutex_unlock(&nodes_mutex);
    211208
     
    318315}
    319316
     317int64_t vfs_node_get_size(vfs_node_t *node)
     318{
     319        if (node->size == -1) {
     320                sysarg_t sz1 = 0;
     321                sysarg_t sz2 = 0;
     322               
     323                async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
     324                (void) async_req_2_2(exch, VFS_OUT_GET_SIZE,
     325                        node->service_id, node->index, &sz1, &sz2);
     326                vfs_exchange_release(exch);
     327               
     328                node->size = MERGE_LOUP32(sz1, sz2);
     329        }
     330        return node->size;
     331}
     332
     333bool vfs_node_has_children(vfs_node_t *node)
     334{
     335        async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
     336        int rc = async_req_2_0(exch, VFS_OUT_IS_EMPTY, node->service_id, node->index);
     337        vfs_exchange_release(exch);
     338        return rc == ENOTEMPTY;
     339}
     340
    320341/**
    321342 * @}
Note: See TracChangeset for help on using the changeset viewer.