From 9f6ae76f020cd6cf1fca7a3ae21ee7819581307d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 1 Aug 2008 09:59:19 +0000 Subject: [PATCH] * Added acquire_vnode() call that you can use to get another reference to an inode - unlike get_vnode() the busy flag won't prevent you from getting that reference. * Changed put_vnode() to return an error in case the vnode couldn't be found. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26713 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/drivers/fs_interface.h | 1 + headers/private/fs_shell/fssh_api_wrapper.h | 1 + headers/private/fs_shell/fssh_fs_interface.h | 2 ++ src/system/kernel/fs/vfs.cpp | 22 ++++++++++++++++++-- src/tools/fs_shell/vfs.cpp | 22 ++++++++++++++++++-- 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/headers/os/drivers/fs_interface.h b/headers/os/drivers/fs_interface.h index e81cea9341..a758c79b48 100644 --- a/headers/os/drivers/fs_interface.h +++ b/headers/os/drivers/fs_interface.h @@ -309,6 +309,7 @@ extern status_t publish_vnode(fs_volume *volume, ino_t vnodeID, extern status_t get_vnode(fs_volume *volume, ino_t vnodeID, void **_privateNode); extern status_t put_vnode(fs_volume *volume, ino_t vnodeID); +extern status_t acquire_vnode(fs_volume *volume, ino_t vnodeID); extern status_t remove_vnode(fs_volume *volume, ino_t vnodeID); extern status_t unremove_vnode(fs_volume *volume, ino_t vnodeID); extern status_t get_vnode_removed(fs_volume *volume, ino_t vnodeID, diff --git a/headers/private/fs_shell/fssh_api_wrapper.h b/headers/private/fs_shell/fssh_api_wrapper.h index 8da598137a..ed09b3cf52 100644 --- a/headers/private/fs_shell/fssh_api_wrapper.h +++ b/headers/private/fs_shell/fssh_api_wrapper.h @@ -905,6 +905,7 @@ #define publish_vnode fssh_publish_vnode #define get_vnode fssh_get_vnode #define put_vnode fssh_put_vnode +#define acquire_vnode fssh_acquire_vnode #define remove_vnode fssh_remove_vnode #define unremove_vnode fssh_unremove_vnode #define get_vnode_removed fssh_get_vnode_removed diff --git a/headers/private/fs_shell/fssh_fs_interface.h b/headers/private/fs_shell/fssh_fs_interface.h index 47231f5c71..d4d406c9c8 100644 --- a/headers/private/fs_shell/fssh_fs_interface.h +++ b/headers/private/fs_shell/fssh_fs_interface.h @@ -347,6 +347,8 @@ extern fssh_status_t fssh_get_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID, void **_privateNode); extern fssh_status_t fssh_put_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID); +extern fssh_status_t fssh_acquire_vnode(fssh_fs_volume *volume, + fssh_vnode_id vnodeID); extern fssh_status_t fssh_remove_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID); extern fssh_status_t fssh_unremove_vnode(fssh_fs_volume *volume, diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index f34ad6338e..e191c3332b 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -3193,6 +3193,23 @@ get_vnode(fs_volume *volume, ino_t vnodeID, void **_fsNode) } +extern "C" status_t +acquire_vnode(fs_volume *volume, ino_t vnodeID) +{ + struct vnode *vnode; + + mutex_lock(&sVnodeMutex); + vnode = lookup_vnode(volume->id, vnodeID); + mutex_unlock(&sVnodeMutex); + + if (vnode == NULL) + return B_BAD_VALUE; + + inc_vnode_ref_count(vnode); + return B_OK; +} + + extern "C" status_t put_vnode(fs_volume *volume, ino_t vnodeID) { @@ -3202,9 +3219,10 @@ put_vnode(fs_volume *volume, ino_t vnodeID) vnode = lookup_vnode(volume->id, vnodeID); mutex_unlock(&sVnodeMutex); - if (vnode) - dec_vnode_ref_count(vnode, false, true); + if (vnode == NULL) + return B_BAD_VALUE; + dec_vnode_ref_count(vnode, false, true); return B_OK; } diff --git a/src/tools/fs_shell/vfs.cpp b/src/tools/fs_shell/vfs.cpp index 795491d15e..aba2b88a2a 100644 --- a/src/tools/fs_shell/vfs.cpp +++ b/src/tools/fs_shell/vfs.cpp @@ -2017,6 +2017,23 @@ fssh_get_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID, void **fsNode) } +extern "C" fssh_status_t +fssh_acquire_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID) +{ + struct vnode *vnode; + + fssh_mutex_lock(&sVnodeMutex); + vnode = lookup_vnode(volume->id, vnodeID); + fssh_mutex_unlock(&sVnodeMutex); + + if (vnode == NULL) + return FSSH_B_BAD_VALUE; + + inc_vnode_ref_count(vnode); + return FSSH_B_OK; +} + + extern "C" fssh_status_t fssh_put_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID) { @@ -2026,9 +2043,10 @@ fssh_put_vnode(fssh_fs_volume *volume, fssh_vnode_id vnodeID) vnode = lookup_vnode(volume->id, vnodeID); fssh_mutex_unlock(&sVnodeMutex); - if (vnode) - dec_vnode_ref_count(vnode, true); + if (vnode == NULL) + return FSSH_B_BAD_VALUE; + dec_vnode_ref_count(vnode, true); return FSSH_B_OK; }