Subversion Repositories HelenOS

Rev

Rev 2763 | Rev 2770 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2763 Rev 2766
Line 48... Line 48...
48
#include <libadt/list.h>
48
#include <libadt/list.h>
49
#include <unistd.h>
49
#include <unistd.h>
50
#include <ctype.h>
50
#include <ctype.h>
51
#include <fcntl.h>
51
#include <fcntl.h>
52
#include <assert.h>
52
#include <assert.h>
53
#include <atomic.h>
-
 
54
#include <vfs/canonify.h>
53
#include <vfs/canonify.h>
55
 
54
 
56
/* Forward declarations of static functions. */
55
/* Forward declarations of static functions. */
57
static int vfs_truncate_internal(int, int, unsigned long, size_t);
56
static int vfs_truncate_internal(int, int, unsigned long, size_t);
58
 
57
 
Line 60... Line 59...
60
 * This rwlock prevents the race between a triplet-to-VFS-node resolution and a
59
 * This rwlock prevents the race between a triplet-to-VFS-node resolution and a
61
 * concurrent VFS operation which modifies the file system namespace.
60
 * concurrent VFS operation which modifies the file system namespace.
62
 */
61
 */
63
RWLOCK_INITIALIZE(namespace_rwlock);
62
RWLOCK_INITIALIZE(namespace_rwlock);
64
 
63
 
65
atomic_t rootfs_futex = FUTEX_INITIALIZER;
64
futex_t rootfs_futex = FUTEX_INITIALIZER;
66
vfs_triplet_t rootfs = {
65
vfs_triplet_t rootfs = {
67
    .fs_handle = 0,
66
    .fs_handle = 0,
68
    .dev_handle = 0,
67
    .dev_handle = 0,
69
    .index = 0,
68
    .index = 0,
70
};
69
};
Line 684... Line 683...
684
     * The name has already been unlinked by vfs_lookup_internal().
683
     * The name has already been unlinked by vfs_lookup_internal().
685
     * We have to get and put the VFS node to ensure that it is
684
     * We have to get and put the VFS node to ensure that it is
686
     * VFS_DESTROY'ed after the last reference to it is dropped.
685
     * VFS_DESTROY'ed after the last reference to it is dropped.
687
     */
686
     */
688
    vfs_node_t *node = vfs_node_get(&lr);
687
    vfs_node_t *node = vfs_node_get(&lr);
-
 
688
    futex_down(&nodes_futex);
689
    node->lnkcnt--;
689
    node->lnkcnt--;
-
 
690
    futex_up(&nodes_futex);
690
    rwlock_write_unlock(&namespace_rwlock);
691
    rwlock_write_unlock(&namespace_rwlock);
691
    vfs_node_put(node);
692
    vfs_node_put(node);
692
    ipc_answer_0(rid, EOK);
693
    ipc_answer_0(rid, EOK);
693
}
694
}
694
 
695
 
Line 808... Line 809...
808
            ipc_answer_0(rid, ENOMEM);
809
            ipc_answer_0(rid, ENOMEM);
809
            free(old);
810
            free(old);
810
            free(new);
811
            free(new);
811
            return;
812
            return;
812
        }
813
        }
-
 
814
        futex_down(&nodes_futex);
813
        new_node->lnkcnt--;
815
        new_node->lnkcnt--;
-
 
816
        futex_up(&nodes_futex);
814
        break;
817
        break;
815
    default:
818
    default:
816
        rwlock_write_unlock(&namespace_rwlock);
819
        rwlock_write_unlock(&namespace_rwlock);
817
        ipc_answer_0(rid, ENOTEMPTY);
820
        ipc_answer_0(rid, ENOTEMPTY);
818
        free(old);
821
        free(old);
Line 828... Line 831...
828
        ipc_answer_0(rid, rc);
831
        ipc_answer_0(rid, rc);
829
        free(old);
832
        free(old);
830
        free(new);
833
        free(new);
831
        return;
834
        return;
832
    }
835
    }
-
 
836
    futex_down(&nodes_futex);
833
    old_node->lnkcnt++;
837
    old_node->lnkcnt++;
-
 
838
    futex_up(&nodes_futex);
834
    /* Destroy the link for the old name. */
839
    /* Destroy the link for the old name. */
835
    rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);
840
    rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);
836
    if (rc != EOK) {
841
    if (rc != EOK) {
837
        rwlock_write_unlock(&namespace_rwlock);
842
        rwlock_write_unlock(&namespace_rwlock);
838
        vfs_node_put(old_node);
843
        vfs_node_put(old_node);
Line 841... Line 846...
841
        ipc_answer_0(rid, rc);
846
        ipc_answer_0(rid, rc);
842
        free(old);
847
        free(old);
843
        free(new);
848
        free(new);
844
        return;
849
        return;
845
    }
850
    }
-
 
851
    futex_down(&nodes_futex);
846
    old_node->lnkcnt--;
852
    old_node->lnkcnt--;
-
 
853
    futex_up(&nodes_futex);
847
    rwlock_write_unlock(&namespace_rwlock);
854
    rwlock_write_unlock(&namespace_rwlock);
848
    vfs_node_put(old_node);
855
    vfs_node_put(old_node);
849
    if (new_node)
856
    if (new_node)
850
        vfs_node_put(new_node);
857
        vfs_node_put(new_node);
851
    free(old);
858
    free(old);