usb_disk: use CD icon for optical media

Tested with a CD drive and a USB adapter.
This commit is contained in:
François Revol 2015-11-24 13:17:39 +01:00
parent ce27a0cc0a
commit 6c51d2639b

View File

@ -288,6 +288,12 @@ const unsigned char kSDIcon[] = {
0x0a, 0x08, 0x02, 0x08, 0x09, 0x00 0x0a, 0x08, 0x02, 0x08, 0x09, 0x00
}; };
device_icon kKeyIconData = { (int32)sizeof(kDeviceIcon), (void *)kDeviceIcon };
device_icon kCDIconData = { (int32)sizeof(kCDIcon), (void *)kCDIcon };
device_icon kMSIconData = { (int32)sizeof(kMemoryStickIcon),
(void *)kMemoryStickIcon };
device_icon kSDIconData = { (int32)sizeof(kSDIcon), (void *)kSDIcon };
// //
//#pragma mark - Forward Declarations //#pragma mark - Forward Declarations
// //
@ -1328,32 +1334,56 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
break; break;
case B_GET_ICON_NAME: case B_GET_ICON_NAME:
result = user_strlcpy((char *)buffer, {
"devices/drive-removable-media-usb", B_FILE_NAME_LENGTH); const char *iconName = "devices/drive-removable-media-usb";
switch (lun->device_type) {
case B_CD:
case B_OPTICAL:
iconName = "devices/drive-optical";
break;
case B_TAPE: // TODO
default:
break;
}
result = user_strlcpy((char *)buffer, iconName,
B_FILE_NAME_LENGTH);
break; break;
}
case B_GET_VECTOR_ICON: case B_GET_VECTOR_ICON:
{ {
device_icon *icon = &kKeyIconData;
if (length != sizeof(device_icon)) { if (length != sizeof(device_icon)) {
result = B_BAD_VALUE; result = B_BAD_VALUE;
break; break;
} }
switch (lun->device_type) {
case B_CD:
case B_OPTICAL:
icon = &kCDIconData;
break;
case B_TAPE: // TODO
default:
break;
}
device_icon iconData; device_icon iconData;
if (user_memcpy(&iconData, buffer, sizeof(device_icon)) != B_OK) { if (user_memcpy(&iconData, buffer, sizeof(device_icon)) != B_OK) {
result = B_BAD_ADDRESS; result = B_BAD_ADDRESS;
break; break;
} }
if (iconData.icon_size >= (int32)sizeof(kDeviceIcon)) { if (iconData.icon_size >= icon->icon_size) {
if (user_memcpy(iconData.icon_data, kDeviceIcon, if (user_memcpy(iconData.icon_data, icon->icon_data,
sizeof(kDeviceIcon)) != B_OK) { (size_t)icon->icon_size) != B_OK) {
result = B_BAD_ADDRESS; result = B_BAD_ADDRESS;
break; break;
} }
} }
iconData.icon_size = sizeof(kDeviceIcon); iconData.icon_size = icon->icon_size;
result = user_memcpy(buffer, &iconData, sizeof(device_icon)); result = user_memcpy(buffer, &iconData, sizeof(device_icon));
break; break;
} }