summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-03-31 04:42:00 +0000
committerngie <ngie@FreeBSD.org>2017-03-31 04:42:00 +0000
commit788b91c13afa67207b7f647ae5e811ced51cb9e7 (patch)
tree19b950b7a098af190c9140d7d09b3cbee9ae37d2 /lib
parentbed0198a40aed70f37fd922323bf0e1f6f23a2d3 (diff)
downloadFreeBSD-src-788b91c13afa67207b7f647ae5e811ced51cb9e7.zip
FreeBSD-src-788b91c13afa67207b7f647ae5e811ced51cb9e7.tar.gz
MFC r316080,r316081,r316115:
r316080: Fix some localized style(9) issues and reword CAM_ERRBUF_SIZE description The CAM_ERRBUF_SIZE description rewording fixes a typo by proxy. r316081: Use `sizeof(cam_errbuf)` instead of `CAM_ERRBUF_SIZE` in snprintf calls Reindent snprintf calls' arguments to match style(9) guidelines with respect to indentation. r316115: libcam: use __func__ instead of hardcoding the function name as `func_name` Tested with: `cam_device_copy(NULL, NULL)` // ;)..
Diffstat (limited to 'lib')
-rw-r--r--lib/libcam/camlib.c167
-rw-r--r--lib/libcam/camlib.h4
2 files changed, 82 insertions, 89 deletions
diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c
index 89736e2..b87f5d2 100644
--- a/lib/libcam/camlib.c
+++ b/lib/libcam/camlib.c
@@ -114,16 +114,14 @@ cam_freeccb(union ccb *ccb)
int
cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
{
- char *func_name = "cam_get_device";
char *tmpstr, *tmpstr2;
char *newpath;
int unit_offset;
int i;
-
if (path == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: device pathname was NULL", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: device pathname was NULL", __func__);
return(-1);
}
@@ -145,8 +143,8 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
}
if (*tmpstr == '\0') {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: no text after slash", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: no text after slash", __func__);
free(newpath);
return(-1);
}
@@ -173,9 +171,9 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
* If we only have 1, we don't have a valid device name.
*/
if (strlen(tmpstr) < 2) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: must have both device name and unit number",
- func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: must have both device name and unit number",
+ __func__);
free(newpath);
return(-1);
}
@@ -185,9 +183,9 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
* has probably given us all numbers. Point out the error.
*/
if (isdigit(*tmpstr)) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: device name cannot begin with a number",
- func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: device name cannot begin with a number",
+ __func__);
free(newpath);
return(-1);
}
@@ -198,8 +196,8 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
* or he gave us a device name/number format we don't recognize.
*/
if (!isdigit(tmpstr[strlen(tmpstr) - 1])) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: unable to find device unit number", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: unable to find device unit number", __func__);
free(newpath);
return(-1);
}
@@ -271,13 +269,12 @@ cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
{
union ccb ccb;
struct periph_match_pattern *match_pat;
- char *func_name = "cam_open_btl";
int fd, bufsize;
if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: couldn't open %s\n%s: %s", func_name, XPT_DEVICE,
- func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: couldn't open %s\n%s: %s", __func__, XPT_DEVICE,
+ __func__, strerror(errno));
return(NULL);
}
@@ -292,8 +289,8 @@ cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
ccb.cdm.match_buf_len = bufsize;
ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
if (ccb.cdm.matches == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: couldn't malloc match buffer", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: couldn't malloc match buffer", __func__);
close(fd);
return(NULL);
}
@@ -305,8 +302,8 @@ cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
ccb.cdm.patterns = (struct dev_match_pattern *)malloc(
sizeof(struct dev_match_pattern));
if (ccb.cdm.patterns == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: couldn't malloc pattern buffer", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: couldn't malloc pattern buffer", __func__);
free(ccb.cdm.matches);
ccb.cdm.matches = NULL;
close(fd);
@@ -328,9 +325,9 @@ cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
PERIPH_MATCH_LUN | PERIPH_MATCH_NAME;
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: CAMIOCOMMAND ioctl failed\n"
- "%s: %s", func_name, func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: CAMIOCOMMAND ioctl failed\n"
+ "%s: %s", __func__, __func__, strerror(errno));
goto btl_bailout;
}
@@ -340,26 +337,26 @@ cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
if ((ccb.ccb_h.status != CAM_REQ_CMP)
|| ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
&& (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: CAM error %#x, CDM error %d "
- "returned from XPT_DEV_MATCH ccb", func_name,
- ccb.ccb_h.status, ccb.cdm.status);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: CAM error %#x, CDM error %d "
+ "returned from XPT_DEV_MATCH ccb", __func__,
+ ccb.ccb_h.status, ccb.cdm.status);
goto btl_bailout;
}
if (ccb.cdm.status == CAM_DEV_MATCH_MORE) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: CDM reported more than one"
- " passthrough device at %d:%d:%jx!!\n",
- func_name, path_id, target_id, (uintmax_t)target_lun);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: CDM reported more than one"
+ " passthrough device at %d:%d:%jx!!\n",
+ __func__, path_id, target_id, (uintmax_t)target_lun);
goto btl_bailout;
}
if (ccb.cdm.num_matches == 0) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: no passthrough device found at"
- " %d:%d:%jx", func_name, path_id, target_id,
- (uintmax_t)target_lun);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: no passthrough device found at"
+ " %d:%d:%jx", __func__, path_id, target_id,
+ (uintmax_t)target_lun);
goto btl_bailout;
}
@@ -382,9 +379,9 @@ cam_open_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun,
break; /* NOTREACHED */
}
default:
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: asked for a peripheral match, but"
- " got a bus or device match", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: asked for a peripheral match, but"
+ " got a bus or device match", __func__);
goto btl_bailout;
break; /* NOTREACHED */
}
@@ -418,7 +415,6 @@ cam_lookup_pass(const char *dev_name, int unit, int flags,
int fd;
union ccb ccb;
char dev_path[256];
- char *func_name = "cam_lookup_pass";
/*
* The flags argument above only applies to the actual passthrough
@@ -426,9 +422,9 @@ cam_lookup_pass(const char *dev_name, int unit, int flags,
* passthrough device.
*/
if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: couldn't open %s\n%s: %s", func_name, XPT_DEVICE,
- func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: couldn't open %s\n%s: %s", __func__, XPT_DEVICE,
+ __func__, strerror(errno));
return(NULL);
}
@@ -457,12 +453,12 @@ cam_lookup_pass(const char *dev_name, int unit, int flags,
snprintf(tmpstr, sizeof(tmpstr),
"\n%s: either the pass driver isn't in "
"your kernel\n%s: or %s%d doesn't exist",
- func_name, func_name, dev_name, unit);
+ __func__, __func__, dev_name, unit);
}
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: CAMGETPASSTHRU ioctl failed\n"
- "%s: %s%s", func_name, func_name, strerror(errno),
- (errno == ENOENT) ? tmpstr : "");
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: CAMGETPASSTHRU ioctl failed\n"
+ "%s: %s%s", __func__, __func__, strerror(errno),
+ (errno == ENOENT) ? tmpstr : "");
close(fd);
return(NULL);
@@ -477,9 +473,9 @@ cam_lookup_pass(const char *dev_name, int unit, int flags,
* the device the user gave us.
*/
if (ccb.cgdl.status == CAM_GDEVLIST_ERROR) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: device %s%d does not exist!",
- func_name, dev_name, unit);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: device %s%d does not exist!",
+ __func__, dev_name, unit);
return(NULL);
}
@@ -499,7 +495,6 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
const char *given_path, const char *given_dev_name,
int given_unit_number)
{
- char *func_name = "cam_real_open_device";
union ccb ccb;
int fd = -1, malloced_device = 0;
@@ -509,10 +504,10 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
if (device == NULL) {
if ((device = (struct cam_device *)malloc(
sizeof(struct cam_device))) == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: device structure malloc"
- " failed\n%s: %s", func_name, func_name,
- strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: device structure malloc"
+ " failed\n%s: %s", __func__, __func__,
+ strerror(errno));
return(NULL);
}
device->fd = -1;
@@ -540,10 +535,10 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
device->given_unit_number = given_unit_number;
if ((fd = open(path, flags)) < 0) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: couldn't open passthrough device %s\n"
- "%s: %s", func_name, path, func_name,
- strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: couldn't open passthrough device %s\n"
+ "%s: %s", __func__, path, __func__,
+ strerror(errno));
goto crod_bailout;
}
@@ -568,9 +563,9 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
* because we just opened it above. The only way this
* ioctl can fail is if the ccb size is wrong.
*/
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: CAMGETPASSTHRU ioctl failed\n"
- "%s: %s", func_name, func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: CAMGETPASSTHRU ioctl failed\n"
+ "%s: %s", __func__, __func__, strerror(errno));
goto crod_bailout;
}
@@ -581,8 +576,8 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
* the device the user gave us.
*/
if (ccb.cgdl.status == CAM_GDEVLIST_ERROR) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: passthrough device does not exist!", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: passthrough device does not exist!", __func__);
goto crod_bailout;
}
@@ -595,9 +590,9 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
ccb.ccb_h.func_code = XPT_PATH_INQ;
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: Path Inquiry CCB failed\n"
- "%s: %s", func_name, func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: Path Inquiry CCB failed\n"
+ "%s: %s", __func__, __func__, strerror(errno));
goto crod_bailout;
}
strlcpy(device->sim_name, ccb.cpi.dev_name, sizeof(device->sim_name));
@@ -610,9 +605,9 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
*/
ccb.ccb_h.func_code = XPT_GDEV_TYPE;
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: Get Device Type CCB failed\n"
- "%s: %s", func_name, func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: Get Device Type CCB failed\n"
+ "%s: %s", __func__, __func__, strerror(errno));
goto crod_bailout;
}
device->pd_type = SID_TYPE(&ccb.cgd.inq_data);
@@ -634,9 +629,9 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
ccb.cts.type = CTS_TYPE_CURRENT_SETTINGS;
if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: Get Transfer Settings CCB failed\n"
- "%s: %s", func_name, func_name, strerror(errno));
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: Get Transfer Settings CCB failed\n"
+ "%s: %s", __func__, __func__, strerror(errno));
goto crod_bailout;
}
if (ccb.cts.transport == XPORT_SPI) {
@@ -713,20 +708,19 @@ cam_path_string(struct cam_device *dev, char *str, int len)
struct cam_device *
cam_device_dup(struct cam_device *device)
{
- char *func_name = "cam_device_dup";
struct cam_device *newdev;
if (device == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: device is NULL", func_name);
- return(NULL);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: device is NULL", __func__);
+ return (NULL);
}
newdev = malloc(sizeof(struct cam_device));
if (newdev == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: couldn't malloc CAM device structure", func_name);
- return(NULL);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: couldn't malloc CAM device structure", __func__);
+ return (NULL);
}
bcopy(device, newdev, sizeof(struct cam_device));
@@ -740,17 +734,16 @@ cam_device_dup(struct cam_device *device)
void
cam_device_copy(struct cam_device *src, struct cam_device *dst)
{
- char *func_name = "cam_device_copy";
if (src == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: source device struct was NULL", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: source device struct was NULL", __func__);
return;
}
if (dst == NULL) {
- snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
- "%s: destination device struct was NULL", func_name);
+ snprintf(cam_errbuf, sizeof(cam_errbuf),
+ "%s: destination device struct was NULL", __func__);
return;
}
diff --git a/lib/libcam/camlib.h b/lib/libcam/camlib.h
index 4fa6a67..5c14740c 100644
--- a/lib/libcam/camlib.h
+++ b/lib/libcam/camlib.h
@@ -70,13 +70,13 @@
#include <cam/cam.h>
#include <cam/cam_ccb.h>
-#define CAM_ERRBUF_SIZE 2048 /* sizeof the CAM libarary error string */
+#define CAM_ERRBUF_SIZE 2048 /* CAM library error string size */
/*
* Right now we hard code the transport layer device, but this will change
* if we ever get more than one transport layer.
*/
-#define XPT_DEVICE "/dev/xpt0"
+#define XPT_DEVICE "/dev/xpt0"
extern char cam_errbuf[];
OpenPOWER on IntegriCloud