Author: scottl
Date: Sat Apr 16 05:14:55 2016
New Revision: 298100
URL: https://svnweb.freebsd.org/changeset/base/298100

Log:
  Partial MFC of r297933
  
  Add sbuf variants ata_cmd_sbuf()
  
  Sponsored by: Netflix

Modified:
  stable/10/sys/cam/ata/ata_all.c
  stable/10/sys/cam/ata/ata_all.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ata/ata_all.c
==============================================================================
--- stable/10/sys/cam/ata/ata_all.c     Sat Apr 16 04:17:47 2016        
(r298099)
+++ stable/10/sys/cam/ata/ata_all.c     Sat Apr 16 05:14:55 2016        
(r298100)
@@ -211,15 +211,31 @@ 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 *
@@ -233,7 +249,7 @@ ata_res_string(struct ata_res *res, char
            res->lba_low_exp, res->lba_mid_exp, res->lba_high_exp,
            res->sector_count, res->sector_count_exp);
 
-       return(res_string);
+       return (res_string);
 }
 
 /*
@@ -242,11 +258,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);
 }

Modified: stable/10/sys/cam/ata/ata_all.h
==============================================================================
--- stable/10/sys/cam/ata/ata_all.h     Sat Apr 16 04:17:47 2016        
(r298099)
+++ stable/10/sys/cam/ata/ata_all.h     Sat Apr 16 05:14:55 2016        
(r298100)
@@ -103,6 +103,7 @@ 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);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "[email protected]"

Reply via email to