static status_t cd_ioctl(void* cookie, uint32 op, void* buffer, size_t length) { cd_handle* handle = (cd_handle*)cookie; cd_driver_info *info = handle->info; TRACE("ioctl(op = %lu)\n", op); switch (op) { case B_GET_DEVICE_SIZE: { status_t status = update_capacity(info); if (status != B_OK) return status; size_t size = info->capacity * info->block_size; return user_memcpy(buffer, &size, sizeof(size_t)); } case B_GET_GEOMETRY: { if (buffer == NULL /*|| length != sizeof(device_geometry)*/) return B_BAD_VALUE; device_geometry geometry; status_t status = get_geometry(handle, &geometry); if (status != B_OK) return status; return user_memcpy(buffer, &geometry, sizeof(device_geometry)); } case B_GET_ICON_NAME: return user_strlcpy((char*)buffer, "devices/drive-optical", B_FILE_NAME_LENGTH); case B_GET_VECTOR_ICON: { device_icon iconData; if (length != sizeof(device_icon)) return B_BAD_VALUE; if (user_memcpy(&iconData, buffer, sizeof(device_icon)) != B_OK) return B_BAD_ADDRESS; if (iconData.icon_size >= (int32)sizeof(kCDIcon)) { if (user_memcpy(iconData.icon_data, kCDIcon, sizeof(kCDIcon)) != B_OK) return B_BAD_ADDRESS; } iconData.icon_size = sizeof(kCDIcon); return user_memcpy(buffer, &iconData, sizeof(device_icon)); } case B_SCSI_GET_TOC: // TODO: we pass a user buffer here! return get_toc(info, (scsi_toc *)buffer); case B_EJECT_DEVICE: case B_SCSI_EJECT: return load_eject(info, false); case B_LOAD_MEDIA: return load_eject(info, true); case B_SCSI_GET_POSITION: { if (buffer == NULL) return B_BAD_VALUE; scsi_position position; status_t status = get_position(info, &position); if (status != B_OK) return status; return user_memcpy(buffer, &position, sizeof(scsi_position)); } case B_SCSI_GET_VOLUME: // TODO: we pass a user buffer here! return get_set_volume(info, (scsi_volume *)buffer, false); case B_SCSI_SET_VOLUME: // TODO: we pass a user buffer here! return get_set_volume(info, (scsi_volume *)buffer, true); case B_SCSI_PLAY_TRACK: { scsi_play_track track; if (user_memcpy(&track, buffer, sizeof(scsi_play_track)) != B_OK) return B_BAD_ADDRESS; return play_track_index(info, &track); } case B_SCSI_PLAY_POSITION: { scsi_play_position position; if (user_memcpy(&position, buffer, sizeof(scsi_play_position)) != B_OK) return B_BAD_ADDRESS; return play_msf(info, &position); } case B_SCSI_STOP_AUDIO: return stop_audio(info); case B_SCSI_PAUSE_AUDIO: return pause_resume(info, false); case B_SCSI_RESUME_AUDIO: return pause_resume(info, true); case B_SCSI_SCAN: { scsi_scan scanBuffer; if (user_memcpy(&scanBuffer, buffer, sizeof(scsi_scan)) != B_OK) return B_BAD_ADDRESS; return scan(info, &scanBuffer); } case B_SCSI_READ_CD: // TODO: we pass a user buffer here! return read_cd(info, (scsi_read_cd *)buffer); default: return sSCSIPeripheral->ioctl(handle->scsi_periph_handle, op, buffer, length); } }
static status_t das_ioctl(void* cookie, uint32 op, void* buffer, size_t length) { das_handle* handle = (das_handle*)cookie; das_driver_info* info = handle->info; TRACE("ioctl(op = %d)\n", op); switch (op) { case B_GET_DEVICE_SIZE: { status_t status = update_capacity(info); if (status != B_OK) return status; size_t size = info->capacity * info->block_size; return user_memcpy(buffer, &size, sizeof(size_t)); } case B_GET_GEOMETRY: { if (buffer == NULL /*|| length != sizeof(device_geometry)*/) return B_BAD_VALUE; device_geometry geometry; status_t status = get_geometry(handle, &geometry); if (status != B_OK) return status; return user_memcpy(buffer, &geometry, sizeof(device_geometry)); } case B_GET_ICON_NAME: // TODO: take device type into account! return user_strlcpy((char*)buffer, info->removable ? "devices/drive-removable-media" : "devices/drive-harddisk", B_FILE_NAME_LENGTH); case B_GET_VECTOR_ICON: { // TODO: take device type into account! device_icon iconData; if (length != sizeof(device_icon)) return B_BAD_VALUE; if (user_memcpy(&iconData, buffer, sizeof(device_icon)) != B_OK) return B_BAD_ADDRESS; if (iconData.icon_size >= (int32)sizeof(kDriveIcon)) { if (user_memcpy(iconData.icon_data, kDriveIcon, sizeof(kDriveIcon)) != B_OK) return B_BAD_ADDRESS; } iconData.icon_size = sizeof(kDriveIcon); return user_memcpy(buffer, &iconData, sizeof(device_icon)); } case B_EJECT_DEVICE: case B_SCSI_EJECT: return load_eject(info, false); case B_LOAD_MEDIA: return load_eject(info, true); case B_FLUSH_DRIVE_CACHE: return synchronize_cache(info); default: return sSCSIPeripheral->ioctl(handle->scsi_periph_handle, op, buffer, length); } }