1 /* 2 * Copyright 2011, Haiku, Inc. All RightsReserved. 3 * Copyright 2002-03, Thomas Kurschel. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 //! Basic handling of file handles. 9 10 11 #include "scsi_periph_int.h" 12 13 #include <stdlib.h> 14 15 #include "dl_list.h" 16 17 18 status_t 19 periph_handle_open(scsi_periph_device_info *device, 20 periph_handle_cookie periph_handle, scsi_periph_handle_info **res_handle) 21 { 22 scsi_periph_handle_info *handle; 23 24 // SHOW_FLOW( 3, "device=%p", device ); 25 26 handle = (scsi_periph_handle_info *)malloc(sizeof(*handle)); 27 if (handle == NULL) 28 return B_NO_MEMORY; 29 30 handle->periph_handle = periph_handle; 31 handle->device = device; 32 handle->pending_error = B_OK; 33 34 mutex_lock(&device->mutex); 35 ADD_DL_LIST_HEAD(handle, device->handles, ); 36 mutex_unlock(&device->mutex); 37 38 *res_handle = handle; 39 40 // SHOW_FLOW( 3, "handle=%p", handle ); 41 42 return B_OK; 43 } 44 45 46 status_t 47 periph_handle_close(scsi_periph_handle_info *handle) 48 { 49 // SHOW_FLOW( 3, "handle=%p", handle ); 50 return B_OK; 51 } 52 53 54 status_t 55 periph_handle_free(scsi_periph_handle_info *handle) 56 { 57 scsi_periph_device_info *device = handle->device; 58 59 // SHOW_FLOW( 3, "handle=%p, device=%p", handle, handle->device ); 60 61 mutex_lock(&device->mutex); 62 REMOVE_DL_LIST(handle, device->handles, ); 63 mutex_unlock(&device->mutex); 64 65 free(handle); 66 67 // SHOW_FLOW0( 3, "done" ); 68 69 return B_OK; 70 } 71