FreeBSD kernel kern code
subr_sbuf.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/ctype.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <machine/stdarg.h>
#include <sys/sbuf.h>
Include dependency graph for subr_sbuf.c:

Go to the source code of this file.

Macros

#define SBMALLOC(size, flags)   malloc(size, M_SBUF, (flags) | M_ZERO)
 
#define SBFREE(buf)   free(buf, M_SBUF)
 
#define SBUF_ISDYNAMIC(s)   ((s)->s_flags & SBUF_DYNAMIC)
 
#define SBUF_ISDYNSTRUCT(s)   ((s)->s_flags & SBUF_DYNSTRUCT)
 
#define SBUF_ISFINISHED(s)   ((s)->s_flags & SBUF_FINISHED)
 
#define SBUF_ISDRAINATEOL(s)   ((s)->s_flags & SBUF_DRAINATEOL)
 
#define SBUF_HASROOM(s)   ((s)->s_len < (s)->s_size - 1)
 
#define SBUF_FREESPACE(s)   ((s)->s_size - ((s)->s_len + 1))
 
#define SBUF_CANEXTEND(s)   ((s)->s_flags & SBUF_AUTOEXTEND)
 
#define SBUF_ISSECTION(s)   ((s)->s_flags & SBUF_INSECTION)
 
#define SBUF_NULINCLUDED(s)   ((s)->s_flags & SBUF_INCLUDENUL)
 
#define SBUF_ISDRAINTOEOR(s)   ((s)->s_flags & SBUF_DRAINTOEOR)
 
#define SBUF_DODRAINTOEOR(s)   (SBUF_ISSECTION(s) && SBUF_ISDRAINTOEOR(s))
 
#define SBUF_MALLOCFLAG(s)    (((s)->s_flags & SBUF_NOWAIT) ? M_NOWAIT : M_WAITOK)
 
#define SBUF_SETFLAG(s, f)   do { (s)->s_flags |= (f); } while (0)
 
#define SBUF_CLEARFLAG(s, f)   do { (s)->s_flags &= ~(f); } while (0)
 
#define SBUF_MINSIZE   2 /* Min is 1 byte + nulterm. */
 
#define SBUF_MINEXTENDSIZE   16 /* Should be power of 2. */
 
#define SBUF_MAXEXTENDSIZE   4096
 
#define SBUF_MAXEXTENDINCR   4096
 
#define assert_sbuf_integrity(s)   do { } while (0)
 
#define assert_sbuf_state(s, i)   do { } while (0)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_SBUF, "sbuf", "string buffers")
 
static int sbuf_extendsize (int size)
 
static int sbuf_extend (struct sbuf *s, int addlen)
 
struct sbuf * sbuf_new (struct sbuf *s, char *buf, int length, int flags)
 
struct sbuf * sbuf_uionew (struct sbuf *s, struct uio *uio, int *error)
 
int sbuf_get_flags (struct sbuf *s)
 
void sbuf_clear_flags (struct sbuf *s, int flags)
 
void sbuf_set_flags (struct sbuf *s, int flags)
 
void sbuf_clear (struct sbuf *s)
 
int sbuf_setpos (struct sbuf *s, ssize_t pos)
 
int sbuf_count_drain (void *arg, const char *data __unused, int len)
 
void sbuf_set_drain (struct sbuf *s, sbuf_drain_func *func, void *ctx)
 
int sbuf_drain (struct sbuf *s)
 
static void sbuf_put_bytes (struct sbuf *s, const char *buf, size_t len)
 
static void sbuf_put_byte (struct sbuf *s, char c)
 
int sbuf_bcat (struct sbuf *s, const void *buf, size_t len)
 
int sbuf_bcopyin (struct sbuf *s, const void *uaddr, size_t len)
 
int sbuf_bcpy (struct sbuf *s, const void *buf, size_t len)
 
int sbuf_cat (struct sbuf *s, const char *str)
 
int sbuf_copyin (struct sbuf *s, const void *uaddr, size_t len)
 
int sbuf_cpy (struct sbuf *s, const char *str)
 
static void sbuf_putc_func (int c, void *arg)
 
int sbuf_vprintf (struct sbuf *s, const char *fmt, va_list ap)
 
