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
This commit is contained in:
Scott Long 2016-04-13 20:10:06 +00:00
parent 5c40acf8b5
commit c9767ca834
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=297933
3 changed files with 47 additions and 25 deletions

View File

@ -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;
snprintf(res_string, len, "%02x %02x %02x %02x "
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)
{
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)
{

View File

@ -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);

View File

@ -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");
}