Minor output buffer size related fixes
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Fri, 23 Oct 2009 11:52:32 +0000 (11:52 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Fri, 23 Oct 2009 11:52:32 +0000 (11:52 +0000)
git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@1257 d57e44dd-8a1f-0410-8b47-8ef2f437770f

iscsi-scst/kernel/conn.c
scst/include/scst_const.h
scst/src/dev_handlers/scst_user.c

index 583f3eb..67d0400 100644 (file)
 
 #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)
index 4cd87f1..011193e 100644 (file)
@@ -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 */
index 49860bd..75a3903 100644 (file)
@@ -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;
                        }
                }