Const'ify the CDB format string passed to the CDB parsing routines

(csio_decode_visit() and family).

Reviewed by:	ken
This commit is contained in:
Kelly Yancey 2001-12-18 00:48:44 +00:00
parent 7e1f6dfe9d
commit cb28eb78cb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=88090
3 changed files with 62 additions and 43 deletions

View file

@ -88,7 +88,7 @@
.Fa "u_int32_t flags" .Fa "u_int32_t flags"
.Fa "int retry_count" .Fa "int retry_count"
.Fa "int timeout" .Fa "int timeout"
.Fa "char *cmd_spec" .Fa "const char *cmd_spec"
.Fa "..." .Fa "..."
.Fc .Fc
.Ft int .Ft int
@ -99,20 +99,20 @@
.Fa "u_int32_t flags" .Fa "u_int32_t flags"
.Fa "int retry_count" .Fa "int retry_count"
.Fa "int timeout" .Fa "int timeout"
.Fa "char *cmd_spec" .Fa "const char *cmd_spec"
.Fa "int (*arg_get)(void *hook, char *field_name)" .Fa "int (*arg_get)(void *hook, char *field_name)"
.Fa "void *gethook" .Fa "void *gethook"
.Fc .Fc
.Ft int .Ft int
.Fo csio_decode .Fo csio_decode
.Fa "struct ccb_scsiio *csio" .Fa "struct ccb_scsiio *csio"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "..." .Fa "..."
.Fc .Fc
.Ft int .Ft int
.Fo csio_decode_visit .Fo csio_decode_visit
.Fa "struct ccb_scsiio *csio" .Fa "struct ccb_scsiio *csio"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "void (*arg_put)(void *hook" .Fa "void (*arg_put)(void *hook"
.Fa "int letter" .Fa "int letter"
.Fa "void *val" .Fa "void *val"
@ -124,27 +124,27 @@
.Fo buff_decode .Fo buff_decode
.Fa "u_int8_t *buff" .Fa "u_int8_t *buff"
.Fa "size_t len" .Fa "size_t len"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "..." .Fa "..."
.Fc .Fc
.Ft int .Ft int
.Fo buff_decode_visit .Fo buff_decode_visit
.Fa "u_int8_t *buff" .Fa "u_int8_t *buff"
.Fa "size_t len" .Fa "size_t len"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "void (*arg_put)(void *, int, void *, int, char *)" .Fa "void (*arg_put)(void *, int, void *, int, char *)"
.Fa "void *puthook" .Fa "void *puthook"
.Fc .Fc
.Ft int .Ft int
.Fo csio_encode .Fo csio_encode
.Fa "struct ccb_scsiio *csio" .Fa "struct ccb_scsiio *csio"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "..." .Fa "..."
.Fc .Fc
.Ft int .Ft int
.Fo csio_encode_visit .Fo csio_encode_visit
.Fa "struct ccb_scsiio *csio" .Fa "struct ccb_scsiio *csio"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "int (*arg_get)(void *hook, char *field_name)" .Fa "int (*arg_get)(void *hook, char *field_name)"
.Fa "void *gethook" .Fa "void *gethook"
.Fc .Fc
@ -152,7 +152,7 @@
.Fo buff_encode_visit .Fo buff_encode_visit
.Fa "u_int8_t *buff" .Fa "u_int8_t *buff"
.Fa "size_t len" .Fa "size_t len"
.Fa "char *fmt" .Fa "const char *fmt"
.Fa "int (*arg_get)(void *hook, char *field_name)" .Fa "int (*arg_get)(void *hook, char *field_name)"
.Fa "void *gethook" .Fa "void *gethook"
.Fc .Fc

View file

@ -150,27 +150,30 @@ int cam_get_device(const char *path, char *dev_name,
/* /*
* Buffer encoding/decoding routines, from the old SCSI library. * Buffer encoding/decoding routines, from the old SCSI library.
*/ */
int csio_decode(struct ccb_scsiio *csio, char *fmt, ...) __printflike(2, 3); int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
int csio_decode_visit(struct ccb_scsiio *csio, char *fmt, __printflike(2, 3);
int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
void (*arg_put)(void *, int, void *, int, char *), void (*arg_put)(void *, int, void *, int, char *),
void *puthook); void *puthook);
int buff_decode(u_int8_t *buff, size_t len, char *fmt, ...) __printflike(3, 4); int buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...)
int buff_decode_visit(u_int8_t *buff, size_t len, char *fmt, __printflike(3, 4);
int buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt,
void (*arg_put)(void *, int, void *, int, char *), void (*arg_put)(void *, int, void *, int, char *),
void *puthook); void *puthook);
int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr,
u_int32_t dxfer_len, u_int32_t flags, int retry_count, u_int32_t dxfer_len, u_int32_t flags, int retry_count,
int timeout, char *cmd_spec, ...); int timeout, const char *cmd_spec, ...);
int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
u_int32_t dxfer_len, u_int32_t flags, int retry_count, u_int32_t dxfer_len, u_int32_t flags, int retry_count,
int timeout, char *cmd_spec, int timeout, const char *cmd_spec,
int (*arg_get)(void *hook, char *field_name), int (*arg_get)(void *hook, char *field_name),
void *gethook); void *gethook);
int csio_encode(struct ccb_scsiio *csio, char *fmt, ...) __printflike(2, 3); int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
int buff_encode_visit(u_int8_t *buff, size_t len, char *fmt, __printflike(2, 3);
int buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt,
int (*arg_get)(void *hook, char *field_name), int (*arg_get)(void *hook, char *field_name),
void *gethook); void *gethook);
int csio_encode_visit(struct ccb_scsiio *csio, char *fmt, int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
int (*arg_get)(void *hook, char *field_name), int (*arg_get)(void *hook, char *field_name),
void *gethook); void *gethook);
__END_DECLS __END_DECLS