int sbuf_printf (struct sbuf *s, const char *fmt,...)
 
int sbuf_putc (struct sbuf *s, int c)
 
int sbuf_nl_terminate (struct sbuf *s)
 
int sbuf_trim (struct sbuf *s)
 
int sbuf_error (const struct sbuf *s)
 
int sbuf_finish (struct sbuf *s)
 
char * sbuf_data (struct sbuf *s)
 
ssize_t sbuf_len (struct sbuf *s)
 
void sbuf_delete (struct sbuf *s)
 
int sbuf_done (const struct sbuf *s)
 
void sbuf_start_section (struct sbuf *s, ssize_t *old_lenp)
 
ssize_t sbuf_end_section (struct sbuf *s, ssize_t old_len, size_t pad, int c)
 

Macro Definition Documentation

◆ assert_sbuf_integrity

#define assert_sbuf_integrity (   s)    do { } while (0)

Definition at line 139 of file subr_sbuf.c.

◆ assert_sbuf_state

#define assert_sbuf_state (   s,
 
)    do { } while (0)

Definition at line 140 of file subr_sbuf.c.

◆ SBFREE

#define SBFREE (   buf)    free(buf, M_SBUF)

Definition at line 60 of file subr_sbuf.c.

◆ SBMALLOC

#define SBMALLOC (   size,
  flags 
)    malloc(size, M_SBUF, (flags) | M_ZERO)

Definition at line 59 of file subr_sbuf.c.

◆ SBUF_CANEXTEND

#define SBUF_CANEXTEND (   s)    ((s)->s_flags & SBUF_AUTOEXTEND)

Definition at line 76 of file subr_sbuf.c.

◆ SBUF_CLEARFLAG

#define SBUF_CLEARFLAG (   s,
 
)    do { (s)->s_flags &= ~(f); } while (0)

Definition at line 88 of file subr_sbuf.c.

◆ SBUF_DODRAINTOEOR

#define SBUF_DODRAINTOEOR (   s)    (SBUF_ISSECTION(s) && SBUF_ISDRAINTOEOR(s))

Definition at line 80 of file subr_sbuf.c.

◆ SBUF_FREESPACE

#define SBUF_FREESPACE (   s)    ((s)->s_size - ((s)->s_len + 1))

Definition at line 75 of file subr_sbuf.c.

◆ SBUF_HASROOM

#define SBUF_HASROOM (   s)    ((s)->s_len < (s)->s_size - 1)

Definition at line 74 of file subr_sbuf.c.

◆ SBUF_ISDRAINATEOL

#define SBUF_ISDRAINATEOL (   s)    ((s)->s_flags & SBUF_DRAINATEOL)

Definition at line 73 of file subr_sbuf.c.

◆ SBUF_ISDRAINTOEOR

#define SBUF_ISDRAINTOEOR (   s)    ((s)->s_flags & SBUF_DRAINTOEOR)

Definition at line 79 of file subr_sbuf.c.

◆ SBUF_ISDYNAMIC

#define SBUF_ISDYNAMIC (   s)    ((s)->s_flags & SBUF_DYNAMIC)

Definition at line 70 of file subr_sbuf.c.

◆ SBUF_ISDYNSTRUCT

#define SBUF_ISDYNSTRUCT (   s)    ((s)->s_flags & SBUF_DYNSTRUCT)

Definition at line 71 of file subr_sbuf.c.

◆ SBUF_ISFINISHED

#define SBUF_ISFINISHED (   s)    ((s)->s_flags & SBUF_FINISHED)

Definition at line 72 of file subr_sbuf.c.

◆ SBUF_ISSECTION

#define SBUF_ISSECTION (   s)    ((s)->s_flags & SBUF_INSECTION)

Definition at line 77 of file subr_sbuf.c.

◆ SBUF_MALLOCFLAG

#define SBUF_MALLOCFLAG (   s)     (((s)->s_flags & SBUF_NOWAIT) ? M_NOWAIT : M_WAITOK)

Definition at line 81 of file subr_sbuf.c.

◆ SBUF_MAXEXTENDINCR

#define SBUF_MAXEXTENDINCR   4096

Definition at line 98 of file subr_sbuf.c.

◆ SBUF_MAXEXTENDSIZE

