2 .\" Copyright (c) 1998 Kenneth D. Merry.
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. The name of the author may not be used to endorse or promote products
14 .\" derived from this software without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" $FreeBSD: src/lib/libcam/cam.3,v 1.5.2.6 2001/12/17 10:08:28 ru Exp $
29 .\" $DragonFly: src/lib/libcam/cam.3,v 1.3 2007/05/13 18:33:56 swildner Exp $
36 .Nm cam_open_spec_device ,
39 .Nm cam_close_device ,
40 .Nm cam_close_spec_device ,
54 .Ft struct cam_device *
56 .Fa "const char *path"
59 .Ft struct cam_device *
60 .Fo cam_open_spec_device
61 .Fa "const char *dev_name"
64 .Fa "struct cam_device *device"
66 .Ft struct cam_device *
68 .Fa "path_id_t path_id"
69 .Fa "target_id_t target_id"
70 .Fa "lun_id_t target_lun"
72 .Fa "struct cam_device *device"
74 .Ft struct cam_device *
76 .Fa "const char *path"
78 .Fa "struct cam_device *device"
82 .Fa "struct cam_device *dev"
85 .Fo cam_close_spec_device
86 .Fa "struct cam_device *dev"
90 .Fa "struct cam_device *dev"
94 .Fa "struct cam_device *device"
103 .Fa "struct cam_device *dev"
107 .Ft struct cam_device *
109 .Fa "struct cam_device *device"
113 .Fa "struct cam_device *src"
114 .Fa "struct cam_device *dst"
118 .Fa "const char *path"
124 The CAM library consists of a number of functions designed to aid in
125 programming with the CAM subsystem. This man page covers the basic set of
126 library functions. More functions are documented in the man pages listed
129 Many of the CAM library functions use the
134 char device_path[MAXPATHLEN+1];/*
136 * device given by the
140 * name and unit number
143 char given_dev_name[DEV_IDLEN+1];/*
144 * Device name given by
147 u_int32_t given_unit_number; /*
148 * Unit number given by
151 char device_name[DEV_IDLEN+1];/*
152 * Name of the device,
155 u_int32_t dev_unit_num; /* Unit number of the passthrough
156 * device associated with this
160 char sim_name[SIM_IDLEN+1];/*
161 * Controller name, e.g.'ahc'
163 u_int32_t sim_unit_number; /* Controller unit number */
164 u_int32_t bus_id; /* Controller bus number */
165 lun_id_t target_lun; /* Logical Unit Number */
166 target_id_t target_id; /* Target ID */
167 path_id_t path_id; /* System SCSI bus number */
168 u_int16_t pd_type; /* type of peripheral device */
169 struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */
170 u_int8_t serial_num[252]; /* device serial number */
171 u_int8_t serial_num_len; /* length of the serial number */
172 u_int8_t sync_period; /* Negotiated sync period */
173 u_int8_t sync_offset; /* Negotiated sync offset */
174 u_int8_t bus_width; /* Negotiated bus width */
175 int fd; /* file descriptor for device */
180 takes as arguments a string describing the device it is to open, and
182 suitable for passing to
184 The "path" passed in may actually be most any type of string that contains
185 a device name and unit number to be opened. The string will be parsed by
187 into a device name and unit number. Once the device name and unit number
188 are determined, a lookup is performed to determine the passthrough device
189 that corresponds to the given device.
191 is rather simple to use, but it isn't really suitable for general use
192 because its behavior isn't necessarily deterministic. Programmers writing
193 new applications should make the extra effort to use one of the other open
194 routines documented below.
196 .Fn cam_open_spec_device
199 device that corresponds to the device name and unit number passed in. The
201 should be flags suitable for passing to
205 argument is optional. The user may supply pre-allocated space for the
211 .Fn cam_open_spec_device
212 will allocate space for the
219 .Fn cam_open_spec_device ,
220 except that it takes a
222 bus, target and logical unit instead of a device name and unit number as
225 argument is the CAM equivalent of a
227 bus number. It represents the logical bus number in the system. The
229 should be flags suitable for passing to
232 .Fn cam_open_spec_device ,
235 argument is optional.
238 takes as an argument the
242 device to open. No translation or lookup is performed, so the path passed
243 in must be that of a CAM
247 should be flags suitable for passing to
252 .Fn cam_open_spec_device
255 should be NULL if the user wants the CAM library to allocate space for the
261 structure allocated by one of the above open() calls, and closes the file
262 descriptor to the passthrough device. This routine should not be called if
263 the user allocated space for the
265 structure. Instead, the user should call
266 .Fn cam_close_spec_device .
268 .Fn cam_close_spec_device
269 merely closes the file descriptor opened in one of the open() routines
270 described above. This function should be called when the
272 structure was allocated by the caller, rather than the CAM library.
278 and sets fields in the CCB header using values from the
292 frees CCBs allocated by
298 structure, and a string with length
300 It creates a colon-terminated printing prefix string similar to the ones
301 used by the kernel. e.g.: "(cd0:ahc1:0:4:0): ".
309 character will be the terminating
313 operates in a fashion similar to
315 It allocates space for a
317 structure and copies the contents of the passed-in
319 structure to the newly allocated structure.
330 argument containing a string with a device name followed by a unit number.
331 It then breaks the string down into a device name and unit number, and
338 can handle strings of the following forms, at least:
340 .Bl -tag -width 1234 -compact
349 is provided as a convenience function for applications that need to provide
350 functionality similar to
351 .Fn cam_open_device .
352 Programmers are encouraged to use more deterministic methods of obtaining
353 device names and unit numbers if possible.
355 .Fn cam_open_device ,
356 .Fn cam_open_spec_device ,
360 return a pointer to a
362 structure, or NULL if there was an error.
365 returns an allocated and partially initialized CCB, or NULL if allocation
369 returns a value of -1 if an error occurred, and
371 is set to indicate the error.
374 returns a filled printing prefix string as a convenience. This is the same
377 .Fn cam_path_string .
380 returns a copy of the
382 passed in, or NULL if an error occurred.
385 returns 0 for success, and -1 to indicate failure.
387 If an error is returned from one of the base CAM library functions
388 described here, the reason for the error is generally printed in the global
399 The CAM library first appeared in
402 .An Kenneth Merry Aq ken@FreeBSD.org
405 doesn't check to see if the
407 passed in is a symlink to something. It also doesn't check to see if the
409 passed in is an actual
411 device. The former would be rather easy to implement, but the latter would
412 require a definitive way to identify a device node as a
416 Some of the functions are possibly mis-named or poorly named.