From 8b6349fd3278fcc2ae839c8bf8e830d70d273a94 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 23 Sep 2009 02:16:47 +0000 Subject: [PATCH] * Add a missing result assign that would cause the synchronize ioctl to always return an error. * Properly use the name length instead of a hardcoded buffer size when composing the name of the raw device and ensure proper termination. * Case new ioctls for Haiku as the target platform. Indeed this driver works fine on BeOS even though it was written natively for Haiku. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33240 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/disk/usb/usb_disk/usb_disk.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp index dcf4be1a50..a9256d0b35 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp @@ -909,15 +909,17 @@ usb_disk_open(const char *name, uint32 flags, void **cookie) return B_NAME_NOT_FOUND; int32 lastPart = 0; - for (int32 i = strlen(name) - 1; i >= 0; i--) { + size_t nameLength = strlen(name); + for (int32 i = nameLength - 1; i >= 0; i--) { if (name[i] == '/') { lastPart = i; break; } } - char rawName[32]; - strlcpy(rawName, name, lastPart + 2); + char rawName[nameLength + 4]; + strncpy(rawName, name, lastPart + 1); + rawName[lastPart + 1] = 0; strcat(rawName, "raw"); TRACE("opening raw device %s for %s\n", rawName, name); @@ -1027,7 +1029,7 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length) case B_FLUSH_DRIVE_CACHE: TRACE("B_FLUSH_DRIVE_CACHE\n"); - usb_disk_synchronize(lun, true); + result = usb_disk_synchronize(lun, true); break; case B_EJECT_DEVICE: @@ -1040,6 +1042,7 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length) NULL, NULL, false); break; +#if HAIKU_TARGET_PLATFORM_HAIKU case B_GET_ICON: // We don't support this legacy ioctl anymore, but the two other // icon ioctls below instead. @@ -1075,6 +1078,7 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length) result = user_memcpy(buffer, &iconData, sizeof(device_icon)); break; } +#endif default: TRACE_ALWAYS("unhandled ioctl %ld\n", op);