View file

@ -100,7 +100,7 @@ __FBSDID("$FreeBSD$");
static int static int
do_buff_decode(u_int8_t *databuf, size_t len, do_buff_decode(u_int8_t *databuf, size_t len,
void (*arg_put)(void *, int , void *, int, char *), void (*arg_put)(void *, int , void *, int, char *),
void *puthook, char *fmt, va_list ap) void *puthook, const char *fmt, va_list ap)
{ {
int assigned = 0; int assigned = 0;
int width; int width;
@ -111,6 +111,7 @@ do_buff_decode(u_int8_t *databuf, size_t len,
0x1f, 0x3f, 0x7f, 0xff}; 0x1f, 0x3f, 0x7f, 0xff};
int value; int value;
u_char *base = databuf; u_char *base = databuf;
char *intendp;
char letter; char letter;
char field_name[80]; char field_name[80];
@ -178,7 +179,8 @@ do_buff_decode(u_int8_t *databuf, size_t len,
case 't': /* Bit (field) */ case 't': /* Bit (field) */
case 'b': /* Bits */ case 'b': /* Bits */
fmt++; fmt++;
width = strtol(fmt, &fmt, 10); width = strtol(fmt, &intendp, 10);
fmt = intendp;
if (width > 8) if (width > 8)
done = 1; done = 1;
else { else {
@ -203,7 +205,8 @@ do_buff_decode(u_int8_t *databuf, size_t len,
case 'i': /* Integral values */ case 'i': /* Integral values */
shift = 0; shift = 0;
fmt++; fmt++;
width = strtol(fmt, &fmt, 10); width = strtol(fmt, &intendp, 10);
fmt = intendp;
switch(width) { switch(width) {
case 1: case 1:
ARG_PUT(*databuf); ARG_PUT(*databuf);
@ -241,7 +244,8 @@ do_buff_decode(u_int8_t *databuf, size_t len,
spaces */ spaces */
shift = 0; shift = 0;
fmt++; fmt++;
width = strtol(fmt, &fmt, 10); width = strtol(fmt, &intendp, 10);
fmt = intendp;
if (!suppress) { if (!suppress) {
if (arg_put) if (arg_put)
(*arg_put)(puthook, (*arg_put)(puthook,
@ -283,8 +287,10 @@ do_buff_decode(u_int8_t *databuf, size_t len,
*/ */
width = (arg_put) ? 0 : va_arg(ap, int); width = (arg_put) ? 0 : va_arg(ap, int);
fmt++; fmt++;
} else } else {
width = strtol(fmt, &fmt, 10); width = strtol(fmt, &intendp, 10);
fmt = intendp;
}
if (plus) if (plus)
databuf += width; /* Relative seek */ databuf += width; /* Relative seek */
@ -341,10 +347,11 @@ do_buff_decode(u_int8_t *databuf, size_t len,
*/ */
static int static int
next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name, next_field(const char **pp, char *fmt, int *width_p, int *value_p, char *name,
int n_name, int *error_p, int *suppress_p) int n_name, int *error_p, int *suppress_p)
{ {
char *p = *pp; const char *p = *pp;
char *intendp;
int something = 0; int something = 0;
@ -404,7 +411,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
suppress = 1; suppress = 1;
} else if (isxdigit(*p)) { } else if (isxdigit(*p)) {
something = 1; something = 1;
value = strtol(p, &p, 16); value = strtol(p, &intendp, 16);
p = intendp;
state = START_FIELD; state = START_FIELD;
} else if (tolower(*p) == 'v') { } else if (tolower(*p) == 'v') {
p++; p++;
@ -421,7 +429,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
*fmt = 'i'; *fmt = 'i';
field_size = 8; field_size = 8;
field_width = strtol(p, &p, 10); field_width = strtol(p, &intendp, 10);
p = intendp;
state = DONE; state = DONE;
} else if (tolower(*p) == 't') { } else if (tolower(*p) == 't') {
@ -436,7 +445,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
*fmt = 'b'; *fmt = 'b';
field_size = 1; field_size = 1;
field_width = strtol(p, &p, 10); field_width = strtol(p, &intendp, 10);
p = intendp;
state = DONE; state = DONE;
} else if (tolower(*p) == 's') { } else if (tolower(*p) == 's') {
/* Seek */ /* Seek */
@ -448,7 +458,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
value = *value_p; value = *value_p;
} else { } else {
something = 1; something = 1;
value = strtol(p, &p, 0); value = strtol(p, &intendp, 0);
p = intendp;
} }
state = DONE; state = DONE;
} else { } else {
@ -473,7 +484,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
if (isdigit(*p)) { if (isdigit(*p)) {
*fmt = 'b'; *fmt = 'b';
field_size = 1; field_size = 1;
field_width = strtol(p, &p, 10); field_width = strtol(p, &intendp, 10);
p = intendp;
state = DONE; state = DONE;
} else if (*p == 'i') { } else if (*p == 'i') {
@ -482,7 +494,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
*fmt = 'i'; *fmt = 'i';
field_size = 8; field_size = 8;
field_width = strtol(p, &p, 10); field_width = strtol(p, &intendp, 10);
p = intendp;
state = DONE; state = DONE;
} else if (*p == 'b') { } else if (*p == 'b') {
@ -491,7 +504,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
*fmt = 'b'; *fmt = 'b';
field_size = 1; field_size = 1;
field_width = strtol(p, &p, 10); field_width = strtol(p, &intendp, 10);
p = intendp;
state = DONE; state = DONE;
} else { } else {
fprintf(stderr, "Invalid startfield %c " fprintf(stderr, "Invalid startfield %c "
@ -522,7 +536,8 @@ next_field(char **pp, char *fmt, int *width_p, int *value_p, char *name,
static int static int
do_encode(u_char *buff, size_t vec_max, size_t *used, do_encode(u_char *buff, size_t vec_max, size_t *used,
int (*arg_get)(void *, char *), void *gethook, char *fmt, va_list ap) int (*arg_get)(void *, char *), void *gethook, const char *fmt,
va_list ap)
{ {
int ind; int ind;
int shift; int shift;
@ -642,7 +657,7 @@ do_encode(u_char *buff, size_t vec_max, size_t *used,
} }
int int
csio_decode(struct ccb_scsiio *csio, char *fmt, ...) csio_decode(struct ccb_scsiio *csio, const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -653,7 +668,7 @@ csio_decode(struct ccb_scsiio *csio, char *fmt, ...)
} }
int int
csio_decode_visit(struct ccb_scsiio *csio, char *fmt, csio_decode_visit(struct ccb_scsiio *csio, const char *fmt,
void (*arg_put)(void *, int, void *, int, char *), void (*arg_put)(void *, int, void *, int, char *),
void *puthook) void *puthook)
{ {
@ -673,7 +688,7 @@ csio_decode_visit(struct ccb_scsiio *csio, char *fmt,
} }
int int
buff_decode(u_int8_t *buff, size_t len, char *fmt, ...) buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -683,7 +698,7 @@ buff_decode(u_int8_t *buff, size_t len, char *fmt, ...)
} }
int int
buff_decode_visit(u_int8_t *buff, size_t len, char *fmt, buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt,
void (*arg_put)(void *, int, void *, int, char *), void (*arg_put)(void *, int, void *, int, char *),
void *puthook) void *puthook)
{ {
@ -707,7 +722,8 @@ buff_decode_visit(u_int8_t *buff, size_t len, char *fmt,
*/ */
int int
csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, u_int32_t dxfer_len, csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, u_int32_t dxfer_len,
u_int32_t flags, int retry_count, int timeout, char *cmd_spec, ...) u_int32_t flags, int retry_count, int timeout, const char *cmd_spec,
...)
{ {
size_t cmdlen; size_t cmdlen;
int retval; int retval;
@ -741,7 +757,7 @@ csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, u_int32_t dxfer_len,
int int
csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
u_int32_t dxfer_len, u_int32_t flags, int retry_count, u_int32_t dxfer_len, u_int32_t flags, int retry_count,
int timeout, char *cmd_spec, int timeout, const char *cmd_spec,
int (*arg_get)(void *hook, char *field_name), void *gethook) int (*arg_get)(void *hook, char *field_name), void *gethook)
{ {
va_list ap; va_list ap;
@ -781,7 +797,7 @@ csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr,
} }
int int
csio_encode(struct ccb_scsiio *csio, char *fmt, ...) csio_encode(struct ccb_scsiio *csio, const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -794,7 +810,7 @@ csio_encode(struct ccb_scsiio *csio, char *fmt, ...)
} }
int int
buff_encode_visit(u_int8_t *buff, size_t len, char *fmt, buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt,
int (*arg_get)(void *hook, char *field_name), void *gethook) int (*arg_get)(void *hook, char *field_name), void *gethook)
{ {
va_list ap; va_list ap;
@ -812,7 +828,7 @@ buff_encode_visit(u_int8_t *buff, size_t len, char *fmt,
} }
int int
csio_encode_visit(struct ccb_scsiio *csio, char *fmt, csio_encode_visit(struct ccb_scsiio *csio, const char *fmt,
int (*arg_get)(void *hook, char *field_name), void *gethook) int (*arg_get)(void *hook, char *field_name), void *gethook)
{ {
va_list ap; va_list ap;