CAM(3)
π CAM(3) β CAM user library, Library Functions Manual β¨
okay so welcome to the CAM(3) page, bestie. This is the CAM user library and weβre gonna make it make sense π
β¨ NAME β¨
cam_open_device, cam_open_spec_device, cam_open_btl, cam_open_pass, cam_close_device, cam_close_spec_device, cam_getccb, cam_send_ccb, cam_freeccb, cam_path_string, cam_device_dup, cam_device_copy, cam_get_device β CAM user library πΈ
π«Ά LIBRARY π«Ά
Common Access Method User Library (libcam, -lcam) π
π SYNOPSIS π
#include <stdio.h>
#include <camlib.h>
struct cam_device *
cam_open_device(const char *path, int flags);
struct cam_device *
cam_open_spec_device(const char *dev_name, int unit, int flags,
struct cam_device *device);
struct cam_device *
cam_open_btl(path_id_t path_id, target_id_t target_id,
lun_id_t target_lun, int flags, struct cam_device *device);
struct cam_device *
cam_open_pass(const char *path, int flags, struct cam_device *device);
void
cam_close_device(struct cam_device *dev);
void
cam_close_spec_device(struct cam_device *dev);
union ccb *
cam_getccb(struct cam_device *dev);
int
cam_send_ccb(struct cam_device *device, union ccb *ccb);
void
cam_freeccb(union ccb *ccb);
char *
cam_path_string(struct cam_device *dev, char *str, int len);
struct cam_device *
cam_device_dup(struct cam_device *device);
void
cam_device_copy(struct cam_device *src, struct cam_device *dst);
int
cam_get_device(const char *path, char *dev_name, int devnamelen,
int *unit);
π¦ DESCRIPTION π¦
The CAM library consists of a number of functions designed to aid in programming with the CAM subsystem described in cam(4). This man page covers the basic set of library functions. More functions are documented in the man pages listed below.
Many of the CAM library functions use the cam_device structure. Here it is in all its iconic detail:
struct cam_device {
char device_path[MAXPATHLEN+1];/*
* Pathname of the
* device given by the
* user. This may be
* null if the user
* states the device
* name and unit number
* separately.
*/
char given_dev_name[DEV_IDLEN+1];/*
* Device name given by
* the user.
*/
uint32_t given_unit_number; /*
* Unit number given by
* the user.
*/
char device_name[DEV_IDLEN+1];/*
* Name of the device,
* e.g., 'pass'
*/
uint32_t dev_unit_num; /* Unit number of the passthrough
* device associated with this
* particular device.
*/
char sim_name[SIM_IDLEN+1];/*
* Controller name, e.g., 'ahc'
*/
uint32_t sim_unit_number; /* Controller unit number */
uint32_t bus_id; /* Controller bus number */
lun_id_t target_lun; /* Logical Unit Number */
target_id_t target_id; /* Target ID */
path_id_t path_id; /* System SCSI bus number */
uint16_t pd_type; /* type of peripheral device */
struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */
uint8_t serial_num[252]; /* device serial number */
uint8_t serial_num_len; /* length of the serial number */
uint8_t sync_period; /* Negotiated sync period */
uint8_t sync_offset; /* Negotiated sync offset */
uint8_t bus_width; /* Negotiated bus width */
int fd; /* file descriptor for device */
};
cam_open_device()β takes as arguments a string describing the device it is to open, and flags suitable for passing toopen(2). Thepathpassed in may actually be most any type of string that contains a device name and unit number to be opened. The string will be parsed bycam_get_device()into a device name and unit number. Once the device name and unit number are determined, a lookup is performed to determine the passthrough device that corresponds to the given device. π«Άcam_open_spec_device()β opens thepass(4)device that corresponds to the device name and unit number passed in. The flags should be flags suitable for passing toopen(2). Thedeviceargument is optional. The user may supply pre-allocated space for thecam_devicestructure. If thedeviceargument isNULL,cam_open_spec_device()will allocate space for thecam_devicestructure usingmalloc(3). β¨cam_open_btl()β is similar tocam_open_spec_device(), except that it takes a SCSI bus, target and logical unit instead of a device name and unit number as arguments. Thepath_idargument is the CAM equivalent of a SCSI bus number. It represents the logical bus number in the system. The flags should be flags suitable for passing toopen(2). As withcam_open_spec_device(), thedeviceargument is optional. π¦cam_open_pass()β takes as an argument the path of apass(4)device to open. No translation or lookup is performed, so the path passed in must be that of a CAMpass(4)device. The flags should be flags suitable for passing toopen(2). Thedeviceargument, as withcam_open_spec_device()andcam_open_btl(), should beNULLif the user wants the CAM library to allocate space for thecam_devicestructure. πcam_close_device()β frees thecam_devicestructure allocated by one of the aboveopen(2)calls, and closes the file descriptor to the passthrough device. This routine should not be called if the user allocated space for thecam_devicestructure. Instead, the user should callcam_close_spec_device(). πcam_close_spec_device()β merely closes the file descriptor opened in one of theopen(2)routines described above. This function should be called when thecam_devicestructure was allocated by the caller, rather than the CAM library. πcam_getccb()β allocates a prezeroed CCB usingcalloc(3)and sets fields in the CCB header using values from thecam_devicestructure. π₯cam_send_ccb()β sends the givenccbto the device described in thecam_devicestructure. πcam_freeccb()β frees CCBs allocated bycam_getccb(). IfccbisNULL, no action is taken. π§cam_path_string()β takes as arguments acam_devicestructure, and a string with lengthlen. It creates a colon-terminated printing prefix string similar to the ones used by the kernel. e.g.:"(cd0:ahc1:0:4:0): ".cam_path_string()will place at mostlen-1characters intostr. Thelen'th character will be the terminating'\0'. πΈcam_device_dup()β operates in a fashion similar tostrdup(3). It allocates space for acam_devicestructure and copies the contents of the passed-indevicestructure to the newly allocated structure. πcam_device_copy()β copies thesrcstructure todst. π«Άcam_get_device()β takes apathargument containing a string with a device name followed by a unit number. It then breaks the string down into a device name and unit number, and passes them back indev_nameandunit, respectively.cam_get_device()can handle strings of the following forms, at least:
/dev/foo1
foo0
nsa2
cam_get_device() is provided as a convenience function for applications that need to provide functionality similar to cam_open_device(). β¨
π RETURN VALUES π
cam_open_device(),cam_open_spec_device(),cam_open_btl(), andcam_open_pass()β return a pointer to acam_devicestructure, orNULLif there was an error. πcam_getccb()β returns an allocated and partially initialized CCB, orNULLif allocation of the CCB failed. πcam_send_ccb()β returns a value of-1if an error occurred, anderrnois set to indicate the error. πcam_path_string()β returns a filled printing prefix string as a convenience. This is the samestrthat is passed intocam_path_string(). πcam_device_dup()β returns a copy of the device passed in, orNULLif an error occurred. π¦cam_get_device()β returns0for success, and-1to indicate failure. β¨
If an error is returned from one of the base CAM library functions described here, the reason for the error is generally printed in the global string cam_errbuf which is CAM_ERRBUF_SIZE characters long. π«Ά
π SEE ALSO π
cam_cdbparse(3), pass(4), camcontrol(8) π
π°οΈ HISTORY π°οΈ
The CAM library first appeared in FreeBSD 3.0. β
πΈ AUTHORS πΈ
Kenneth Merry <ken@FreeBSD.org> π
π BUGS π
cam_open_device() does not check to see if the path passed in is a symlink to something. It also does not check to see if the path passed in is an actual pass(4) device. The former would be rather easy to implement, but the latter would require a definitive way to identify a device node as a pass(4) device. π¬
Some of the functions are possibly misnamed or poorly named. π
π Thatβs the whole page, bestie β Debian, June 1, 2023, CAM(3). Mwah π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1998 Kenneth D. Merry
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms