From owner-svn-src-all@freebsd.org Wed Apr 13 20:10:07 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E61A3B0FB27; Wed, 13 Apr 2016 20:10:07 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A78111445; Wed, 13 Apr 2016 20:10:07 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3DKA6sq075721; Wed, 13 Apr 2016 20:10:06 GMT (envelope-from scottl@FreeBSD.org) Received: (from scottl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3DKA6kW075718; Wed, 13 Apr 2016 20:10:06 GMT (envelope-from scottl@FreeBSD.org) Message-Id: <201604132010.u3DKA6kW075718@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottl set sender to scottl@FreeBSD.org using -f From: Scott Long Date: Wed, 13 Apr 2016 20:10:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297933 - in head/sys/cam: . ata X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Apr 2016 20:10:08 -0000 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"); }