Devices: extend dm_wrapper and new layout
Shows Device path in /dev if used and Driver used. New tree-view layout for Basic Information and Attributes separated. Changes: - Added new attribute in device_manager to get the path of device - Tree view layout that separates the Basic Information of a device, such as name or driver used and the Attributes that shows the rest - new call in dm_wrapper - new case in device_manager - logic to add the new attributes as Device path and Driver used in DevicesView.cpp Change-Id: I05eaf5d7cf9e3b5ec8e9f1e0ac5c6cf7561ccde5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/11012 Reviewed-by: Kacper Kasper <[email protected]> Tested-by: Commit checker robot <[email protected]> Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Kacper Kasper
parent
e196d6d923
commit
315411d839
@@ -150,6 +150,8 @@ struct driver_module_info {
|
||||
|
||||
#define B_DEVICE_UNIQUE_ID "device/unique id" /* string */
|
||||
|
||||
#define B_DEVICE_PUBLISHED_PATH "device/published path"
|
||||
|
||||
/* device flags */
|
||||
#define B_FIND_CHILD_ON_DEMAND 0x01
|
||||
#define B_FIND_MULTIPLE_CHILDREN 0x02
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define DM_GET_CHILD 2
|
||||
#define DM_GET_NEXT_CHILD 3
|
||||
#define DM_GET_NEXT_ATTRIBUTE 4
|
||||
#define DM_GET_DRIVER_PATH 5
|
||||
|
||||
typedef addr_t device_node_cookie;
|
||||
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <Drivers.h>
|
||||
#include <StorageDefs.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "DevicesView.h"
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@@ -384,10 +391,31 @@ DevicesView::AddDeviceAndChildren(device_node_cookie *node, Device* parent)
|
||||
CAT_NONE, B_TRANSLATE("Unknown device"));
|
||||
}
|
||||
|
||||
struct device_attr_info driverAttrInfo;
|
||||
driverAttrInfo.node_cookie = *node;
|
||||
driverAttrInfo.cookie = 0;
|
||||
dm_get_driver_path(&driverAttrInfo);
|
||||
|
||||
bool hasPublishedPath = false;
|
||||
|
||||
// Add its attributes to the device, initialize it and add to the list.
|
||||
for (unsigned int i = 0; i < attributes.size(); i++) {
|
||||
if (attributes[i].fName == B_DEVICE_PUBLISHED_PATH) {
|
||||
newDevice->SetAttribute(B_TRANSLATE("Device paths"), attributes[i].fValue);
|
||||
hasPublishedPath = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
newDevice->SetAttribute(attributes[i].fName, attributes[i].fValue);
|
||||
}
|
||||
|
||||
if (driverAttrInfo.value.string[0] != '\0')
|
||||
newDevice->SetAttribute(B_TRANSLATE("Driver used"), driverAttrInfo.value.string);
|
||||
else
|
||||
newDevice->SetAttribute(B_TRANSLATE("Driver used"), B_TRANSLATE("Unknown"));
|
||||
if (!hasPublishedPath)
|
||||
newDevice->SetAttribute(B_TRANSLATE("Device paths"), B_TRANSLATE("None"));
|
||||
|
||||
newDevice->InitFromAttributes();
|
||||
fDevices.push_back(newDevice);
|
||||
|
||||
|
||||
@@ -55,9 +55,8 @@ PropertyList::PropertyList(const char* name)
|
||||
AddColumn(nameColumn = new BStringColumn(B_TRANSLATE("Name"), 150, 50, 500,
|
||||
B_TRUNCATE_MIDDLE),
|
||||
kNameColumn);
|
||||
AddColumn(new BStringColumn(B_TRANSLATE("Value"), 300, 50, 500,
|
||||
AddColumn(new BStringColumn(B_TRANSLATE("Value"), 400, 100, 1000,
|
||||
B_TRUNCATE_END), kValueColumn);
|
||||
SetSortColumn(nameColumn, false, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,9 +70,23 @@ void
|
||||
PropertyList::AddAttributes(const Attributes& attributes)
|
||||
{
|
||||
RemoveAll();
|
||||
|
||||
PropertyRow* basicRoot = new PropertyRow(B_TRANSLATE("Basic information"), "");
|
||||
PropertyRow* advancedRoot = new PropertyRow(B_TRANSLATE("Attributes"), "");
|
||||
|
||||
AddRow(basicRoot);
|
||||
AddRow(advancedRoot);
|
||||
|
||||
for (unsigned int i = 0; i < attributes.size(); i++) {
|
||||
AddRow(new PropertyRow(attributes[i].fName, attributes[i].fValue));
|
||||
PropertyRow* childRow = new PropertyRow(attributes[i].fName, attributes[i].fValue);
|
||||
|
||||
if (attributes[i].fName.FindFirst('/') != B_ERROR)
|
||||
AddRow(childRow, advancedRoot);
|
||||
else
|
||||
AddRow(childRow, basicRoot);
|
||||
}
|
||||
ExpandOrCollapse(basicRoot, true);
|
||||
ExpandOrCollapse(advancedRoot, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,3 +67,11 @@ dm_get_next_attr(struct device_attr_info *attr)
|
||||
return _kern_generic_syscall(DEVICE_MANAGER_SYSCALLS,
|
||||
DM_GET_NEXT_ATTRIBUTE, attr, sizeof(struct device_attr_info));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
dm_get_driver_path(struct device_attr_info *attr)
|
||||
{
|
||||
return _kern_generic_syscall(DEVICE_MANAGER_SYSCALLS,
|
||||
DM_GET_DRIVER_PATH, attr, sizeof(struct device_attr_info));
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ status_t get_root(device_node_cookie *cookie);
|
||||
status_t get_child(device_node_cookie *cookie);
|
||||
status_t get_next_child(device_node_cookie *cookie);
|
||||
status_t dm_get_next_attr(struct device_attr_info *attr);
|
||||
status_t dm_get_driver_path(struct device_attr_info *attr);
|
||||
|
||||
#endif /* DM_WRAPPER_H */
|
||||
|
||||
@@ -480,6 +480,42 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
|
||||
// copy back to user space
|
||||
return user_memcpy(buffer, &attrInfo, sizeof(device_attr_info));
|
||||
}
|
||||
|
||||
case DM_GET_DRIVER_PATH:
|
||||
{
|
||||
struct device_attr_info attrInfo;
|
||||
if (!IS_USER_ADDRESS(buffer))
|
||||
return B_BAD_ADDRESS;
|
||||
if (bufferSize != sizeof(device_attr_info))
|
||||
return B_BAD_VALUE;
|
||||
if (user_memcpy(&attrInfo, buffer, sizeof(device_attr_info)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
device_node* node = (device_node*)attrInfo.node_cookie;
|
||||
if (node == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
const char* driverPath = NULL;
|
||||
if (node->ModuleName() != NULL)
|
||||
driverPath = node->ModuleName();
|
||||
|
||||
if (driverPath == NULL || driverPath[0] == '\0')
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
|
||||
char* allocatedPath = NULL;
|
||||
status_t status = module_get_path(driverPath, &allocatedPath);
|
||||
|
||||
if (status == B_OK && allocatedPath != NULL) {
|
||||
strlcpy(attrInfo.value.string, allocatedPath, sizeof(attrInfo.value.string));
|
||||
free(allocatedPath);
|
||||
} else {
|
||||
attrInfo.value.string[0] = '\0';
|
||||
}
|
||||
|
||||
attrInfo.type = B_STRING_TYPE;
|
||||
|
||||
return user_memcpy(buffer, &attrInfo, sizeof(device_attr_info));
|
||||
}
|
||||
}
|
||||
|
||||
return B_BAD_HANDLER;
|
||||
@@ -675,7 +711,7 @@ publish_device(device_node *node, const char *path, const char *moduleName)
|
||||
attr = new(std::nothrow) device_attr_private();
|
||||
if (attr != NULL) {
|
||||
char buf[256];
|
||||
sprintf(buf, "dev/%" B_PRIdINO "/path", device->ID());
|
||||
snprintf(buf, sizeof(buf), "dev/%" B_PRIdINO "/path", device->ID());
|
||||
attr->name = strdup(buf);
|
||||
attr->type = B_STRING_TYPE;
|
||||
attr->value.string = strdup(path);
|
||||
@@ -685,13 +721,23 @@ publish_device(device_node *node, const char *path, const char *moduleName)
|
||||
attr = new(std::nothrow) device_attr_private();
|
||||
if (attr != NULL) {
|
||||
char buf[256];
|
||||
sprintf(buf, "dev/%" B_PRIdINO "/driver", device->ID());
|
||||
snprintf(buf, sizeof(buf), "dev/%" B_PRIdINO "/driver", device->ID());
|
||||
attr->name = strdup(buf);
|
||||
attr->type = B_STRING_TYPE;
|
||||
attr->value.string = strdup(moduleName);
|
||||
node->Attributes().Add(attr);
|
||||
}
|
||||
|
||||
attr = new(std::nothrow) device_attr_private();
|
||||
if (attr != NULL) {
|
||||
attr->name = strdup(B_DEVICE_PUBLISHED_PATH);
|
||||
attr->type = B_STRING_TYPE;
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf), "/dev/%s", path);
|
||||
attr->value.string = strdup(buf);
|
||||
node->Attributes().Add(attr);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user