#define SBUF_MAXEXTENDSIZE   4096

Definition at line 97 of file subr_sbuf.c.

◆ SBUF_MINEXTENDSIZE

#define SBUF_MINEXTENDSIZE   16 /* Should be power of 2. */

Definition at line 91 of file subr_sbuf.c.

◆ SBUF_MINSIZE

#define SBUF_MINSIZE   2 /* Min is 1 byte + nulterm. */

Definition at line 90 of file subr_sbuf.c.

◆ SBUF_NULINCLUDED

#define SBUF_NULINCLUDED (   s)    ((s)->s_flags & SBUF_INCLUDENUL)

Definition at line 78 of file subr_sbuf.c.

◆ SBUF_SETFLAG

#define SBUF_SETFLAG (   s,
 
)    do { (s)->s_flags |= (f); } while (0)

Definition at line 87 of file subr_sbuf.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_SBUF  ,
"sbuf"  ,
"string buffers"   
)
static

◆ sbuf_bcat()

◆ sbuf_bcopyin()

int sbuf_bcopyin ( struct sbuf *  s,
const void *  uaddr,
size_t  len 
)

Definition at line 523 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_extend(), and SBUF_FREESPACE.

Here is the call graph for this function:

◆ sbuf_bcpy()

int sbuf_bcpy ( struct sbuf *  s,
const void *  buf,
size_t  len 
)

Definition at line 552 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, buf, sbuf_bcat(), and sbuf_clear().

Here is the call graph for this function:

◆ sbuf_cat()

◆ sbuf_clear()

void sbuf_clear ( struct sbuf *  s)

Definition at line 316 of file subr_sbuf.c.

References assert_sbuf_integrity, and SBUF_CLEARFLAG.

Referenced by kern_abort2(), sbuf_bcpy(), sbuf_cpy(), sbuf_print_witness_badstacks(), sonewconn(), sysctl_kern_console(), and vfs_mountroot().

Here is the caller graph for this function:

◆ sbuf_clear_flags()

void sbuf_clear_flags ( struct sbuf *  s,
int  flags 
)

◆ sbuf_copyin()

int sbuf_copyin ( struct sbuf *  s,
const void *  uaddr,
size_t  len 
)

Definition at line 582 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_extend(), SBUF_FREESPACE, and SBUF_ISSECTION.

Referenced by kern_abort2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_count_drain()

int sbuf_count_drain ( void *  arg,
const char *data  __unused,
int  len 
)

Definition at line 362 of file subr_sbuf.c.

Referenced by note_procstat_auxv(), note_procstat_files(), and note_procstat_vmmap().

Here is the caller graph for this function:

◆ sbuf_cpy()

int sbuf_cpy ( struct sbuf *  s,
const char *  str 
)

Definition at line 622 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_cat(), and sbuf_clear().

Referenced by cpufreq_levels_sysctl(), cpufreq_settings_sysctl(), devaddq(), devctl_notify(), and mount_devctl_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_data()

◆ sbuf_delete()

◆ sbuf_done()

int sbuf_done ( const struct sbuf *  s)

Definition at line 917 of file subr_sbuf.c.

References SBUF_ISFINISHED.

◆ sbuf_drain()

int sbuf_drain ( struct sbuf *  s)

Definition at line 391 of file subr_sbuf.c.

References SBUF_CLEARFLAG, SBUF_DODRAINTOEOR, and SBUF_SETFLAG.

Referenced by sbuf_finish(), sbuf_put_byte(), and sbuf_put_bytes().

Here is the caller graph for this function:

◆ sbuf_end_section()

ssize_t sbuf_end_section ( struct sbuf *  s,
ssize_t  old_len,
size_t  pad,
int  c 
)

Definition at line 953 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, SBUF_CLEARFLAG, SBUF_ISSECTION, and sbuf_put_byte().

Referenced by corehdr(), note_procstat_files(), and putnote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_error()

int sbuf_error ( const struct sbuf *  s)

Definition at line 823 of file subr_sbuf.c.

Referenced by corefile_open(), export_kinfo_to_sb(), mount_devctl_event(), stats_v1_blob_tostr(), stats_v1_itercb_tostr(), and stats_voistatdata_tostr().

