From ac29495ceeb368c22526b38880cc7ad1cfaf231c Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 23 Oct 2009 11:52:32 +0000 Subject: [PATCH] Minor output buffer size related fixes git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1257 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/conn.c | 32 ++++++++++++++----------------- scst/include/scst_const.h | 2 +- scst/src/dev_handlers/scst_user.c | 5 +++-- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/iscsi-scst/kernel/conn.c b/iscsi-scst/kernel/conn.c index 583f3eb5c..67d040012 100644 --- a/iscsi-scst/kernel/conn.c +++ b/iscsi-scst/kernel/conn.c @@ -23,47 +23,43 @@ #ifdef CONFIG_SCST_PROC -static void print_conn_state(char *p, size_t size, struct iscsi_conn *conn) +static int print_conn_state(char *p, size_t size, struct iscsi_conn *conn) { - int printed = 0; + int pos = 0; if (conn->closing) { - snprintf(p, size, "%s", "closing"); - return; + pos += scnprintf(p, size, "%s", "closing"); + goto out; } switch (conn->rd_state) { case ISCSI_CONN_RD_STATE_PROCESSING: - size -= scnprintf(p, size, "%s", "read_processing "); - printed = 1; + pos += scnprintf(&p[pos], size - pos, "%s", "read_processing "); break; case ISCSI_CONN_RD_STATE_IN_LIST: - size -= scnprintf(p, size, "%s", "in_read_list "); - printed = 1; + pos += scnprintf(&p[pos], size - pos, "%s", "in_read_list "); break; } switch (conn->wr_state) { case ISCSI_CONN_WR_STATE_PROCESSING: - size -= scnprintf(p, size, "%s", "write_processing "); - printed = 1; + pos += scnprintf(&p[pos], size - pos, "%s", "write_processing "); break; case ISCSI_CONN_WR_STATE_IN_LIST: - size -= scnprintf(p, size, "%s", "in_write_list "); - printed = 1; + pos += scnprintf(&p[pos], size - pos, "%s", "in_write_list "); break; case ISCSI_CONN_WR_STATE_SPACE_WAIT: - size -= scnprintf(p, size, "%s", "space_waiting "); - printed = 1; + pos += scnprintf(&p[pos], size - pos, "%s", "space_waiting "); break; } if (test_bit(ISCSI_CONN_REINSTATING, &conn->conn_aflags)) - snprintf(p, size, "%s", "reinstating "); - else if (!printed) - snprintf(p, size, "%s", "established idle "); + pos += scnprintf(&p[pos], size - pos, "%s", "reinstating "); + else if (pos == 0) + pos += scnprintf(&p[pos], size - pos, "%s", "established idle "); - return; +out: + return pos; } static void print_digest_state(char *p, size_t size, unsigned long flags) diff --git a/scst/include/scst_const.h b/scst/include/scst_const.h index 4cd87f137..011193e42 100644 --- a/scst/include/scst_const.h +++ b/scst/include/scst_const.h @@ -339,6 +339,6 @@ enum scst_cmd_queue_type { /************************************************************* ** Misc constants *************************************************************/ -#define SCST_SYSFS_BLOCK_SIZE (PAGE_SIZE - 64) +#define SCST_SYSFS_BLOCK_SIZE PAGE_SIZE #endif /* __SCST_CONST_H */ diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 49860bd44..75a39030a 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -3411,9 +3411,10 @@ static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, atomic_read(&ucmd->ucmd_ref), ucmd->sent_to_user, ucmd->seen_by_user, ucmd->aborted, ucmd->jammed, ucmd->cmd); - if (pos >= SCST_SYSFS_BLOCK_SIZE) { - scnprintf(&buf[ppos], + if (pos >= SCST_SYSFS_BLOCK_SIZE-1) { + ppos += scnprintf(&buf[ppos], SCST_SYSFS_BLOCK_SIZE - ppos, "...\n"); + pos = ppos; break; } }