2000-12-13 19:53:37 +00:00
|
|
|
|
.\"-
|
|
|
|
|
.\" Copyright (c) 2000 Poul Henning Kamp and Dag-Erling Co<43>dan Sm<53>rgrav
|
|
|
|
|
.\" All rights reserved.
|
|
|
|
|
.\"
|
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
|
.\" are met:
|
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
|
.\"
|
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
|
.\"
|
|
|
|
|
.\" $FreeBSD$
|
|
|
|
|
.\"
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Dd January 3, 2002
|
2001-04-18 08:25:26 +00:00
|
|
|
|
.Dt SBUF 9
|
2001-07-10 15:31:11 +00:00
|
|
|
|
.Os
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Sh NAME
|
|
|
|
|
.Nm sbuf_new ,
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Nm sbuf_clear ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Nm sbuf_setpos ,
|
2001-06-11 17:05:52 +00:00
|
|
|
|
.Nm sbuf_bcat ,
|
|
|
|
|
.Nm sbuf_bcopyin ,
|
|
|
|
|
.Nm sbuf_bcpy ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Nm sbuf_cat ,
|
2001-06-11 17:05:52 +00:00
|
|
|
|
.Nm sbuf_copyin ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Nm sbuf_cpy ,
|
|
|
|
|
.Nm sbuf_printf ,
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Nm sbuf_vprintf ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Nm sbuf_putc ,
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Nm sbuf_trim ,
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Nm sbuf_overflowed ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Nm sbuf_finish ,
|
|
|
|
|
.Nm sbuf_data ,
|
|
|
|
|
.Nm sbuf_len ,
|
|
|
|
|
.Nm sbuf_delete
|
|
|
|
|
.Nd safe string formatting
|
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
|
.In sys/types.h
|
|
|
|
|
.In sys/sbuf.h
|
2001-10-04 09:01:15 +00:00
|
|
|
|
.Ft struct sbuf *
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_new "struct sbuf *s" "char *buf" "int length" "int flags"
|
|
|
|
|
.Ft void
|
|
|
|
|
.Fn sbuf_clear "struct sbuf *s"
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Ft int
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_setpos "struct sbuf *s" "int pos"
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Ft int
|
2001-06-11 17:05:52 +00:00
|
|
|
|
.Fn sbuf_bcat "struct sbuf *s" "const char *str" "size_t len"
|
|
|
|
|
.Ft int
|
|
|
|
|
.Fn sbuf_bcopyin "struct sbuf *s" "const void *uaddr" "size_t len"
|
|
|
|
|
.Ft int
|
|
|
|
|
.Fn sbuf_bcpy "struct sbuf *s" "const char *str" "size_t len"
|
|
|
|
|
.Ft int
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
|
.Fn sbuf_cat "struct sbuf *s" "const char *str"
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Ft int
|
2001-06-11 17:05:52 +00:00
|
|
|
|
.Fn sbuf_copyin "struct sbuf *s" "const void *uaddr" "size_t len"
|
|
|
|
|
.Ft int
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
|
.Fn sbuf_cpy "struct sbuf *s" "const char *str"
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Ft int
|
2001-07-05 22:34:11 +00:00
|
|
|
|
.Fn sbuf_printf "struct sbuf *s" "const char *fmt" "..."
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Ft int
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Fn sbuf_vprintf "struct sbuf *s" "const char *fmt" "va_list ap"
|
|
|
|
|
.Ft int
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_putc "struct sbuf *s" "int c"
|
|
|
|
|
.Ft int
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Fn sbuf_trim "struct sbuf *s"
|
|
|
|
|
.Ft int
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_overflowed "struct sbuf *s"
|
|
|
|
|
.Ft void
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_finish "struct sbuf *s"
|
|
|
|
|
.Ft char *
|
|
|
|
|
.Fn sbuf_data "struct sbuf *s"
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Ft int
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_len "struct sbuf *s"
|
|
|
|
|
.Ft void
|
|
|
|
|
.Fn sbuf_delete "struct sbuf *s"
|
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
|
The
|
|
|
|
|
.Nm sbuf
|
2000-12-14 09:36:49 +00:00
|
|
|
|
family of functions allows one to safely allocate, construct and
|
2000-12-13 19:53:37 +00:00
|
|
|
|
release bounded null-terminated strings in kernel space.
|
|
|
|
|
Instead of arrays of characters, these functions operate on structures
|
|
|
|
|
called
|
|
|
|
|
.Fa sbufs ,
|
|
|
|
|
defined in
|
|
|
|
|
.Aq Pa sys/sbuf.h .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Fn sbuf_new
|
|
|
|
|
function initializes the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
pointed to by its first argument.
|
2001-06-10 15:48:04 +00:00
|
|
|
|
If that pointer is
|
|
|
|
|
.Dv NULL ,
|
|
|
|
|
.Fn sbuf_new
|
|
|
|
|
allocates a
|
2001-07-04 15:37:13 +00:00
|
|
|
|
.Vt struct sbuf
|
2001-06-10 15:48:04 +00:00
|
|
|
|
using
|
|
|
|
|
.Xr malloc 9 .
|
2000-12-13 19:53:37 +00:00
|
|
|
|
The
|
|
|
|
|
.Fa buf
|
|
|
|
|
argument is a pointer to a buffer in which to store the actual string;
|
|
|
|
|
if it is
|
|
|
|
|
.Dv NULL ,
|
|
|
|
|
.Fn sbuf_new
|
|
|
|
|
will allocate one using
|
|
|
|
|
.Xr malloc 9 .
|
|
|
|
|
The
|
|
|
|
|
.Fa length
|
2002-01-06 08:40:42 +00:00
|
|
|
|
is the initial size of the storage buffer.
|
2000-12-13 19:53:37 +00:00
|
|
|
|
The fourth argument,
|
|
|
|
|
.Fa flags ,
|
2002-01-06 08:40:42 +00:00
|
|
|
|
may be comprised of the following flags:
|
2002-01-10 12:53:51 +00:00
|
|
|
|
.Bl -tag -width ".Dv SBUF_AUTOEXTEND"
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.It Dv SBUF_FIXEDLEN
|
2002-01-10 12:53:51 +00:00
|
|
|
|
The storage buffer is fixed at its initial size.
|
2002-01-06 08:40:42 +00:00
|
|
|
|
Attempting to extend the sbuf beyond this size results in an overflow condition.
|
|
|
|
|
.It Dv SBUF_AUTOEXTEND
|
|
|
|
|
This indicates that the storage buffer may be extended as necessary, so long
|
|
|
|
|
as resources allow, to hold additional data.
|
|
|
|
|
.El
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Pp
|
|
|
|
|
Note that if
|
|
|
|
|
.Fa buf
|
|
|
|
|
is not
|
|
|
|
|
.Dv NULL ,
|
|
|
|
|
it must point to an array of at least
|
|
|
|
|
.Fa length
|
|
|
|
|
characters.
|
2002-01-06 08:40:42 +00:00
|
|
|
|
The contents of the provided buffer are undefined; to retrieve the sbuf data
|
|
|
|
|
.Fn sbuf_data
|
|
|
|
|
must be called on the finished
|
|
|
|
|
.Fa sbuf .
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Pp
|
|
|
|
|
The
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_clear
|
|
|
|
|
function invalidates the contents of the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
and resets its position to zero.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_setpos
|
|
|
|
|
function sets the
|
|
|
|
|
.Fa sbuf Ns 's
|
2002-01-06 08:40:42 +00:00
|
|
|
|
end position to
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fa pos ,
|
|
|
|
|
which is a value between zero and one less than the size of the
|
|
|
|
|
storage buffer.
|
2002-01-06 08:40:42 +00:00
|
|
|
|
This effectively truncates the sbuf at the new position.
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Pp
|
|
|
|
|
The
|
2001-06-11 17:05:52 +00:00
|
|
|
|
.Fn sbuf_bcat
|
|
|
|
|
function appends the first
|
|
|
|
|
.Fa len
|
|
|
|
|
bytes from the byte string
|
|
|
|
|
.Fa str
|
|
|
|
|
to the
|
|
|
|
|
.Fa sbuf .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Fn sbuf_bcopyin
|
|
|
|
|
function copies
|
|
|
|
|
.Fa len
|
|
|
|
|
bytes from the specified userland address into the
|
|
|
|
|
.Fa sbuf .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Fn sbuf_bcpy
|
|
|
|
|
function replaces the contents of the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
with the first
|
|
|
|
|
.Fa len
|
|
|
|
|
bytes from the byte string
|
|
|
|
|
.Fa str .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_cat
|
2001-06-11 17:05:52 +00:00
|
|
|
|
function appends the NUL-terminated string
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fa str
|
|
|
|
|
to the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
at the current position.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2001-06-11 17:05:52 +00:00
|
|
|
|
.Fn sbuf_copyin
|
|
|
|
|
function copies a NUL-terminated string from the specified userland
|
|
|
|
|
address into the
|
|
|
|
|
.Fa sbuf .
|
|
|
|
|
If the
|
|
|
|
|
.Fa len
|
|
|
|
|
argument is non-zero, no more than
|
|
|
|
|
.Fa len
|
|
|
|
|
characters (not counting the terminating NUL) are copied; otherwise
|
|
|
|
|
the entire string, or as much of it as can fit in the
|
|
|
|
|
.Fa sbuf ,
|
|
|
|
|
is copied.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_cpy
|
|
|
|
|
function replaces the contents of the
|
|
|
|
|
.Fa sbuf
|
2001-06-11 17:05:52 +00:00
|
|
|
|
with those of the NUL-terminated string
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fa str .
|
|
|
|
|
This is equivalent to calling
|
|
|
|
|
.Fn sbuf_cat
|
|
|
|
|
with a fresh
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
or one which position has been reset to zero with
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_clear
|
|
|
|
|
or
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_setpos .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Fn sbuf_printf
|
|
|
|
|
function formats its arguments according to the format string pointed
|
|
|
|
|
to by
|
|
|
|
|
.Fa fmt
|
|
|
|
|
and appends the resulting string to the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
at the current position.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Fn sbuf_vprintf
|
|
|
|
|
function behaves the same as
|
|
|
|
|
.Fn sbuf_printf
|
|
|
|
|
except that the arguments are obtained from the variable-length argument list
|
|
|
|
|
.Fa ap .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_putc
|
|
|
|
|
function appends the character
|
|
|
|
|
.Fa c
|
|
|
|
|
to the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
at the current position.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Fn sbuf_trim
|
|
|
|
|
function removes trailing whitespace from the
|
|
|
|
|
.Fa sbuf .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_overflowed
|
|
|
|
|
function returns a non-zero value if the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
overflowed.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_finish
|
|
|
|
|
function null-terminates the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
and marks it as finished, which means that it may no longer be
|
|
|
|
|
modified using
|
|
|
|
|
.Fn sbuf_setpos ,
|
|
|
|
|
.Fn sbuf_cat ,
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
|
.Fn sbuf_cpy ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_printf
|
|
|
|
|
or
|
|
|
|
|
.Fn sbuf_putc .
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Fn sbuf_data
|
|
|
|
|
and
|
|
|
|
|
.Fn sbuf_len
|
2001-01-28 00:18:54 +00:00
|
|
|
|
functions return the actual string and its length, respectively;
|
|
|
|
|
.Fn sbuf_data
|
|
|
|
|
only works on a finished
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fa sbuf .
|
|
|
|
|
.Pp
|
|
|
|
|
Finally, the
|
|
|
|
|
.Fn sbuf_delete
|
|
|
|
|
function clears the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
and frees its storage buffer if it was allocated by
|
|
|
|
|
.Fn sbuf_new .
|
|
|
|
|
.Sh NOTES
|
|
|
|
|
If an operation caused an
|
|
|
|
|
.Fa sbuf
|
2001-01-28 00:18:54 +00:00
|
|
|
|
to overflow, most subsequent operations on it will fail until the
|
|
|
|
|
.Fa sbuf
|
|
|
|
|
is finished using
|
|
|
|
|
.Fn sbuf_finish
|
|
|
|
|
or reset using
|
|
|
|
|
.Fn sbuf_clear ,
|
|
|
|
|
or its position is reset to a value between 0 and one less than the
|
|
|
|
|
size of its storage buffer using
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_setpos ,
|
|
|
|
|
or it is reinitialized to a sufficiently short string using
|
|
|
|
|
.Fn sbuf_cpy .
|
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
|
.Fn sbuf_new
|
2001-06-10 15:48:04 +00:00
|
|
|
|
returns
|
|
|
|
|
.Dv NULL
|
|
|
|
|
if it failed to allocate a storage buffer, and a pointer to the new
|
|
|
|
|
.Fa sbuf
|
2000-12-13 19:53:37 +00:00
|
|
|
|
otherwise.
|
|
|
|
|
.Pp
|
|
|
|
|
.Fn sbuf_setpos
|
|
|
|
|
returns \-1 if
|
|
|
|
|
.Fa pos
|
|
|
|
|
was invalid, and zero otherwise.
|
|
|
|
|
.Pp
|
|
|
|
|
.Fn sbuf_cat ,
|
|
|
|
|
.Fn sbuf_cpy ,
|
|
|
|
|
.Fn sbuf_printf ,
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Fn sbuf_putc ,
|
2000-12-13 19:53:37 +00:00
|
|
|
|
and
|
2002-01-06 08:40:42 +00:00
|
|
|
|
.Fn sbuf_trim
|
2000-12-13 19:53:37 +00:00
|
|
|
|
all return \-1 if the buffer overflowed, and zero otherwise.
|
|
|
|
|
.Pp
|
2001-01-28 00:18:54 +00:00
|
|
|
|
.Fn sbuf_overflowed
|
|
|
|
|
returns a non-zero value if the buffer overflowed, and zero otherwise.
|
|
|
|
|
.Pp
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Fn sbuf_data
|
|
|
|
|
and
|
|
|
|
|
.Fn sbuf_len
|
|
|
|
|
return
|
|
|
|
|
.Dv NULL
|
2001-01-28 00:18:54 +00:00
|
|
|
|
and \-1, respectively, if the buffer overflowed.
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Sh SEE ALSO
|
|
|
|
|
.Xr printf 3 ,
|
|
|
|
|
.Xr strcat 3 ,
|
2001-07-04 15:37:13 +00:00
|
|
|
|
.Xr strcpy 3 ,
|
|
|
|
|
.Xr copyin 9 ,
|
2001-12-09 08:12:06 +00:00
|
|
|
|
.Xr copyinstr 9 ,
|
|
|
|
|
.Xr printf 9
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Sh HISTORY
|
|
|
|
|
The
|
|
|
|
|
.Nm sbuf
|
|
|
|
|
family of functions first appeared in
|
2001-07-19 09:07:51 +00:00
|
|
|
|
.Fx 4.4 .
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Sh AUTHORS
|
|
|
|
|
.An -nosplit
|
|
|
|
|
The
|
|
|
|
|
.Nm sbuf
|
|
|
|
|
family of functions was designed by
|
|
|
|
|
.An Poul-Henning Kamp Aq phk@FreeBSD.org
|
|
|
|
|
and implemented by
|
|
|
|
|
.An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .
|
2001-01-28 00:18:54 +00:00
|
|
|
|
Additional improvements were suggested by
|
|
|
|
|
.An Justin T. Gibbs Aq gibbs@FreeBSD.org .
|
2002-01-06 08:40:42 +00:00
|
|
|
|
Auto-extend support added by
|
|
|
|
|
.An Kelly Yancey Aq kbyanc@FreeBSD.org .
|
2000-12-13 19:53:37 +00:00
|
|
|
|
.Pp
|
|
|
|
|
This manual page was written by
|
|
|
|
|
.An Dag-Erling Co\(:idan Sm\(/orgrav .
|