vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / bus_managers / scsi / sim_interface.cpp
blob30b3fcc7fd2cb0dcc66869013b1a0feda8abdc1e
1 /*
2 * Copyright 2004-2008, Haiku, Inc. All RightsReserved.
3 * Copyright 2002/03, Thomas Kurschel. All rights reserved.
5 * Distributed under the terms of the MIT License.
6 */
8 /*
9 Controllers use this interface to interact with bus manager.
13 #include "scsi_internal.h"
14 #include "queuing.h"
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
21 /** new scsi controller added
22 * in return, we register a new scsi bus node and let its fixed
23 * consumer (the SCSI device layer) automatically scan it for devices
26 static status_t
27 scsi_controller_added(device_node *parent)
29 const char *controller_name;
30 int32 pathID;
32 SHOW_FLOW0(4, "");
34 if (pnp->get_attr_string(parent, SCSI_DESCRIPTION_CONTROLLER_NAME,
35 &controller_name, false) != B_OK) {
36 dprintf("scsi: ignored controller - controller name missing\n");
37 return B_ERROR;
40 pathID = pnp->create_id(SCSI_PATHID_GENERATOR);
41 if (pathID < 0) {
42 dprintf("scsi: Cannot register SCSI controller %s - out of path IDs\n",
43 controller_name);
44 return B_ERROR;
48 device_attr attrs[] = {
49 // remember who we are
50 // (could use the controller name, but probably some software would choke)
51 // TODO create_id() generates a 32 bit ranged integer but we need only 8 bits
52 { SCSI_BUS_PATH_ID_ITEM, B_UINT8_TYPE, { ui8: (uint8)pathID }},
54 // tell PnP manager to clean up ID
55 // { PNP_MANAGER_ID_GENERATOR, B_STRING_TYPE, { string: SCSI_PATHID_GENERATOR }},
56 // { PNP_MANAGER_AUTO_ID, B_UINT32_TYPE, { ui32: path_id }},
60 return pnp->register_node(parent, SCSI_BUS_MODULE_NAME, attrs, NULL,
61 NULL);
66 static status_t
67 scsi_controller_init(device_node *node, void **_cookie)
69 *_cookie = node;
70 return B_OK;
74 static status_t
75 scsi_controller_register_raw_device(void *_cookie)
77 device_node *node = (device_node *)_cookie;
78 uint32 channel;
79 uint8 pathID;
80 char *name;
82 #if 1
83 // TODO: this seems to cause a crash in some configurations, and needs to be investigated!
84 // see bug #389 and #393.
85 // TODO: check if the above is still true
86 if (pnp->get_attr_uint32(node, "ide/channel_id", &channel, true) == B_OK) {
87 // this is actually an IDE device, we don't need to publish
88 // a bus device for those
89 return B_OK;
91 #endif
92 pnp->get_attr_uint8(node, SCSI_BUS_PATH_ID_ITEM, &pathID, false);
94 // put that on heap to not overflow the limited kernel stack
95 name = (char*)malloc(PATH_MAX + 1);
96 if (name == NULL)
97 return B_NO_MEMORY;
99 snprintf(name, PATH_MAX + 1, "bus/scsi/%d/bus_raw", pathID);
101 return pnp->publish_device(node, name, SCSI_BUS_RAW_MODULE_NAME);
105 static status_t
106 std_ops(int32 op, ...)
108 switch (op) {
109 case B_MODULE_INIT:
110 case B_MODULE_UNINIT:
111 return B_OK;
113 default:
114 return B_ERROR;
119 scsi_for_sim_interface scsi_for_sim_module =
123 SCSI_FOR_SIM_MODULE_NAME,
125 std_ops
128 NULL, // supported devices
129 scsi_controller_added,
130 scsi_controller_init,
131 NULL, // uninit
132 scsi_controller_register_raw_device,
133 NULL, // rescan
134 NULL, // removed
137 scsi_requeue_request,
138 scsi_resubmit_request,
139 scsi_request_finished,
141 scsi_alloc_dpc,
142 scsi_free_dpc,
143 scsi_schedule_dpc,
145 scsi_block_bus,
146 scsi_unblock_bus,
147 scsi_block_device,
148 scsi_unblock_device,
150 scsi_cont_send_bus,
151 scsi_cont_send_device