From 28092be1969370f0c4a92536ed066c5700cc56f0 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 30 Nov 2013 00:26:43 +0100 Subject: [PATCH] devfs: Add devfs_{get,put}_device() devfs_get_device() returns the device for a given path (if any), also acquiring a reference to its vnode (thus ensuring the device won't go away). devfs_put_device() puts the device vnode's reference. --- src/system/kernel/device_manager/devfs.cpp | 30 +++++++++++++++++-- .../kernel/device_manager/devfs_private.h | 8 +++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/device_manager/devfs.cpp b/src/system/kernel/device_manager/devfs.cpp index 6127269a94..88564a9ad0 100644 --- a/src/system/kernel/device_manager/devfs.cpp +++ b/src/system/kernel/device_manager/devfs.cpp @@ -2143,6 +2143,34 @@ devfs_unpublish_device(BaseDevice* device, bool disconnect) } +/*! Gets the device for a given devfs relative path. + If successful the call must be balanced with a call to devfs_put_device(). +*/ +status_t +devfs_get_device(const char* path, BaseDevice*& _device) +{ + devfs_vnode* node; + status_t status = get_node_for_path(sDeviceFileSystem, path, &node); + if (status != B_OK) + return status; + + if (!S_ISCHR(node->stream.type) || node->stream.u.dev.partition != NULL) { + put_vnode(sDeviceFileSystem->volume, node->id); + return B_BAD_VALUE; + } + + _device = node->stream.u.dev.device; + return B_OK; +} + + +void +devfs_put_device(BaseDevice* device) +{ + put_vnode(sDeviceFileSystem->volume, device->ID()); +} + + void devfs_compute_geometry_size(device_geometry* geometry, uint64 blockCount, uint32 blockSize) @@ -2175,5 +2203,3 @@ devfs_publish_device(const char* path, device_hooks* hooks) { return legacy_driver_publish(path, hooks); } - - diff --git a/src/system/kernel/device_manager/devfs_private.h b/src/system/kernel/device_manager/devfs_private.h index dc0ea9196a..74365133bf 100644 --- a/src/system/kernel/device_manager/devfs_private.h +++ b/src/system/kernel/device_manager/devfs_private.h @@ -16,8 +16,10 @@ namespace BPrivate { using BPrivate::BaseDevice; -status_t devfs_publish_device(const char* path, BaseDevice* device); -status_t devfs_unpublish_device(BaseDevice* device, bool disconnect); -status_t devfs_get_device(dev_t device, ino_t node, BaseDevice** _device); +status_t devfs_publish_device(const char* path, BaseDevice* device); +status_t devfs_unpublish_device(BaseDevice* device, bool disconnect); + +status_t devfs_get_device(const char* path, BaseDevice*& _device); +void devfs_put_device(BaseDevice* device); #endif /* DEVFS_PRIVATE_H */