Here is the caller graph for this function:

◆ sbuf_extend()

static int sbuf_extend ( struct sbuf *  s,
int  addlen 
)
static

Definition at line 169 of file subr_sbuf.c.

References SBFREE, SBMALLOC, SBUF_CANEXTEND, sbuf_extendsize(), SBUF_ISDYNAMIC, SBUF_MALLOCFLAG, and SBUF_SETFLAG.

Referenced by sbuf_bcopyin(), sbuf_copyin(), sbuf_put_byte(), and sbuf_put_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_extendsize()

static int sbuf_extendsize ( int  size)
static

Definition at line 150 of file subr_sbuf.c.

References SBUF_MAXEXTENDINCR, SBUF_MAXEXTENDSIZE, and SBUF_MINEXTENDSIZE.

Referenced by sbuf_extend(), and sbuf_new().

Here is the caller graph for this function:

◆ sbuf_finish()

◆ sbuf_get_flags()

int sbuf_get_flags ( struct sbuf *  s)

Definition at line 292 of file subr_sbuf.c.

◆ sbuf_len()

◆ sbuf_new()

◆ sbuf_nl_terminate()

int sbuf_nl_terminate ( struct sbuf *  s)

Definition at line 768 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, SBUF_ISDRAINATEOL, and sbuf_put_byte().

Referenced by stack_sbuf_print_flags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_printf()

◆ sbuf_put_byte()

static void sbuf_put_byte ( struct sbuf *  s,
char  c 
)
static

Definition at line 480 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, sbuf_drain(), sbuf_extend(), SBUF_FREESPACE, and SBUF_ISSECTION.

Referenced by sbuf_end_section(), sbuf_nl_terminate(), sbuf_putc(), and sbuf_putc_func().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_put_bytes()

static void sbuf_put_bytes ( struct sbuf *  s,
const char *  buf,
size_t  len 
)
static

Definition at line 444 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, buf, sbuf_drain(), sbuf_extend(), SBUF_FREESPACE, and SBUF_ISSECTION.

Referenced by sbuf_bcat(), and sbuf_cat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_putc()

◆ sbuf_putc_func()

static void sbuf_putc_func ( int  c,
void *  arg 
)
static

Definition at line 642 of file subr_sbuf.c.

References sbuf_put_byte().

Referenced by sbuf_vprintf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sbuf_set_drain()

void sbuf_set_drain ( struct sbuf *  s,
sbuf_drain_func *  func,
void *  ctx 
)

◆ sbuf_set_flags()

void sbuf_set_flags ( struct sbuf *  s,
int  flags 
)

Definition at line 306 of file subr_sbuf.c.

References flags.

◆ sbuf_setpos()

int sbuf_setpos ( struct sbuf *  s,
ssize_t  pos 
)

Definition at line 336 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, and SBUF_ISSECTION.

◆ sbuf_start_section()

void sbuf_start_section ( struct sbuf *  s,
ssize_t *  old_lenp 
)

Definition at line 927 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, SBUF_ISSECTION, and SBUF_SETFLAG.

Referenced by corehdr(), note_procstat_files(), and putnote().

Here is the caller graph for this function:

◆ sbuf_trim()

int sbuf_trim ( struct sbuf *  s)

Definition at line 799 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, and SBUF_ISSECTION.

Referenced by cpufreq_levels_sysctl(), cpufreq_settings_sysctl(), and kern_abort2().

Here is the caller graph for this function:

◆ sbuf_uionew()

struct sbuf * sbuf_uionew ( struct sbuf *  s,
struct uio *  uio,
int *  error 
)

Definition at line 261 of file subr_sbuf.c.

References sbuf_delete(), SBUF_ISSECTION, SBUF_MINSIZE, sbuf_new(), and uiomove().

Here is the call graph for this function:

◆ sbuf_vprintf()

int sbuf_vprintf ( struct sbuf *  s,
const char *  fmt,
va_list  ap 
)

Definition at line 650 of file subr_sbuf.c.

References assert_sbuf_integrity, assert_sbuf_state, kvprintf(), and sbuf_putc_func().

Referenced by device_log(), device_printf(), mount_argf(), and sbuf_printf().

Here is the call graph for this function:
Here is the caller graph for this function: