summaryrefslogtreecommitdiffstats
path: root/sys/cam
diff options
context:
space:
mode:
authorscottl <scottl@FreeBSD.org>2016-04-13 20:10:06 +0000
committerscottl <scottl@FreeBSD.org>2016-04-13 20:10:06 +0000
commit82742760bc949bcbaaceb50975543e111cfd8ffb (patch)
tree5d04f1fb4324437f4ab86f99c405db9f89668e12 /sys/cam
parentc9795129dffbe44689041ad4306fac1e7f082039 (diff)
downloadFreeBSD-src-82742760bc949bcbaaceb50975543e111cfd8ffb.zip
FreeBSD-src-82742760bc949bcbaaceb50975543e111cfd8ffb.tar.gz
Add sbuf variants ata_cmd_sbuf() and ata_res_sbuf(), and reimplement the
_string variants on top of this. This requires a change to the function signature of ata_res_sbuf(). Its use in the tree seems to be very limited, and the change makes it more consistent with the rest of the API. Reviewed by: imp, mav, kenm Sponsored by: Netflix Differential Revision: D5940
Diffstat (limited to 'sys/cam')
-rw-r--r--sys/cam/ata/ata_all.c66
-rw-r--r--sys/cam/ata/ata_all.h3
-rw-r--r--sys/cam/cam.c3
3 files changed, 47 insertions, 25 deletions
diff --git a/sys/cam/ata/ata_all.c b/sys/cam/ata/ata_all.c
index d5220e8..51231b7 100644
--- a/sys/cam/ata/ata_all.c
+++ b/sys/cam/ata/ata_all.c
@@ -211,29 +211,64 @@ ata_op_string(struct ata_cmd *cmd)
char *
ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len)
{
+ struct sbuf sb;
+ int error;
- snprintf(cmd_string, len, "%02x %02x %02x %02x "
+ if (len == 0)
+ return ("");
+
+ sbuf_new(&sb, cmd_string, len, SBUF_FIXEDLEN);
+ ata_cmd_sbuf(cmd, &sb);
+
+ error = sbuf_finish(&sb);
+ if (error != 0 && error != ENOMEM)
+ return ("");
+
+ return(sbuf_data(&sb));
+}
+
+void
+ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb)
+{
+ sbuf_printf(sb, "%02x %02x %02x %02x "
"%02x %02x %02x %02x %02x %02x %02x %02x",
cmd->command, cmd->features,
cmd->lba_low, cmd->lba_mid, cmd->lba_high, cmd->device,
cmd->lba_low_exp, cmd->lba_mid_exp, cmd->lba_high_exp,
cmd->features_exp, cmd->sector_count, cmd->sector_count_exp);
-
- return(cmd_string);
}
char *
ata_res_string(struct ata_res *res, char *res_string, size_t len)
{
+ struct sbuf sb;
+ int error;
+
+ if (len == 0)
+ return ("");
+
+ sbuf_new(&sb, res_string, len, SBUF_FIXEDLEN);
+ ata_res_sbuf(res, &sb);
+
+ error = sbuf_finish(&sb);
+ if (error != 0 && error != ENOMEM)
+ return ("");
+
+ return(sbuf_data(&sb));
+}
+
+int
+ata_res_sbuf(struct ata_res *res, struct sbuf *sb)
+{
- snprintf(res_string, len, "%02x %02x %02x %02x "
+ sbuf_printf(sb, "%02x %02x %02x %02x "
"%02x %02x %02x %02x %02x %02x %02x",
res->status, res->error,
res->lba_low, res->lba_mid, res->lba_high, res->device,
res->lba_low_exp, res->lba_mid_exp, res->lba_high_exp,
res->sector_count, res->sector_count_exp);
- return(res_string);
+ return (0);
}
/*
@@ -242,11 +277,10 @@ ata_res_string(struct ata_res *res, char *res_string, size_t len)
int
ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
{
- char cmd_str[(12 * 3) + 1];
- sbuf_printf(sb, "%s. ACB: %s",
- ata_op_string(&ataio->cmd),
- ata_cmd_string(&ataio->cmd, cmd_str, sizeof(cmd_str)));
+ sbuf_printf(sb, "%s. ACB: ",
+ ata_op_string(&ataio->cmd));
+ ata_cmd_sbuf(&ataio->cmd, sb);
return(0);
}
@@ -284,20 +318,6 @@ ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
return(0);
}
-/*
- * ata_res_sbuf() returns 0 for success and -1 for failure.
- */
-int
-ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb)
-{
- char res_str[(11 * 3) + 1];
-
- sbuf_printf(sb, "RES: %s",
- ata_res_string(&ataio->res, res_str, sizeof(res_str)));
-
- return(0);
-}
-
void
ata_print_ident(struct ata_params *ident_data)
{
diff --git a/sys/cam/ata/ata_all.h b/sys/cam/ata/ata_all.h
index 91e941c..433c61c 100644
--- a/sys/cam/ata/ata_all.h
+++ b/sys/cam/ata/ata_all.h
@@ -103,10 +103,11 @@ int ata_version(int ver);
char * ata_op_string(struct ata_cmd *cmd);
char * ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
+void ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb);
char * ata_res_string(struct ata_res *res, char *res_string, size_t len);
int ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
int ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
-int ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
+int ata_res_sbuf(struct ata_res *res, struct sbuf *sb);
void ata_print_ident(struct ata_params *ident_data);
void ata_print_ident_short(struct ata_params *ident_data);
diff --git a/sys/cam/cam.c b/sys/cam/cam.c
index 1f627ef..5061dd6 100644
--- a/sys/cam/cam.c
+++ b/sys/cam/cam.c
@@ -412,7 +412,8 @@ cam_error_string(struct cam_device *device, union ccb *ccb, char *str,
}
if (proto_flags & CAM_EAF_PRINT_RESULT) {
sbuf_cat(&sb, path_str);
- ata_res_sbuf(&ccb->ataio, &sb);
+ sbuf_printf(&sb, "RES: ");
+ ata_res_sbuf(&ccb->ataio.res, &sb);
sbuf_printf(&sb, "\n");
}
OpenPOWER on IntegriCloud