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.
This commit is contained in:
Ingo Weinhold
2013-11-30 17:02:48 +01:00
parent 4a5eb16053
commit 28092be196
2 changed files with 33 additions and 5 deletions
+28 -2
View File
@@ -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);
}
@@ -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 */