cmdfilter: clean up sysfs interface
Subsystems (2)
PATCH 1/1 cmdfilter: clean up sysfs interface
This patch adds the user interface as discussed in the "cmd filter fixes" thread.
This patch depends on the cmdfilter fixes sent by Fujita.
I have done tests with this patch ontop of his patchset and everything works as expected.
--------------
This patch changes the interface of the cmd filter to use a +/- notation like echo -- +0x02 +0x03 -0x08 .
If neither + or - is given it defaults to + (allow command).
Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
block/cmd-filter.c | 45 +++++++++++++++++++++++++--------------------
1 files changed, 25 insertions(+), 20 deletions(-)
block/cmd-filter.c +0 -0
@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct
blk_scsi_cmd_filter *filter, char *page,
for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
if (test_bit(i, okbits)) {
- sprintf(npage, "%02x", i);
- npage += 2;
+ sprintf(npage, "0x%02x", i);
+ npage += 4;
if (i < BLK_SCSI_MAX_CMDS - 1)
sprintf(npage++, " ");
}
@@ -111,33 +111,38 @@ static ssize_t rcf_writecmds_show(struct blk_scsi_cmd_filter *filter,
static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter,
const char *page, size_t count, int rw)
{
- ssize_t ret = 0;
- unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
- int cmd, status, len;
+ unsigned long *target_okbits;
+ int cmd, status, set;
substring_t ss;
+ char *p;
- memset(&okbits, 0, sizeof(okbits));
+ if (rw == READ)
+ target_okbits = filter->read_ok;
+ else
+ target_okbits = filter->write_ok;
+
+ while ((p = strsep(&page, " ")) != NULL) {
+ set = 1;
+
+ if (p[0] == '-') {
+ set = 0;
+ p++;
+ }
- for (len = strlen(page); len > 0; len -= 3) {
- if (len < 2)
- break;
- ss.from = (char *) page + ret;
- ss.to = (char *) page + ret + 2;
- ret += 3;
+ if (p[0] == '+')
+ p++;
+ ss.from = (char *) p;
+ ss.to = (char *) p + 4;
status = match_hex(&ss, &cmd);
/* either of these cases means invalid input, so do nothing. */ if (status || cmd >= BLK_SCSI_MAX_CMDS)
return -EINVAL;
-
- __set_bit(cmd, okbits);
+ if (set)
+ set_bit(cmd, target_okbits);
+ else
+ clear_bit(cmd, target_okbits);
}
- if (rw == READ)
- target_okbits = filter->read_ok;
- else
- target_okbits = filter->write_ok;
-
- memmove(target_okbits, okbits, sizeof(okbits));
return count;
}
PATCH v2 1/1 cmdfilter: clean up sysfs interface
vs fix error handling and compiler warnings
----------------
This patch changes the interface of the cmd filter to use a +/- notation like echo -- +0x02 +0x03 -0x08 .
If neither + or - is given it defaults to + (allow command).
Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
block/cmd-filter.c | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-)
block/cmd-filter.c +0 -0
@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct
blk_scsi_cmd_filter *filter, char *page,
for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
if (test_bit(i, okbits)) {
- sprintf(npage, "%02x", i);
- npage += 2;
+ sprintf(npage, "0x%02x", i);
+ npage += 4;
if (i < BLK_SCSI_MAX_CMDS - 1)
sprintf(npage++, " ");
}
@@ -111,32 +111,42 @@ static ssize_t rcf_writecmds_show(struct blk_scsi_cmd_filter *filter,
static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter,
const char *page, size_t count, int rw)
{
- ssize_t ret = 0;
unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
- int cmd, status, len;
+ int cmd, status, set;
substring_t ss;
+ char *p;
- memset(&okbits, 0, sizeof(okbits));
+ if (rw == READ) {
+ memcpy(&okbits, filter->read_ok, sizeof(okbits));
+ target_okbits = filter->read_ok;
+ } else {
+ memcpy(&okbits, filter->write_ok, sizeof(okbits));
+ target_okbits = filter->write_ok;
+ }
+
+ while ((p = strsep((char **)&page, " ")) != NULL) {
+ set = 1;
+
+ if (p[0] == '-') {
+ set = 0;
+ p++;
+ }
- for (len = strlen(page); len > 0; len -= 3) {
- if (len < 2)
- break;
- ss.from = (char *) page + ret;
- ss.to = (char *) page + ret + 2;
- ret += 3;
+ if (p[0] == '+')
+ p++;
+ ss.from = (char *) p;
+ ss.to = (char *) p + 4;
status = match_hex(&ss, &cmd);
/* either of these cases means invalid input, so do nothing. */ if (status || cmd >= BLK_SCSI_MAX_CMDS)
return -EINVAL;
- __set_bit(cmd, okbits);
+ if (set)
+ __set_bit(cmd, okbits);
+ else
+ __clear_bit(cmd, okbits);
}
- if (rw == READ)
- target_okbits = filter->read_ok;
- else
- target_okbits = filter->write_ok;
-
memmove(target_okbits, okbits, sizeof(okbits)); return count;
}
Quoted 21 lines · On Sat, 2 Aug 2008 17:19:18 +0200 "Adel Gadllah" <[email protected]> wrote:
vs fix error handling and compiler warnings
----------------
This patch changes the interface of the cmd filter to use a +/- notation like echo -- +0x02 +0x03 -0x08 .
If neither + or - is given it defaults to + (allow command).Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
Quoted 2 lines
block/cmd-filter.c | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-)
The patch is corrupted?
fujita@viola:~/git/linux-2.6$ patch -p1 < /home/fujita/Mail/kernel/scsi/1494 patching file block/cmd-filter.c patch: **** malformed patch at line 92: blk_scsi_cmd_filter *filter, char *page,
Quoted 46 lines
block/cmd-filter.c +2
-2@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {if (test_bit (i, okbits)) { -sprintf (npage,"%02x" , i); - npage +=2 ; +sprintf (npage,"0x%02x" , i); + npage +=4 ;if (i <BLK_SCSI_MAX_CMDS -1 )sprintf (npage++," " );block/cmd-filter.c +17
-4}@@ -111,32 +111,42 @@ static ssize_t rcf_writecmds_show(structblk_scsi_cmd_filter *filter, static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter, const char *page, size_t count, int rw) { - ssize_t ret = 0; unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; -int cmd, status, len; +int cmd, status, set;substring_t ss; +char *p; -memset (&okbits,0 ,sizeof (okbits)); +if (rw ==READ ) { +memcpy (&okbits, filter->read_ok,sizeof (okbits)); + target_okbits = filter->read_ok; + }else { +memcpy (&okbits, filter->write_ok,sizeof (okbits)); + target_okbits = filter->write_ok; + } + +while ((p =strsep ((char **)&page," " )) !=NULL ) { + set =1 ; + +if (p[0 ] =='-' ) { + set =0 ; + p++; + } -for (len =strlen (page); len >0 ; len -=3 ) {
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 140
Quoted 10 lines
block/cmd-filter.c +4
-5-if (len <2 ) -break ; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret +2 ; - ret +=3 ; +if (p[0 ] =='+' ) + p++; + ss.from = (char *) p; + ss.to = (char *) p +4 ; status =match_hex (&ss, &cmd);
how about using simple_strtol here? It can handle an value too.
strchr(str, ' ') would make the intention clear here rather than using '4' ?
2008/8/8 FUJITA Tomonori <[email protected]>:
Quoted 24 lines
Quoted 21 lines · On Sat, 2 Aug 2008 17:19:18 +0200 "Adel Gadllah" <[email protected]> wrote:
vs fix error handling and compiler warnings
----------------
This patch changes the interface of the cmd filter to use a +/- notation like echo -- +0x02 +0x03 -0x08 .
If neither + or - is given it defaults to + (allow command).Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
Quoted 8 lines
Quoted 2 lines
block/cmd-filter.c | 44 +++++++++++++++++++++++++++----------------- 1 files changed, 27 insertions(+), 17 deletions(-)The patch is corrupted?
fujita@viola:~/git/linux-2.6$ patch -p1 < /home/fujita/Mail/kernel/scsi/1494 patching file block/cmd-filter.c patch: **** malformed patch at line 92: blk_scsi_cmd_filter *filter, char *page,
argh... stupid gmail will resend once I am home. (ie. later today)
Quoted 45 lines
Quoted 45 lines
block/cmd-filter.c +2
-2@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {if (test_bit (i, okbits)) { -sprintf (npage,"%02x" , i); - npage +=2 ; +sprintf (npage,"0x%02x" , i); + npage +=4 ;if (i <BLK_SCSI_MAX_CMDS -1 )sprintf (npage++," " );}block/cmd-filter.c +17
-3@@ -111,32 +111,42 @@ static ssize_t rcf_writecmds_show(structblk_scsi_cmd_filter *filter, static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter, const char *page, size_t count, int rw) { - ssize_t ret = 0; unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; -int cmd, status, len; +int cmd, status, set;substring_t ss; +char *p; -memset (&okbits,0 ,sizeof (okbits)); +if (rw ==READ ) { +memcpy (&okbits, filter->read_ok,sizeof (okbits)); + target_okbits = filter->read_ok; + }else { +memcpy (&okbits, filter->write_ok,sizeof (okbits)); + target_okbits = filter->write_ok; + } + +while ((p =strsep ((char **)&page," " )) !=NULL ) { + set =1 ; + +if (p[0 ] =='-' ) { + set =0 ; + p++; + }
Quoted 13 lines
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 140
Quoted 11 lines
block/cmd-filter.c +4
-6-for (len =strlen (page); len >0 ; len -=3 ) { -if (len <2 ) -break ; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret +2 ; - ret +=3 ; +if (p[0 ] =='+' ) + p++; + ss.from = (char *) p; + ss.to = (char *) p +4 ; status =match_hex (&ss, &cmd);how about using
simple_strtolhere? It can handle an value too.
by value you mean a non hex input?
Quoted 2 lines
strchr(str, ' ')would make the intention clear here rather than using '4' ?
yeah will do that
Quoted 20 lines · On Fri, 8 Aug 2008 09:47:44 +0200 "Adel Gadllah" <[email protected]> wrote:
Quoted 20 lines
Quoted 19 lines
(quoted diff) +11
-6+ while ((p = strsep((char **)&page, " ")) != NULL) { + set = 1; + + if (p[0] == '-') { + set = 0; + p++; + } - for (len = strlen(page); len > 0; len -= 3) { - if (len < 2) - break; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret + 2; - ret += 3; + if (p[0] == '+') + p++; + ss.from = (char *) p; + ss.to = (char *) p + 4; status = match_hex(&ss, &cmd);
Quoted 3 lines
Quoted 1 line
how about using
simple_strtolhere? It can handle an value too.by value you mean a non hex input?
Oops, "it can handle a sign" But I found that simple_strtol can't handle '+' though glibc strtol can. Please ignore this comment.
After looking at the string helper functions, here are some new comments:
o match_hex just uses simple_strtol internally. So I don't think that we need it here. we can simply use simple_strtol.
o simple_strtol can handle '-' sign. So we don't need:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+ if (p[0] == '-') { + set = 0; + p++; + }
Quoted 4 lines · On Fri, 8 Aug 2008 09:47:44 +0200 "Adel Gadllah" <[email protected]> wrote:
Quoted 2 lines
strchr(str, ' ')would make the intention clear here rather than using '4' ?yeah will do that
Actually you don't need strchr here. You can just use simple_strtol.
2008/8/8 FUJITA Tomonori <[email protected]>:
Quoted 10 lines
Quoted 4 lines · On Fri, 8 Aug 2008 09:47:44 +0200 "Adel Gadllah" <[email protected]> wrote:
Quoted 2 lines
strchr(str, ' ')would make the intention clear here rather than using '4' ?yeah will do that
Actually you don't need strchr here. You can just use
simple_strtol.
yeah that makes sense.
PATCH v3 1/1 cmdfilter: clean up sysfs interface
v3 clean up parsing.
-----------------------------------
This patch changes the interface of the cmd filter to use a +/- notation like:
echo -- +0x02 +0x03 -0x08
If neither + or - is given it defaults to + (allow command).
Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
block/cmd-filter.c | 53 ++++++++++++++++++++++++++++++--------------------- 1 files changed, 31 insertions(+), 22 deletions(-)
block/cmd-filter.c +0 -0
@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct
blk_scsi_cmd_filter *filter, char *page,
for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
if (test_bit(i, okbits)) {
- sprintf(npage, "%02x", i);
- npage += 2;
+ sprintf(npage, "0x%02x", i);
+ npage += 4;
if (i < BLK_SCSI_MAX_CMDS - 1)
sprintf(npage++, " ");
}
@@ -111,32 +111,41 @@ static ssize_t rcf_writecmds_show(struct blk_scsi_cmd_filter *filter,
static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter,
const char *page, size_t count, int rw)
{
- ssize_t ret = 0;
unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
- int cmd, status, len;
- substring_t ss;
-
- memset(&okbits, 0, sizeof(okbits));
-
- for (len = strlen(page); len > 0; len -= 3) {
- if (len < 2)
- break;
- ss.from = (char *) page + ret;
- ss.to = (char *) page + ret + 2;
- ret += 3;
- status = match_hex(&ss, &cmd);
+ int cmd, set;
+ char *p, *status;
+
+ if (rw == READ) {
+ memcpy(&okbits, filter->read_ok, sizeof(okbits));
+ target_okbits = filter->read_ok;
+ } else {
+ memcpy(&okbits, filter->write_ok, sizeof(okbits));
+ target_okbits = filter->write_ok;
+ }
+
+ while ((p = strsep((char **)&page, " ")) != NULL) {
+ set = 1;
+
+ if (p[0] == '-') {
+ set = 0;
+ p++;
+ }
+
+ if (p[0] == '+')
+ p++;
+
+ cmd = simple_strtol(p, &status, 16);
+
/* either of these cases means invalid input, so do nothing. */
- if (status || cmd >= BLK_SCSI_MAX_CMDS)
+ if ((status == p) || cmd >= BLK_SCSI_MAX_CMDS)
return -EINVAL;
- __set_bit(cmd, okbits);
+ if (set)
+ __set_bit(cmd, okbits);
+ else
+ __clear_bit(cmd, okbits);
}
- if (rw == READ)
- target_okbits = filter->read_ok;
- else
- target_okbits = filter->write_ok;
-
memmove(target_okbits, okbits, sizeof(okbits)); return count;
}
Quoted 21 lines · On Fri, 8 Aug 2008 20:46:55 +0200 "Adel Gadllah" <[email protected]> wrote:
v3 clean up parsing.
-----------------------------------
This patch changes the interface of the cmd filter to use a +/- notation like:
echo -- +0x02 +0x03 -0x08
If neither + or - is given it defaults to + (allow command).Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
Quoted 2 lines
block/cmd-filter.c | 53 ++++++++++++++++++++++++++++++--------------------- 1 files changed, 31 insertions(+), 22 deletions(-)
Hmm, the patch seems to be corrupted again.
block/cmd-filter.c
Quoted 4 lines
block/cmd-filter.c +0
-0
I think that you can remove "linux/parser.h".
Quoted 31 lines
block/cmd-filter.c +2
-2@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {if (test_bit (i, okbits)) { -sprintf (npage,"%02x" , i); - npage +=2 ; +sprintf (npage,"0x%02x" , i); + npage +=4 ;if (i <BLK_SCSI_MAX_CMDS -1 )sprintf (npage++," " );block/cmd-filter.c +0
-13}@@ -111,32 +111,41 @@ static ssize_t rcf_writecmds_show(structblk_scsi_cmd_filter *filter, static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter, const char *page, size_t count, int rw) { - ssize_t ret = 0; unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; -int cmd, status, len; -substring_t ss; - -memset (&okbits,0 ,sizeof (okbits)); - -for (len =strlen (page); len >0 ; len -=3 ) { -if (len <2 ) -break ; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret +2 ; - ret +=3 ; - status =match_hex (&ss, &cmd);
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 125
Quoted 10 lines
block/cmd-filter.c +10
-0+int cmd, set; +char *p, *status; + +if (rw ==READ ) { +memcpy (&okbits, filter->read_ok,sizeof (okbits)); + target_okbits = filter->read_ok; + }else { +memcpy (&okbits, filter->write_ok,sizeof (okbits)); + target_okbits = filter->write_ok; + }
Do we need this? We can modify filter->write_ok or filter->read_ok directly?
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 132
Quoted 7 lines
block/cmd-filter.c +7
-0+while ((p =strsep ((char **)&page," " )) !=NULL ) { + set =1 ; + +if (p[0 ] =='-' ) { + set =0 ; + p++; + }
As I wrote, I prefer to let simple_strtol to handle '-' though the current code is also fine by me.
Quoted 14 lines
block/cmd-filter.c +9
-2+if (p[0 ] =='+' ) + p++; + + cmd =simple_strtol (p, &status,16 ); +/* either of these cases means invalid input, so do nothing. */ -if (status || cmd >=BLK_SCSI_MAX_CMDS ) +if ((status == p) || cmd >=BLK_SCSI_MAX_CMDS )return -EINVAL ; -__set_bit (cmd, okbits); +if (set) +__set_bit (cmd, okbits); +else
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 149
Quoted 10 lines
block/cmd-filter.c +1
-5+__clear_bit (cmd, okbits); } -if (rw ==READ ) - target_okbits = filter->read_ok; -else - target_okbits = filter->write_ok; -memmove (target_okbits, okbits,sizeof (okbits));return count;
block/cmd-filter.c +27 -24
@@ -20,7 +20,6 @@#include <linux/list.h> #include <linux/genhd.h> #include <linux/spinlock.h> -#include <linux/parser.h> #include <linux/capability.h> #include <linux/bitops.h>
@@ -65,8 +64,8 @@ static ssize_t rcf_cmds_show(struct blk_cmd_filter *filter, char *page,for (i =0 ; i <BLK_SCSI_MAX_CMDS ; i++) {if (test_bit (i, okbits)) { -sprintf (npage,"%02x" , i); - npage +=2 ; +sprintf (npage,"0x%02x" , i); + npage +=4 ;if (i <BLK_SCSI_MAX_CMDS -1 )sprintf (npage++," " ); }
@@ -92,33 +91,37 @@ static ssize_t rcf_writecmds_show(struct blk_cmd_filter *filter,static ssize_t rcf_cmds_store (struct blk_cmd_filter *filter,const char *page,size_t count,int rw) { -ssize_t ret =0 ; -unsigned long okbits[BLK_SCSI_CMD_PER_LONG ], *target_okbits; -int cmd, status, len; -substring_t ss; - -memset (&okbits,0 ,sizeof (okbits)); - -for (len =strlen (page); len >0 ; len -=3 ) { -if (len <2 ) -break ; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret +2 ; - ret +=3 ; - status =match_hex (&ss, &cmd); -/* either of these cases means invalid input, so do nothing. */ -if (status || cmd >=BLK_SCSI_MAX_CMDS ) -return -EINVAL ; - -__set_bit (cmd, okbits); - } +unsigned long *target_okbits; +int cmd, set; +char *p, *status;if (rw ==READ ) target_okbits = filter->read_ok;else target_okbits = filter->write_ok; -memmove (target_okbits, okbits,sizeof (okbits)); +while ((p =strsep ((char **)&page," " )) !=NULL ) { + set =1 ; + +if (p[0 ] =='+' ) + p++; + + cmd =simple_strtol (p, &status,16 ); +if (cmd <0 ) { + cmd = -cmd; + set =0 ; + } + +/* either of these cases means invalid input, so do nothing. */ +if (status == p || cmd >=BLK_SCSI_MAX_CMDS ) +return -EINVAL ; + +if (set) +__set_bit (cmd, target_okbits); +else +__clear_bit (cmd, target_okbits); + } +return count; }
2008/8/8 FUJITA Tomonori <[email protected]>:
Quoted 24 lines
Quoted 21 lines · On Fri, 8 Aug 2008 20:46:55 +0200 "Adel Gadllah" <[email protected]> wrote:
v3 clean up parsing.
-----------------------------------
This patch changes the interface of the cmd filter to use a +/- notation like:
echo -- +0x02 +0x03 -0x08
If neither + or - is given it defaults to + (allow command).Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
Quoted 4 lines
Quoted 2 lines
block/cmd-filter.c | 53 ++++++++++++++++++++++++++++++--------------------- 1 files changed, 31 insertions(+), 22 deletions(-)Hmm, the patch seems to be corrupted again.
OK, attached as file...
Quoted 45 lines
block/cmd-filter.c
Quoted 5 lines
block/cmd-filter.c +0
-0I think that you can remove "
linux/parser.h".Quoted 36 lines
block/cmd-filter.c +2
-2@@ -84,8 +84,8 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {if (test_bit (i, okbits)) { -sprintf (npage,"%02x" , i); - npage +=2 ; +sprintf (npage,"0x%02x" , i); + npage +=4 ;if (i <BLK_SCSI_MAX_CMDS -1 )sprintf (npage++," " );}block/cmd-filter.c +5
-13@@ -111,32 +111,41 @@ static ssize_t rcf_writecmds_show(structblk_scsi_cmd_filter *filter, static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter, const char *page, size_t count, int rw) { - ssize_t ret = 0; unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; -int cmd, status, len; -substring_t ss; - -memset (&okbits,0 ,sizeof (okbits)); - -for (len =strlen (page); len >0 ; len -=3 ) { -if (len <2 ) -break ; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret +2 ; - ret +=3 ; - status =match_hex (&ss, &cmd); +int cmd, set; +char *p, *status; + +if (rw ==READ ) { +memcpy (&okbits, filter->read_ok,sizeof (okbits));
Quoted 8 lines
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 125
Quoted 5 lines
block/cmd-filter.c +5
-0+ target_okbits = filter->read_ok; + }else { +memcpy (&okbits, filter->write_ok,sizeof (okbits)); + target_okbits = filter->write_ok; + }Do we need this? We can modify
filter->write_okorfilter->read_okdirectly?
Yes, because in case of an error (wrong input) only a part of the request will be done (ex: enable 2 commands but not the third due to a typo which might confuse the user).
Quoted 10 lines
block/cmd-filter.c static ssize_t rcf_writecmds_show(struct · line 132
Quoted 7 lines
block/cmd-filter.c +7
-0+while ((p =strsep ((char **)&page," " )) !=NULL ) { + set =1 ; + +if (p[0 ] =='-' ) { + set =0 ; + p++; + }As I wrote, I prefer to let
simple_strtolto handle '-' though the current code is also fine by me.
well this seems easier (see my last mail)
This patch changes the interface of the cmd filter to use a +/- notation like:
echo -- +0x02 +0x03 -0x08
If neither + or - is given it defaults to + (allow command).
Note: The interface was added in 2.6.17-rc1 and is unused and undocumented so far so it's safe to change it.
block/cmd-filter.c | 54 +++++++++++++++++++++++++++++----------------------
1 files changed, 31 insertions(+), 23 deletions(-)
block/cmd-filter.c +31 -23
@@ -20,7 +20,6 @@#include <linux/list.h> #include <linux/genhd.h> #include <linux/spinlock.h> -#include <linux/parser.h> #include <linux/capability.h> #include <linux/bitops.h>
@@ -84,8 +83,8 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page,for (i =0 ; i <BLK_SCSI_MAX_CMDS ; i++) {if (test_bit (i, okbits)) { -sprintf (npage,"%02x" , i); - npage +=2 ; +sprintf (npage,"0x%02x" , i); + npage +=4 ;if (i <BLK_SCSI_MAX_CMDS -1 )sprintf (npage++," " ); }
@@ -111,32 +110,41 @@ static ssize_t rcf_writecmds_show(struct blk_scsi_cmd_filter *filter,static ssize_t rcf_cmds_store (struct blk_scsi_cmd_filter *filter,const char *page,size_t count,int rw) { -ssize_t ret =0 ;unsigned long okbits[BLK_SCSI_CMD_PER_LONG ], *target_okbits; -int cmd, status, len; -substring_t ss; - -memset (&okbits,0 ,sizeof (okbits)); - -for (len =strlen (page); len >0 ; len -=3 ) { -if (len <2 ) -break ; - ss.from = (char *) page + ret; - ss.to = (char *) page + ret +2 ; - ret +=3 ; - status =match_hex (&ss, &cmd); +int cmd, set; +char *p, *status; + +if (rw ==READ ) { +memcpy (&okbits, filter->read_ok,sizeof (okbits)); + target_okbits = filter->read_ok; + }else { +memcpy (&okbits, filter->write_ok,sizeof (okbits)); + target_okbits = filter->write_ok; + } + +while ((p =strsep ((char **)&page," " )) !=NULL ) { + set =1 ; + +if (p[0 ] =='-' ) { + set =0 ; + p++; + } + +if (p[0 ] =='+' ) + p++; + + cmd =simple_strtol (p, &status,16 ); +/* either of these cases means invalid input, so do nothing. */ -if (status || cmd >=BLK_SCSI_MAX_CMDS ) +if ((status == p) || cmd >=BLK_SCSI_MAX_CMDS )return -EINVAL ; -__set_bit (cmd, okbits); +if (set) +__set_bit (cmd, okbits); +else +__clear_bit (cmd, okbits); } -if (rw ==READ ) - target_okbits = filter->read_ok; -else - target_okbits = filter->write_ok; -memmove (target_okbits, okbits,sizeof (okbits));return count; }