Author: scottl
Date: Wed Apr 13 20:10:06 2016
New Revision: 297933
URL: https://svnweb.freebsd.org/changeset/base/297933

Log:
  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

Modified:
  head/sys/cam/ata/ata_all.c
  head/sys/cam/ata/ata_all.h
  head/sys/cam/cam.c

Modified: head/sys/cam/ata/ata_all.c
==============================================================================
--- head/sys/cam/ata/ata_all.c  Wed Apr 13 18:39:33 2016        (r297932)
+++ head/sys/cam/ata/ata_all.c  Wed Apr 13 20:10:06 2016        (r297933)
@@ -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
 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,
        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)
 {

Modified: head/sys/cam/ata/ata_all.h
==============================================================================
--- head/sys/cam/ata/ata_all.h  Wed Apr 13 18:39:33 2016        (r297932)
+++ head/sys/cam/ata/ata_all.h  Wed Apr 13 20:10:06 2016        (r297933)
@@ -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);

Modified: head/sys/cam/cam.c
==============================================================================
--- head/sys/cam/cam.c  Wed Apr 13 18:39:33 2016        (r297932)
+++ head/sys/cam/cam.c  Wed Apr 13 20:10:06 2016        (r297933)
@@ -412,7 +412,8 @@ cam_error_string(struct cam_device *devi
                        }
                        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");
                        }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to