hrev44684 adds 2 changesets to branch 'master' old head: cff0983994df0eba9ce5d308a5a9ae3686e4f47d new head: adf340f0ed7fd0cd6c3d1a1313f54e8488fdeb6d ---------------------------------------------------------------------------- 9b9cb22: Consolidated and fixed device_geometry computation. * The only implementation that would accept more than 2 TB was the one in scsi_disk. But even that one was limited to 63 TB. * Now there is a new utility function devfs_compute_geometry_size() which does it correctly for sizes up to 2^64 which should be good enough for quite some time :-) * This fixes bug #8992. adf340f: Style cleanup. [ Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 5 files changed, 68 insertions(+), 52 deletions(-) headers/private/kernel/fs/devfs.h | 25 ++++++----- .../kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp | 9 ++-- .../drivers/disk/scsi/scsi_disk/scsi_disk.cpp | 22 ++++------ .../kernel/drivers/disk/usb/usb_disk/usb_disk.cpp | 35 +++++++++------- src/system/kernel/device_manager/devfs.cpp | 29 +++++++++---- ############################################################################ Commit: 9b9cb227c7835fa55076dafac035a25e30b089ff URL: http://cgit.haiku-os.org/haiku/commit/?id=9b9cb22 Author: Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> Date: Mon Oct 8 11:54:07 2012 UTC Ticket: https://dev.haiku-os.org/ticket/8992 Consolidated and fixed device_geometry computation. * The only implementation that would accept more than 2 TB was the one in scsi_disk. But even that one was limited to 63 TB. * Now there is a new utility function devfs_compute_geometry_size() which does it correctly for sizes up to 2^64 which should be good enough for quite some time :-) * This fixes bug #8992. ---------------------------------------------------------------------------- diff --git a/headers/private/kernel/fs/devfs.h b/headers/private/kernel/fs/devfs.h index 6968da2..44db6e7 100644 --- a/headers/private/kernel/fs/devfs.h +++ b/headers/private/kernel/fs/devfs.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008, Axel DÃrfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. + * Copyright 2002-2012, Axel DÃrfler, axeld@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -29,6 +29,9 @@ status_t devfs_publish_device(const char *path, device_hooks *calls); status_t devfs_publish_directory(const char *path); status_t devfs_rescan_driver(const char *driverName); +void devfs_compute_geometry_size(device_geometry* geometry, uint64 blockCount, + uint32 blockSize); + #ifdef __cplusplus } #endif diff --git a/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp b/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp index e01fd5e..f2a65fb 100644 --- a/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp +++ b/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004-2010, Haiku, Inc. All rights reserved. + * Copyright 2004-2012, Haiku, Inc. All rights reserved. * Copyright 2002-2003, Thomas Kurschel. All rights reserved. * * Distributed under the terms of the MIT License. @@ -21,6 +21,7 @@ #include <algorithm> +#include <fs/devfs.h> #include <io_requests.h> #include <vm/vm_page.h> @@ -205,10 +206,8 @@ get_geometry(cd_handle *handle, device_geometry *geometry) if (status == B_DEV_MEDIA_CHANGED) return B_DEV_MEDIA_CHANGED; - geometry->bytes_per_sector = info->block_size; - geometry->sectors_per_track = 1; - geometry->cylinder_count = info->capacity; - geometry->head_count = 1; + devfs_compute_geometry_size(geometry, info->capacity, info->block_size); + geometry->device_type = info->device_type; geometry->removable = info->removable; diff --git a/src/add-ons/kernel/drivers/disk/scsi/scsi_disk/scsi_disk.cpp b/src/add-ons/kernel/drivers/disk/scsi/scsi_disk/scsi_disk.cpp index 0f2fe7f..655ffc3 100644 --- a/src/add-ons/kernel/drivers/disk/scsi/scsi_disk/scsi_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/scsi/scsi_disk/scsi_disk.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2008, Axel DÃrfler, axeld@xxxxxxxxxxxxxxxxx + * Copyright 2008-2012, Axel DÃrfler, axeld@xxxxxxxxxxxxxxxxx * Copyright 2002/03, Thomas Kurschel. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -20,6 +20,8 @@ #include <string.h> #include <stdlib.h> +#include <fs/devfs.h> + #include "dma_resources.h" #include "IORequest.h" #include "IOSchedulerSimple.h" @@ -65,7 +67,7 @@ static device_manager_info* sDeviceManager; static status_t -update_capacity(das_driver_info *device) +update_capacity(das_driver_info* device) { TRACE("update_capacity()\n"); @@ -88,20 +90,12 @@ get_geometry(das_handle* handle, device_geometry* geometry) das_driver_info* info = handle->info; status_t status = update_capacity(info); - if (status < B_OK) + if (status != B_OK) return status; - geometry->bytes_per_sector = info->block_size; - if (info->capacity > UINT_MAX) { - // TODO this doesn't work for capacity greater than 35TB - geometry->sectors_per_track = 256; - geometry->cylinder_count = info->capacity / (256 * 32); - geometry->head_count = 32; - } else { - geometry->sectors_per_track = 1; - geometry->cylinder_count = info->capacity; - geometry->head_count = 1; - } + + devfs_compute_geometry_size(geometry, info->capacity, info->block_size); + geometry->device_type = B_DISK; geometry->removable = info->removable; 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 70236c5..c5c82b1 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 @@ -1,18 +1,23 @@ /* - * Copyright 2008-2010, Haiku Inc. All rights reserved. + * Copyright 2008-2012, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Michael Lotz <mmlr@xxxxxxxx> */ + +#include "usb_disk.h" + #include <ByteOrder.h> -#include <KernelExport.h> #include <Drivers.h> -#include <malloc.h> + #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include "usb_disk.h" + +#include <fs/devfs.h> + #include "usb_disk_scsi.h" @@ -463,7 +468,7 @@ usb_disk_request_sense(device_lun *lun) TRACE_ALWAYS("request_sense: media changed\n"); lun->media_changed = true; lun->media_present = true; - + return B_DEV_MEDIA_CHANGED; } // fall through @@ -1058,17 +1063,17 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length) break; } - device_geometry *geometry = (device_geometry *)buffer; - geometry->bytes_per_sector = lun->block_size; - geometry->cylinder_count = lun->block_count; - geometry->sectors_per_track = geometry->head_count = 1; - geometry->device_type = lun->device_type; - geometry->removable = lun->removable; - geometry->read_only = lun->write_protected; - geometry->write_once = (lun->device_type == B_WORM); + device_geometry geometry; + devfs_compute_geometry_size(&geometry, lun->block_count, + lun->block_size); + + geometry.device_type = lun->device_type; + geometry.removable = lun->removable; + geometry.read_only = lun->write_protected; + geometry.write_once = lun->device_type == B_WORM; TRACE("B_GET_GEOMETRY: %ld sectors at %ld bytes per sector\n", - geometry->cylinder_count, geometry->bytes_per_sector); - result = B_OK; + geometry.cylinder_count, geometry.bytes_per_sector); + result = user_memcpy(buffer, &geometry, sizeof(device_geometry)); break; } diff --git a/src/system/kernel/device_manager/devfs.cpp b/src/system/kernel/device_manager/devfs.cpp index a1e0411..ba3a113 100644 --- a/src/system/kernel/device_manager/devfs.cpp +++ b/src/system/kernel/device_manager/devfs.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011, Axel DÃrfler, axeld@xxxxxxxxxxxxxxxxx + * Copyright 2002-2012, Axel DÃrfler, axeld@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -26,6 +26,7 @@ #include <debug.h> #include <elf.h> #include <FindDirectory.h> +#include <fs/devfs.h> #include <fs/KPath.h> #include <fs/node_monitor.h> #include <kdevice_manager.h> @@ -1498,17 +1499,16 @@ devfs_ioctl(fs_volume* _volume, fs_vnode* _vnode, void* _cookie, uint32 op, device_geometry geometry; status_t status = vnode->stream.u.dev.device->Control( cookie->device_cookie, op, &geometry, length); - if (status < B_OK) + if (status != B_OK) return status; // patch values to match partition size - geometry.sectors_per_track = 0; if (geometry.bytes_per_sector == 0) geometry.bytes_per_sector = 512; - geometry.sectors_per_track = partition->info.size - / geometry.bytes_per_sector; - geometry.head_count = 1; - geometry.cylinder_count = 1; + + devfs_compute_geometry_size(&geometry, + partition->info.size / geometry.bytes_per_sector, + geometry.bytes_per_sector); return user_memcpy(buffer, &geometry, sizeof(device_geometry)); } @@ -2207,6 +2207,21 @@ devfs_unpublish_device(BaseDevice* device, bool disconnect) } +void +devfs_compute_geometry_size(device_geometry* geometry, uint64 blockCount, + uint32 blockSize) +{ + if (blockCount > UINT32_MAX) + geometry->head_count = (blockCount + UINT32_MAX - 1) / UINT32_MAX; + else + geometry->head_count = 1; + + geometry->cylinder_count = 1; + geometry->sectors_per_track = blockCount / geometry->head_count; + geometry->bytes_per_sector = blockSize; +} + + // #pragma mark - support API for legacy drivers ############################################################################ Revision: hrev44684 Commit: adf340f0ed7fd0cd6c3d1a1313f54e8488fdeb6d URL: http://cgit.haiku-os.org/haiku/commit/?id=adf340f Author: Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> Date: Mon Oct 8 11:58:09 2012 UTC Style cleanup. ---------------------------------------------------------------------------- diff --git a/headers/private/kernel/fs/devfs.h b/headers/private/kernel/fs/devfs.h index 44db6e7..0cd4507 100644 --- a/headers/private/kernel/fs/devfs.h +++ b/headers/private/kernel/fs/devfs.h @@ -16,18 +16,18 @@ extern "C" { #endif -status_t devfs_unpublish_file_device(const char *path); -status_t devfs_publish_file_device(const char *path, const char *filePath); - -status_t devfs_unpublish_partition(const char *path); -status_t devfs_publish_partition(const char *name, const partition_info *info); -status_t devfs_rename_partition(const char *devicePath, const char *oldName, - const char *newName); - -status_t devfs_unpublish_device(const char *path, bool disconnect); -status_t devfs_publish_device(const char *path, device_hooks *calls); -status_t devfs_publish_directory(const char *path); -status_t devfs_rescan_driver(const char *driverName); +status_t devfs_unpublish_file_device(const char* path); +status_t devfs_publish_file_device(const char* path, const char* filePath); + +status_t devfs_unpublish_partition(const char* path); +status_t devfs_publish_partition(const char* name, const partition_info* info); +status_t devfs_rename_partition(const char* devicePath, const char* oldName, + const char* newName); + +status_t devfs_unpublish_device(const char* path, bool disconnect); +status_t devfs_publish_device(const char* path, device_hooks* calls); +status_t devfs_publish_directory(const char* path); +status_t devfs_rescan_driver(const char* driverName); void devfs_compute_geometry_size(device_geometry* geometry, uint64 blockCount, uint32 blockSize);