13a7d8294SWarner Losh.\" Copyright (c) Michael Smith 23a7d8294SWarner Losh.\" All rights reserved. 33a7d8294SWarner Losh.\" 43a7d8294SWarner Losh.\" Redistribution and use in source and binary forms, with or without 53a7d8294SWarner Losh.\" modification, are permitted provided that the following conditions 63a7d8294SWarner Losh.\" are met: 73a7d8294SWarner Losh.\" 1. Redistributions of source code must retain the above copyright 83a7d8294SWarner Losh.\" notice, this list of conditions and the following disclaimer. 93a7d8294SWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright 103a7d8294SWarner Losh.\" notice, this list of conditions and the following disclaimer in the 113a7d8294SWarner Losh.\" documentation and/or other materials provided with the distribution. 123a7d8294SWarner Losh.\" 133a7d8294SWarner Losh.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 143a7d8294SWarner Losh.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 153a7d8294SWarner Losh.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 163a7d8294SWarner Losh.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 173a7d8294SWarner Losh.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 183a7d8294SWarner Losh.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 193a7d8294SWarner Losh.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 203a7d8294SWarner Losh.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 213a7d8294SWarner Losh.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 223a7d8294SWarner Losh.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 233a7d8294SWarner Losh.\" SUCH DAMAGE. 243a7d8294SWarner Losh.\" 2545ad9557SWarner Losh.Dd September 9, 2022 26f6b2a429SKyle Evans.Dt LIBSA 3 273a7d8294SWarner Losh.Os 283a7d8294SWarner Losh.Sh NAME 29f6b2a429SKyle Evans.Nm libsa 303a7d8294SWarner Losh.Nd support library for standalone executables 313a7d8294SWarner Losh.Sh SYNOPSIS 323a7d8294SWarner Losh.In stand.h 333a7d8294SWarner Losh.Sh DESCRIPTION 343a7d8294SWarner LoshThe 353a7d8294SWarner Losh.Nm 363a7d8294SWarner Loshlibrary provides a set of supporting functions for standalone 373a7d8294SWarner Loshapplications, mimicking where possible the standard 383a7d8294SWarner Losh.Bx 393a7d8294SWarner Loshprogramming 403a7d8294SWarner Loshenvironment. 413a7d8294SWarner LoshThe following sections group these functions by kind. 423a7d8294SWarner LoshUnless specifically described here, see the corresponding section 3 433a7d8294SWarner Loshmanpages for the given functions. 443a7d8294SWarner Losh.Sh STRING FUNCTIONS 453a7d8294SWarner LoshString functions are available as documented in 463a7d8294SWarner Losh.Xr string 3 473a7d8294SWarner Loshand 483a7d8294SWarner Losh.Xr bstring 3 . 493a7d8294SWarner Losh.Sh MEMORY ALLOCATION 503a7d8294SWarner Losh.Bl -hang -width 10n 513a7d8294SWarner Losh.It Xo 523a7d8294SWarner Losh.Ft "void *" 533a7d8294SWarner Losh.Fn malloc "size_t size" 543a7d8294SWarner Losh.Xc 553a7d8294SWarner Losh.Pp 563a7d8294SWarner LoshAllocate 573a7d8294SWarner Losh.Fa size 583a7d8294SWarner Loshbytes of memory from the heap using a best-fit algorithm. 593a7d8294SWarner Losh.It Xo 603a7d8294SWarner Losh.Ft void 613a7d8294SWarner Losh.Fn free "void *ptr" 623a7d8294SWarner Losh.Xc 633a7d8294SWarner Losh.Pp 643a7d8294SWarner LoshFree the allocated object at 653a7d8294SWarner Losh.Fa ptr . 663a7d8294SWarner Losh.It Xo 673a7d8294SWarner Losh.Ft void 683a7d8294SWarner Losh.Fn setheap "void *start" "void *limit" 693a7d8294SWarner Losh.Xc 703a7d8294SWarner Losh.Pp 713a7d8294SWarner LoshInitialise the heap. 723a7d8294SWarner LoshThis function must be called before calling 733a7d8294SWarner Losh.Fn alloc 743a7d8294SWarner Loshfor the first time. 753a7d8294SWarner LoshThe region between 763a7d8294SWarner Losh.Fa start 773a7d8294SWarner Loshand 783a7d8294SWarner Losh.Fa limit 793a7d8294SWarner Loshwill be used for the heap; attempting to allocate beyond this will result 803a7d8294SWarner Loshin a panic. 813a7d8294SWarner Losh.It Xo 823a7d8294SWarner Losh.Ft "char *" 833a7d8294SWarner Losh.Fn sbrk "int junk" 843a7d8294SWarner Losh.Xc 853a7d8294SWarner Losh.Pp 863a7d8294SWarner LoshProvides the behaviour of 873a7d8294SWarner Losh.Fn sbrk 0 , 883a7d8294SWarner Loshi.e., returns the highest point that the heap has reached. 893a7d8294SWarner LoshThis value can 903a7d8294SWarner Loshbe used during testing to determine the actual heap usage. 913a7d8294SWarner LoshThe 923a7d8294SWarner Losh.Fa junk 933a7d8294SWarner Loshargument is ignored. 943a7d8294SWarner Losh.El 953a7d8294SWarner Losh.Sh ENVIRONMENT 963a7d8294SWarner LoshA set of functions are provided for manipulating a flat variable space similar 973a7d8294SWarner Loshto the traditional shell-supported environment. 983a7d8294SWarner LoshMajor enhancements are support 993a7d8294SWarner Loshfor set/unset hook functions. 1003a7d8294SWarner Losh.Bl -hang -width 10n 1013a7d8294SWarner Losh.It Xo 1023a7d8294SWarner Losh.Ft "char *" 1033a7d8294SWarner Losh.Fn getenv "const char *name" 1043a7d8294SWarner Losh.Xc 1053a7d8294SWarner Losh.It Xo 1063a7d8294SWarner Losh.Ft int 1073a7d8294SWarner Losh.Fn setenv "const char *name" "const char *value" "int overwrite" 1083a7d8294SWarner Losh.Xc 1093a7d8294SWarner Losh.It Xo 1103a7d8294SWarner Losh.Ft int 1113a7d8294SWarner Losh.Fn putenv "char *string" 1123a7d8294SWarner Losh.Xc 1133a7d8294SWarner Losh.It Xo 1143a7d8294SWarner Losh.Ft int 1153a7d8294SWarner Losh.Fn unsetenv "const char *name" 1163a7d8294SWarner Losh.Xc 1173a7d8294SWarner Losh.Pp 1183a7d8294SWarner LoshThese functions behave similarly to their standard library counterparts. 1193a7d8294SWarner Losh.It Xo 1203a7d8294SWarner Losh.Ft "struct env_var *" 1213a7d8294SWarner Losh.Fn env_getenv "const char *name" 1223a7d8294SWarner Losh.Xc 1233a7d8294SWarner Losh.Pp 1243a7d8294SWarner LoshLooks up a variable in the environment and returns its entire 1253a7d8294SWarner Loshdata structure. 1263a7d8294SWarner Losh.It Xo 1273a7d8294SWarner Losh.Ft int 1283a7d8294SWarner Losh.Fn env_setenv "const char *name" "int flags" "const void *value" "ev_sethook_t sethook" "ev_unsethook_t unsethook" 1293a7d8294SWarner Losh.Xc 1303a7d8294SWarner Losh.Pp 1313a7d8294SWarner LoshCreates a new or sets an existing environment variable called 1323a7d8294SWarner Losh.Fa name . 1333a7d8294SWarner LoshIf creating a new variable, the 1343a7d8294SWarner Losh.Fa sethook 1353a7d8294SWarner Loshand 1363a7d8294SWarner Losh.Fa unsethook 1373a7d8294SWarner Losharguments may be specified. 1383a7d8294SWarner Losh.Pp 1393a7d8294SWarner LoshThe set hook is invoked whenever an attempt 1403a7d8294SWarner Loshis made to set the variable, unless the EV_NOHOOK flag is set. 1413a7d8294SWarner LoshTypically 1423a7d8294SWarner Losha set hook will validate the 1433a7d8294SWarner Losh.Fa value 1443a7d8294SWarner Loshargument, and then call 1453a7d8294SWarner Losh.Fn env_setenv 1463a7d8294SWarner Loshagain with EV_NOHOOK set to actually save the value. 1473a7d8294SWarner LoshThe predefined function 1483a7d8294SWarner Losh.Fn env_noset 1493a7d8294SWarner Loshmay be specified to refuse all attempts to set a variable. 1503a7d8294SWarner Losh.Pp 1513a7d8294SWarner LoshThe unset hook is invoked when an attempt is made to unset a variable. 1523a7d8294SWarner LoshIf it 1533a7d8294SWarner Loshreturns zero, the variable will be unset. 1543a7d8294SWarner LoshThe predefined function 1553a7d8294SWarner Losh.Fa env_nounset 1563a7d8294SWarner Loshmay be used to prevent a variable being unset. 1573a7d8294SWarner Losh.El 1583a7d8294SWarner Losh.Sh STANDARD LIBRARY SUPPORT 1593a7d8294SWarner Losh.Bl -hang -width 10n 1603a7d8294SWarner Losh.It Xo 1613a7d8294SWarner Losh.Ft int 1623a7d8294SWarner Losh.Fn abs "int i" 1633a7d8294SWarner Losh.Xc 1643a7d8294SWarner Losh.It Xo 1653a7d8294SWarner Losh.Ft int 1663a7d8294SWarner Losh.Fn getopt "int argc" "char * const *argv" "const char *optstring" 1673a7d8294SWarner Losh.Xc 1683a7d8294SWarner Losh.It Xo 1693a7d8294SWarner Losh.Ft long 1703a7d8294SWarner Losh.Fn strtol "const char *nptr" "char **endptr" "int base" 1713a7d8294SWarner Losh.Xc 1723a7d8294SWarner Losh.It Xo 1733a7d8294SWarner Losh.Ft long long 1743a7d8294SWarner Losh.Fn strtoll "const char *nptr" "char **endptr" "int base" 1753a7d8294SWarner Losh.Xc 1763a7d8294SWarner Losh.It Xo 1773a7d8294SWarner Losh.Ft long 1783a7d8294SWarner Losh.Fn strtoul "const char *nptr" "char **endptr" "int base" 1793a7d8294SWarner Losh.Xc 1803a7d8294SWarner Losh.It Xo 1813a7d8294SWarner Losh.Ft long long 1823a7d8294SWarner Losh.Fn strtoull "const char *nptr" "char **endptr" "int base" 1833a7d8294SWarner Losh.Xc 1843a7d8294SWarner Losh.It Xo 1853a7d8294SWarner Losh.Ft void 1863a7d8294SWarner Losh.Fn srandom "unsigned int seed" 1873a7d8294SWarner Losh.Xc 1883a7d8294SWarner Losh.It Xo 1893a7d8294SWarner Losh.Ft "long" 1903a7d8294SWarner Losh.Fn random void 1913a7d8294SWarner Losh.Xc 1923a7d8294SWarner Losh.It Xo 1933a7d8294SWarner Losh.Ft "char *" 1943a7d8294SWarner Losh.Fn strerror "int error" 1953a7d8294SWarner Losh.Xc 1963a7d8294SWarner Losh.Pp 1973a7d8294SWarner LoshReturns error messages for the subset of errno values supported by 1983a7d8294SWarner Losh.Nm . 1993a7d8294SWarner Losh.It Fn assert expression 2003a7d8294SWarner Losh.Pp 2013a7d8294SWarner LoshRequires 2023a7d8294SWarner Losh.In assert.h . 2033a7d8294SWarner Losh.It Xo 2043a7d8294SWarner Losh.Ft int 2053a7d8294SWarner Losh.Fn setjmp "jmp_buf env" 2063a7d8294SWarner Losh.Xc 2073a7d8294SWarner Losh.It Xo 2083a7d8294SWarner Losh.Ft void 2093a7d8294SWarner Losh.Fn longjmp "jmp_buf env" "int val" 2103a7d8294SWarner Losh.Xc 2113a7d8294SWarner Losh.Pp 2123a7d8294SWarner LoshDefined as 2133a7d8294SWarner Losh.Fn _setjmp 2143a7d8294SWarner Loshand 2153a7d8294SWarner Losh.Fn _longjmp 2163a7d8294SWarner Loshrespectively as there is no signal state to manipulate. 2173a7d8294SWarner LoshRequires 2183a7d8294SWarner Losh.In setjmp.h . 2193a7d8294SWarner Losh.El 2203a7d8294SWarner Losh.Sh CHARACTER I/O 2213a7d8294SWarner Losh.Bl -hang -width 10n 2223a7d8294SWarner Losh.It Xo 2233a7d8294SWarner Losh.Ft void 2243a7d8294SWarner Losh.Fn gets "char *buf" 2253a7d8294SWarner Losh.Xc 2263a7d8294SWarner Losh.Pp 2273a7d8294SWarner LoshRead characters from the console into 2283a7d8294SWarner Losh.Fa buf . 2293a7d8294SWarner LoshAll of the standard cautions apply to this function. 2303a7d8294SWarner Losh.It Xo 2313a7d8294SWarner Losh.Ft void 2323a7d8294SWarner Losh.Fn ngets "char *buf" "int size" 2333a7d8294SWarner Losh.Xc 2343a7d8294SWarner Losh.Pp 2353a7d8294SWarner LoshRead at most 2363a7d8294SWarner Losh.Fa size 2373a7d8294SWarner Losh- 1 characters from the console into 2383a7d8294SWarner Losh.Fa buf . 2393a7d8294SWarner LoshIf 2403a7d8294SWarner Losh.Fa size 2413a7d8294SWarner Loshis less than 1, the function's behaviour is as for 2423a7d8294SWarner Losh.Fn gets . 2433a7d8294SWarner Losh.It Xo 2443a7d8294SWarner Losh.Ft int 2453a7d8294SWarner Losh.Fn fgetstr "char *buf" "int size" "int fd" 2463a7d8294SWarner Losh.Xc 2473a7d8294SWarner Losh.Pp 2483a7d8294SWarner LoshRead a line of at most 2493a7d8294SWarner Losh.Fa size 2503a7d8294SWarner Loshcharacters into 2513a7d8294SWarner Losh.Fa buf . 2523a7d8294SWarner LoshLine terminating characters are stripped, and the buffer is always 2533a7d8294SWarner Losh.Dv NUL 2543a7d8294SWarner Loshterminated. 2553a7d8294SWarner LoshReturns the number of characters in 2563a7d8294SWarner Losh.Fa buf 2573a7d8294SWarner Loshif successful, or -1 if a read error occurs. 2583a7d8294SWarner Losh.It Xo 2593a7d8294SWarner Losh.Ft int 2603a7d8294SWarner Losh.Fn printf "const char *fmt" "..." 2613a7d8294SWarner Losh.Xc 2623a7d8294SWarner Losh.It Xo 2633a7d8294SWarner Losh.Ft void 2643a7d8294SWarner Losh.Fn vprintf "const char *fmt" "va_list ap" 2653a7d8294SWarner Losh.Xc 2663a7d8294SWarner Losh.It Xo 2673a7d8294SWarner Losh.Ft int 2683a7d8294SWarner Losh.Fn sprintf "char *buf" "const char *fmt" "..." 2693a7d8294SWarner Losh.Xc 2703a7d8294SWarner Losh.It Xo 2713a7d8294SWarner Losh.Ft void 2723a7d8294SWarner Losh.Fn vsprintf "char *buf" "const char *fmt" "va_list ap" 2733a7d8294SWarner Losh.Xc 2743a7d8294SWarner Losh.Pp 2753a7d8294SWarner LoshThe *printf functions implement a subset of the standard 2763a7d8294SWarner Losh.Fn printf 2773a7d8294SWarner Loshfamily functionality and some extensions. 2783a7d8294SWarner LoshThe following standard conversions 2793a7d8294SWarner Loshare supported: c,d,n,o,p,s,u,x. 2803a7d8294SWarner LoshThe following modifiers are supported: 2813a7d8294SWarner Losh+,-,#,*,0,field width,precision,l. 2823a7d8294SWarner Losh.Pp 2833a7d8294SWarner LoshThe 2843a7d8294SWarner Losh.Li b 2853a7d8294SWarner Loshconversion is provided to decode error registers. 2863a7d8294SWarner LoshIts usage is: 2873a7d8294SWarner Losh.Bd -ragged -offset indent 2883a7d8294SWarner Loshprintf( 2893a7d8294SWarner Losh.Qq reg=%b\en , 2903a7d8294SWarner Loshregval, 2913a7d8294SWarner Losh.Qq <base><arg>* 2923a7d8294SWarner Losh); 2933a7d8294SWarner Losh.Ed 2943a7d8294SWarner Losh.Pp 2953a7d8294SWarner Loshwhere <base> is the output expressed as a control character, e.g.\& \e10 gives 2963a7d8294SWarner Loshoctal, \e20 gives hex. 2973a7d8294SWarner LoshEach <arg> is a sequence of characters, the first of 2983a7d8294SWarner Loshwhich gives the bit number to be inspected (origin 1) and the next characters 2993a7d8294SWarner Losh(up to a character less than 32) give the text to be displayed if the bit is set. 3003a7d8294SWarner LoshThus 3013a7d8294SWarner Losh.Bd -ragged -offset indent 3023a7d8294SWarner Loshprintf( 3033a7d8294SWarner Losh.Qq reg=%b\en , 3043a7d8294SWarner Losh3, 3053a7d8294SWarner Losh.Qq \e10\e2BITTWO\e1BITONE 3063a7d8294SWarner Losh); 3073a7d8294SWarner Losh.Ed 3083a7d8294SWarner Losh.Pp 3093a7d8294SWarner Loshwould give the output 3103a7d8294SWarner Losh.Bd -ragged -offset indent 3113a7d8294SWarner Loshreg=3<BITTWO,BITONE> 3123a7d8294SWarner Losh.Ed 3133a7d8294SWarner Losh.Pp 3143a7d8294SWarner LoshThe 3153a7d8294SWarner Losh.Li D 3163a7d8294SWarner Loshconversion provides a hexdump facility, e.g. 3173a7d8294SWarner Losh.Bd -ragged -offset indent 3183a7d8294SWarner Loshprintf( 3193a7d8294SWarner Losh.Qq %6D , 3203a7d8294SWarner Loshptr, 3213a7d8294SWarner Losh.Qq \&: 3223a7d8294SWarner Losh); gives 3233a7d8294SWarner Losh.Qq XX:XX:XX:XX:XX:XX 3243a7d8294SWarner Losh.Ed 3253a7d8294SWarner Losh.Bd -ragged -offset indent 3263a7d8294SWarner Loshprintf( 3273a7d8294SWarner Losh.Qq %*D , 3283a7d8294SWarner Loshlen, 3293a7d8294SWarner Loshptr, 3303a7d8294SWarner Losh.Qq "\ " 3313a7d8294SWarner Losh); gives 3323a7d8294SWarner Losh.Qq XX XX XX ... 3333a7d8294SWarner Losh.Ed 3343a7d8294SWarner Losh.El 3353a7d8294SWarner Losh.Sh CHARACTER TESTS AND CONVERSIONS 3363a7d8294SWarner Losh.Bl -hang -width 10n 3373a7d8294SWarner Losh.It Xo 3383a7d8294SWarner Losh.Ft int 3393a7d8294SWarner Losh.Fn isupper "int c" 3403a7d8294SWarner Losh.Xc 3413a7d8294SWarner Losh.It Xo 3423a7d8294SWarner Losh.Ft int 3433a7d8294SWarner Losh.Fn islower "int c" 3443a7d8294SWarner Losh.Xc 3453a7d8294SWarner Losh.It Xo 3463a7d8294SWarner Losh.Ft int 3473a7d8294SWarner Losh.Fn isspace "int c" 3483a7d8294SWarner Losh.Xc 3493a7d8294SWarner Losh.It Xo 3503a7d8294SWarner Losh.Ft int 3513a7d8294SWarner Losh.Fn isdigit "int c" 3523a7d8294SWarner Losh.Xc 3533a7d8294SWarner Losh.It Xo 3543a7d8294SWarner Losh.Ft int 3553a7d8294SWarner Losh.Fn isxdigit "int c" 3563a7d8294SWarner Losh.Xc 3573a7d8294SWarner Losh.It Xo 3583a7d8294SWarner Losh.Ft int 3593a7d8294SWarner Losh.Fn isascii "int c" 3603a7d8294SWarner Losh.Xc 3613a7d8294SWarner Losh.It Xo 3623a7d8294SWarner Losh.Ft int 3633a7d8294SWarner Losh.Fn isalpha "int c" 3643a7d8294SWarner Losh.Xc 3653a7d8294SWarner Losh.It Xo 3663a7d8294SWarner Losh.Ft int 3673a7d8294SWarner Losh.Fn isalnum "int c" 3683a7d8294SWarner Losh.Xc 3693a7d8294SWarner Losh.It Xo 3703a7d8294SWarner Losh.Ft int 3713a7d8294SWarner Losh.Fn iscntrl "int c" 3723a7d8294SWarner Losh.Xc 3733a7d8294SWarner Losh.It Xo 3743a7d8294SWarner Losh.Ft int 3753a7d8294SWarner Losh.Fn isgraph "int c" 3763a7d8294SWarner Losh.Xc 3773a7d8294SWarner Losh.It Xo 3783a7d8294SWarner Losh.Ft int 3793a7d8294SWarner Losh.Fn ispunct "int c" 3803a7d8294SWarner Losh.Xc 3813a7d8294SWarner Losh.It Xo 3823a7d8294SWarner Losh.Ft int 3833a7d8294SWarner Losh.Fn toupper "int c" 3843a7d8294SWarner Losh.Xc 3853a7d8294SWarner Losh.It Xo 3863a7d8294SWarner Losh.Ft int 3873a7d8294SWarner Losh.Fn tolower "int c" 3883a7d8294SWarner Losh.Xc 3893a7d8294SWarner Losh.El 3903a7d8294SWarner Losh.Sh FILE I/O 3913a7d8294SWarner Losh.Bl -hang -width 10n 3923a7d8294SWarner Losh.It Xo 3933a7d8294SWarner Losh.Ft int 3943a7d8294SWarner Losh.Fn open "const char *path" "int flags" 3953a7d8294SWarner Losh.Xc 3963a7d8294SWarner Losh.Pp 3973a7d8294SWarner LoshSimilar to the behaviour as specified in 3983a7d8294SWarner Losh.Xr open 2 , 3993a7d8294SWarner Loshexcept that file creation is not supported, so the mode parameter is not 4003a7d8294SWarner Loshrequired. 4013a7d8294SWarner LoshThe 4023a7d8294SWarner Losh.Fa flags 403f6b2a429SKyle Evansargument may be one of O_RDONLY, O_WRONLY and O_RDWR. 404f6b2a429SKyle EvansOnly UFS currently supports writing. 4053a7d8294SWarner Losh.It Xo 4063a7d8294SWarner Losh.Ft int 4073a7d8294SWarner Losh.Fn close "int fd" 4083a7d8294SWarner Losh.Xc 4093a7d8294SWarner Losh.It Xo 4103a7d8294SWarner Losh.Ft void 4113a7d8294SWarner Losh.Fn closeall void 4123a7d8294SWarner Losh.Xc 4133a7d8294SWarner Losh.Pp 4143a7d8294SWarner LoshClose all open files. 4153a7d8294SWarner Losh.It Xo 4163a7d8294SWarner Losh.Ft ssize_t 4173a7d8294SWarner Losh.Fn read "int fd" "void *buf" "size_t len" 4183a7d8294SWarner Losh.Xc 4193a7d8294SWarner Losh.It Xo 4203a7d8294SWarner Losh.Ft ssize_t 4213a7d8294SWarner Losh.Fn write "int fd" "void *buf" "size_t len" 4223a7d8294SWarner Losh.Xc 4233a7d8294SWarner Losh.Pp 4243a7d8294SWarner Losh(No file systems currently support writing.) 4253a7d8294SWarner Losh.It Xo 4263a7d8294SWarner Losh.Ft off_t 4273a7d8294SWarner Losh.Fn lseek "int fd" "off_t offset" "int whence" 4283a7d8294SWarner Losh.Xc 4293a7d8294SWarner Losh.Pp 4303a7d8294SWarner LoshFiles being automatically uncompressed during reading cannot seek backwards 4313a7d8294SWarner Loshfrom the current point. 4323a7d8294SWarner Losh.It Xo 4333a7d8294SWarner Losh.Ft int 4343a7d8294SWarner Losh.Fn stat "const char *path" "struct stat *sb" 4353a7d8294SWarner Losh.Xc 4363a7d8294SWarner Losh.It Xo 4373a7d8294SWarner Losh.Ft int 4383a7d8294SWarner Losh.Fn fstat "int fd" "struct stat *sb" 4393a7d8294SWarner Losh.Xc 4403a7d8294SWarner Losh.Pp 4413a7d8294SWarner LoshThe 4423a7d8294SWarner Losh.Fn stat 4433a7d8294SWarner Loshand 4443a7d8294SWarner Losh.Fn fstat 4453a7d8294SWarner Loshfunctions only fill out the following fields in the 4463a7d8294SWarner Losh.Fa sb 4473a7d8294SWarner Loshstructure: st_mode,st_nlink,st_uid,st_gid,st_size. 4483a7d8294SWarner LoshThe 4493a7d8294SWarner Losh.Nm tftp 4503a7d8294SWarner Loshfile system cannot provide meaningful values for this call, and the 4513a7d8294SWarner Losh.Nm cd9660 4523a7d8294SWarner Loshfile system always reports files having uid/gid of zero. 4533a7d8294SWarner Losh.El 4543a7d8294SWarner Losh.Sh PAGER 4553a7d8294SWarner LoshThe 4563a7d8294SWarner Losh.Nm 4573a7d8294SWarner Loshlibrary supplies a simple internal pager to ease reading the output of large 4583a7d8294SWarner Loshcommands. 4593a7d8294SWarner Losh.Bl -hang -width 10n 4603a7d8294SWarner Losh.It Xo 4613a7d8294SWarner Losh.Ft void 4623a7d8294SWarner Losh.Fn pager_open 4633a7d8294SWarner Losh.Xc 4643a7d8294SWarner Losh.Pp 4653a7d8294SWarner LoshInitialises the pager and tells it that the next line output will be the top of the 4663a7d8294SWarner Loshdisplay. 4673a7d8294SWarner LoshThe environment variable LINES is consulted to determine the number of 4683a7d8294SWarner Loshlines to be displayed before pausing. 4693a7d8294SWarner Losh.It Xo 4703a7d8294SWarner Losh.Ft void 4713a7d8294SWarner Losh.Fn pager_close void 4723a7d8294SWarner Losh.Xc 4733a7d8294SWarner Losh.Pp 4743a7d8294SWarner LoshCloses the pager. 4753a7d8294SWarner Losh.It Xo 4763a7d8294SWarner Losh.Ft int 4773a7d8294SWarner Losh.Fn pager_output "const char *lines" 4783a7d8294SWarner Losh.Xc 4793a7d8294SWarner Losh.Pp 4803a7d8294SWarner LoshSends the lines in the 4813a7d8294SWarner Losh.Dv NUL Ns 4823a7d8294SWarner Losh-terminated buffer at 4833a7d8294SWarner Losh.Fa lines 4843a7d8294SWarner Loshto the pager. 4853a7d8294SWarner LoshNewline characters are counted in order to determine the number 4863a7d8294SWarner Loshof lines being output (wrapped lines are not accounted for). 4873a7d8294SWarner LoshThe 4883a7d8294SWarner Losh.Fn pager_output 4893a7d8294SWarner Loshfunction will return zero when all of the lines have been output, or nonzero 4903a7d8294SWarner Loshif the display was paused and the user elected to quit. 4913a7d8294SWarner Losh.It Xo 4923a7d8294SWarner Losh.Ft int 4933a7d8294SWarner Losh.Fn pager_file "const char *fname" 4943a7d8294SWarner Losh.Xc 4953a7d8294SWarner Losh.Pp 4963a7d8294SWarner LoshAttempts to open and display the file 4973a7d8294SWarner Losh.Fa fname . 4983a7d8294SWarner LoshReturns -1 on error, 0 at EOF, or 1 if the user elects to quit while reading. 4993a7d8294SWarner Losh.El 500*1631382cSKyle Evans.Sh FEATURE SUPPORT 501*1631382cSKyle EvansA set of functions are provided to communicate support of features from the 502*1631382cSKyle Evansloader binary to the interpreter. 503*1631382cSKyle EvansThese are used to do something sensible if we are still operating with a loader 504*1631382cSKyle Evansbinary that behaves differently than expected. 505*1631382cSKyle Evans.Bl -hang -width 10n 506*1631382cSKyle Evans.It Xo 507*1631382cSKyle Evans.Ft void 508*1631382cSKyle Evans.Fn feature_enable "uint32_t mask" 509*1631382cSKyle Evans.Xc 510*1631382cSKyle Evans.Pp 511*1631382cSKyle EvansEnable the referenced 512*1631382cSKyle Evans.Fa mask 513*1631382cSKyle Evansfeature, which should be one of the 514*1631382cSKyle Evans.Li FEATURE_* 515*1631382cSKyle Evansmacros defined in 516*1631382cSKyle Evans.In stand.h . 517*1631382cSKyle Evans.It Xo 518*1631382cSKyle Evans.Ft bool 519*1631382cSKyle Evans.Fn feature_name_is_enabled "const char *name" 520*1631382cSKyle Evans.Xc 521*1631382cSKyle Evans.Pp 522*1631382cSKyle EvansCheck if the referenced 523*1631382cSKyle Evans.Fa name 524*1631382cSKyle Evansfeature is enabled. 525*1631382cSKyle EvansThe 526*1631382cSKyle Evans.Fa name 527*1631382cSKyle Evansis usually the same name as the 528*1631382cSKyle Evans.Li FEATURE_* 529*1631382cSKyle Evansmacro, but with the FEATURE_ prefix stripped off. 530*1631382cSKyle EvansThe authoritative source of feature names is the mapping table near the top in 531*1631382cSKyle Evans.Pa stand/libsa/features.c . 532*1631382cSKyle Evans.It Xo 533*1631382cSKyle Evans.Ft void 534*1631382cSKyle Evans.Fn "(feature_iter_fn)" "void *cookie" "const char *name" "const char *desc" "bool enabled" 535*1631382cSKyle Evans.Xc 536*1631382cSKyle Evans.Pp 537*1631382cSKyle EvansThe 538*1631382cSKyle Evans.Fa cookie 539*1631382cSKyle Evansargument is passed as-is from the argument of the same name to 540*1631382cSKyle Evans.Fn feature_iter . 541*1631382cSKyle EvansThe 542*1631382cSKyle Evans.Fa name 543*1631382cSKyle Evansand 544*1631382cSKyle Evans.Fa desc 545*1631382cSKyle Evansarguments are defined in the mapping table in 546*1631382cSKyle Evans.Pa stand/libsa/features.c . 547*1631382cSKyle EvansThe 548*1631382cSKyle Evans.Fa enabled 549*1631382cSKyle Evansargument indicates the current status of the feature, though one could 550*1631382cSKyle Evanstheoretically turn a feature off in later execution. 551*1631382cSKyle EvansAs such, this should likely not be trusted if it is needed after the iteration 552*1631382cSKyle Evanshas finished. 553*1631382cSKyle Evans.It Xo 554*1631382cSKyle Evans.Ft void 555*1631382cSKyle Evans.Fn "feature_iter" "feature_iter_fn *iter_fn" "void *cookie" 556*1631382cSKyle Evans.Xc 557*1631382cSKyle Evans.Pp 558*1631382cSKyle EvansIterate over the current set of features. 559*1631382cSKyle Evans.El 5603a7d8294SWarner Losh.Sh MISC 5613a7d8294SWarner Losh.Bl -hang -width 10n 5623a7d8294SWarner Losh.It Xo 56345ad9557SWarner Losh.Ft char * 56445ad9557SWarner Losh.Fn devformat "struct devdesc *" 56545ad9557SWarner Losh.Xc 56645ad9557SWarner Losh.Pp 56745ad9557SWarner LoshFormat the specified device as a string. 56845ad9557SWarner Losh.It Xo 569781ca0afSWarner Losh.Ft int 570781ca0afSWarner Losh.Fn devparse "struct devdesc **dev" "const char *devdesc" "const char **path" 571781ca0afSWarner Losh.Xc 572781ca0afSWarner Losh.Pp 573781ca0afSWarner LoshParse the 574781ca0afSWarner Losh.Dv devdesc 575781ca0afSWarner Loshstring of the form 576781ca0afSWarner Losh.Sq device:[/path/to/file] . 577781ca0afSWarner LoshThe 578781ca0afSWarner Losh.Dv devsw 579781ca0afSWarner Loshtable is used to match the start of the 580781ca0afSWarner Losh.Sq device 581781ca0afSWarner Loshstring with 582781ca0afSWarner Losh.Fa dv_name . 583781ca0afSWarner LoshIf 584781ca0afSWarner Losh.Fa dv_parsedev 585781ca0afSWarner Loshis non-NULL, then it will be called to parse the rest of the string and allocate 586781ca0afSWarner Loshthe 587781ca0afSWarner Losh.Dv struct devdesc 588781ca0afSWarner Loshfor this path. 589781ca0afSWarner LoshIf NULL, then a default routine will be called that will allocate a simple 590781ca0afSWarner Losh.Dv struct devdesc , 591781ca0afSWarner Loshparse a unit number and ensure there's no trailing characters. 592781ca0afSWarner LoshIf 593781ca0afSWarner Losh.Dv path 594781ca0afSWarner Loshis non-NULL, then a pointer to the remainder of the 595781ca0afSWarner Losh.Dv devdesc 596781ca0afSWarner Loshstring after the device specification is written. 597781ca0afSWarner Losh.It Xo 59866012c8fSWarner Losh.Ft int 59966012c8fSWarner Losh.Fn devinit void 60066012c8fSWarner LoshCalls all the 60166012c8fSWarner Losh.Fa dv_init 60266012c8fSWarner Loshroutines in the 60366012c8fSWarner Losh.Dv devsw 60466012c8fSWarner Losharray, returning the number of routines that returned an error. 60566012c8fSWarner Losh.It Xo 6063a7d8294SWarner Losh.Ft void 6073a7d8294SWarner Losh.Fn twiddle void 6083a7d8294SWarner Losh.Xc 6093a7d8294SWarner Losh.Pp 6103a7d8294SWarner LoshSuccessive calls emit the characters in the sequence |,/,-,\\ followed by a 6113a7d8294SWarner Loshbackspace in order to provide reassurance to the user. 6123a7d8294SWarner Losh.El 6133a7d8294SWarner Losh.Sh REQUIRED LOW-LEVEL SUPPORT 6143a7d8294SWarner LoshThe following resources are consumed by 6153a7d8294SWarner Losh.Nm 6163a7d8294SWarner Losh- stack, heap, console and devices. 6173a7d8294SWarner Losh.Pp 6183a7d8294SWarner LoshThe stack must be established before 6193a7d8294SWarner Losh.Nm 6203a7d8294SWarner Loshfunctions can be invoked. 6213a7d8294SWarner LoshStack requirements vary depending on the functions 6223a7d8294SWarner Loshand file systems used by the consumer and the support layer functions detailed 6233a7d8294SWarner Loshbelow. 6243a7d8294SWarner Losh.Pp 6253a7d8294SWarner LoshThe heap must be established before calling 6263a7d8294SWarner Losh.Fn alloc 6273a7d8294SWarner Loshor 6283a7d8294SWarner Losh.Fn open 6293a7d8294SWarner Loshby calling 6303a7d8294SWarner Losh.Fn setheap . 6313a7d8294SWarner LoshHeap usage will vary depending on the number of simultaneously open files, 6323a7d8294SWarner Loshas well as client behaviour. 6333a7d8294SWarner LoshAutomatic decompression will allocate more 6343a7d8294SWarner Loshthan 64K of data per open file. 6353a7d8294SWarner Losh.Pp 6363a7d8294SWarner LoshConsole access is performed via the 6373a7d8294SWarner Losh.Fn getchar , 6383a7d8294SWarner Losh.Fn putchar 6393a7d8294SWarner Loshand 6403a7d8294SWarner Losh.Fn ischar 6413a7d8294SWarner Loshfunctions detailed below. 6423a7d8294SWarner Losh.Pp 6433a7d8294SWarner LoshDevice access is initiated via 6443a7d8294SWarner Losh.Fn devopen 6453a7d8294SWarner Loshand is performed through the 6463a7d8294SWarner Losh.Fn dv_strategy , 6473a7d8294SWarner Losh.Fn dv_ioctl 6483a7d8294SWarner Loshand 6493a7d8294SWarner Losh.Fn dv_close 6503a7d8294SWarner Loshfunctions in the device switch structure that 6513a7d8294SWarner Losh.Fn devopen 6523a7d8294SWarner Loshreturns. 6533a7d8294SWarner Losh.Pp 6543a7d8294SWarner LoshThe consumer must provide the following support functions: 6553a7d8294SWarner Losh.Bl -hang -width 10n 6563a7d8294SWarner Losh.It Xo 6573a7d8294SWarner Losh.Ft int 6583a7d8294SWarner Losh.Fn getchar void 6593a7d8294SWarner Losh.Xc 6603a7d8294SWarner Losh.Pp 6613a7d8294SWarner LoshReturn a character from the console, used by 6623a7d8294SWarner Losh.Fn gets , 6633a7d8294SWarner Losh.Fn ngets 6643a7d8294SWarner Loshand pager functions. 6653a7d8294SWarner Losh.It Xo 6663a7d8294SWarner Losh.Ft int 6673a7d8294SWarner Losh.Fn ischar void 6683a7d8294SWarner Losh.Xc 6693a7d8294SWarner Losh.Pp 6703a7d8294SWarner LoshReturns nonzero if a character is waiting from the console. 6713a7d8294SWarner Losh.It Xo 6723a7d8294SWarner Losh.Ft void 6733a7d8294SWarner Losh.Fn putchar int 6743a7d8294SWarner Losh.Xc 6753a7d8294SWarner Losh.Pp 6763a7d8294SWarner LoshWrite a character to the console, used by 6773a7d8294SWarner Losh.Fn gets , 6783a7d8294SWarner Losh.Fn ngets , 6793a7d8294SWarner Losh.Fn *printf , 6803a7d8294SWarner Losh.Fn panic 6813a7d8294SWarner Loshand 6823a7d8294SWarner Losh.Fn twiddle 6833a7d8294SWarner Loshand thus by many other functions for debugging and informational output. 6843a7d8294SWarner Losh.It Xo 6853a7d8294SWarner Losh.Ft int 6863a7d8294SWarner Losh.Fn devopen "struct open_file *of" "const char *name" "const char **file" 6873a7d8294SWarner Losh.Xc 6883a7d8294SWarner Losh.Pp 6893a7d8294SWarner LoshOpen the appropriate device for the file named in 6903a7d8294SWarner Losh.Fa name , 6913a7d8294SWarner Loshreturning in 6923a7d8294SWarner Losh.Fa file 6933a7d8294SWarner Losha pointer to the remaining body of 6943a7d8294SWarner Losh.Fa name 6953a7d8294SWarner Loshwhich does not refer to the device. 6963a7d8294SWarner LoshThe 6973a7d8294SWarner Losh.Va f_dev 6983a7d8294SWarner Loshfield in 6993a7d8294SWarner Losh.Fa of 7003a7d8294SWarner Loshwill be set to point to the 7013a7d8294SWarner Losh.Vt devsw 7023a7d8294SWarner Loshstructure for the opened device if successful. 7033a7d8294SWarner LoshDevice identifiers must 7043a7d8294SWarner Loshalways precede the path component, but may otherwise be arbitrarily formatted. 7053a7d8294SWarner LoshUsed by 7063a7d8294SWarner Losh.Fn open 7073a7d8294SWarner Loshand thus for all device-related I/O. 7083a7d8294SWarner Losh.It Xo 7093a7d8294SWarner Losh.Ft int 7103a7d8294SWarner Losh.Fn devclose "struct open_file *of" 7113a7d8294SWarner Losh.Xc 7123a7d8294SWarner Losh.Pp 7133a7d8294SWarner LoshClose the device allocated for 7143a7d8294SWarner Losh.Fa of . 7153a7d8294SWarner LoshThe device driver itself will already have been called for the close; this call 7163a7d8294SWarner Loshshould clean up any allocation made by devopen only. 7173a7d8294SWarner Losh.It Xo 7183a7d8294SWarner Losh.Ft void 71945ad9557SWarner Losh.Fn __abort 7203a7d8294SWarner Losh.Xc 7213a7d8294SWarner Losh.Pp 7223a7d8294SWarner LoshCalls 7233a7d8294SWarner Losh.Fn panic 7243a7d8294SWarner Loshwith a fixed string. 7253a7d8294SWarner Losh.It Xo 7263a7d8294SWarner Losh.Ft void 7273a7d8294SWarner Losh.Fn panic "const char *msg" "..." 7283a7d8294SWarner Losh.Xc 7293a7d8294SWarner Losh.Pp 7303a7d8294SWarner LoshSignal a fatal and unrecoverable error condition. 7313a7d8294SWarner LoshThe 7323a7d8294SWarner Losh.Fa msg ... 7333a7d8294SWarner Losharguments are as for 7343a7d8294SWarner Losh.Fn printf . 7353a7d8294SWarner Losh.El 7363a7d8294SWarner Losh.Sh INTERNAL FILE SYSTEMS 7373a7d8294SWarner LoshInternal file systems are enabled by the consumer exporting the array 7383a7d8294SWarner Losh.Vt struct fs_ops *file_system[] , 7393a7d8294SWarner Loshwhich should be initialised with pointers 7403a7d8294SWarner Loshto 7413a7d8294SWarner Losh.Vt struct fs_ops 7423a7d8294SWarner Loshstructures. 7433a7d8294SWarner LoshThe following file system handlers are supplied by 7443a7d8294SWarner Losh.Nm , 7453a7d8294SWarner Loshthe consumer may supply other file systems of their own: 7463a7d8294SWarner Losh.Bl -hang -width ".Va cd9660_fsops" 7473a7d8294SWarner Losh.It Va ufs_fsops 7483a7d8294SWarner LoshThe 7493a7d8294SWarner Losh.Bx 7503a7d8294SWarner LoshUFS. 7513a7d8294SWarner Losh.It Va ext2fs_fsops 7523a7d8294SWarner LoshLinux ext2fs file system. 7533a7d8294SWarner Losh.It Va tftp_fsops 7543a7d8294SWarner LoshFile access via TFTP. 7553a7d8294SWarner Losh.It Va nfs_fsops 7563a7d8294SWarner LoshFile access via NFS. 7573a7d8294SWarner Losh.It Va cd9660_fsops 7583a7d8294SWarner LoshISO 9660 (CD-ROM) file system. 7593a7d8294SWarner Losh.It Va gzipfs_fsops 7603a7d8294SWarner LoshStacked file system supporting gzipped files. 7613a7d8294SWarner LoshWhen trying the gzipfs file system, 7623a7d8294SWarner Losh.Nm 7633a7d8294SWarner Loshappends 7643a7d8294SWarner Losh.Li .gz 7653a7d8294SWarner Loshto the end of the filename, and then tries to locate the file using the other 7663a7d8294SWarner Loshfile systems. 7673a7d8294SWarner LoshPlacement of this file system in the 7683a7d8294SWarner Losh.Va file_system[] 7693a7d8294SWarner Losharray determines whether gzipped files will be opened in preference to non-gzipped 7703a7d8294SWarner Loshfiles. 7713a7d8294SWarner LoshIt is only possible to seek a gzipped file forwards, and 7723a7d8294SWarner Losh.Fn stat 7733a7d8294SWarner Loshand 7743a7d8294SWarner Losh.Fn fstat 7753a7d8294SWarner Loshon gzipped files will report an invalid length. 7763a7d8294SWarner Losh.It Va bzipfs_fsops 7773a7d8294SWarner LoshThe same as 7783a7d8294SWarner Losh.Va gzipfs_fsops , 7793a7d8294SWarner Loshbut for 7803a7d8294SWarner Losh.Xr bzip2 1 Ns -compressed 7813a7d8294SWarner Loshfiles. 7823a7d8294SWarner Losh.El 7833a7d8294SWarner Losh.Pp 7843a7d8294SWarner LoshThe array of 7853a7d8294SWarner Losh.Vt struct fs_ops 7863a7d8294SWarner Loshpointers should be terminated with a NULL. 7873a7d8294SWarner Losh.Sh DEVICES 7883a7d8294SWarner LoshDevices are exported by the supporting code via the array 7893a7d8294SWarner Losh.Vt struct devsw *devsw[] 7903a7d8294SWarner Loshwhich is a NULL terminated array of pointers to device switch structures. 79145ad9557SWarner Losh.Sh DRIVER INTERFACE 79245ad9557SWarner LoshThe driver needs to provide a common set of entry points that are 79345ad9557SWarner Loshused by 79445ad9557SWarner Losh.Nm libsa 79545ad9557SWarner Loshto interface with the device. 79645ad9557SWarner Losh.Bd -literal 79745ad9557SWarner Loshstruct devsw { 79845ad9557SWarner Losh const char dv_name[DEV_NAMLEN]; 79945ad9557SWarner Losh int dv_type; 80045ad9557SWarner Losh int (*dv_init)(void); 80145ad9557SWarner Losh int (*dv_strategy)(void *devdata, int rw, daddr_t blk, 80245ad9557SWarner Losh size_t size, char *buf, size_t *rsize); 80345ad9557SWarner Losh int (*dv_open)(struct open_file *f, ...); 80445ad9557SWarner Losh int (*dv_close)(struct open_file *f); 80545ad9557SWarner Losh int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data); 80645ad9557SWarner Losh int (*dv_print)(int verbose); 80745ad9557SWarner Losh void (*dv_cleanup)(void); 808a0aad69fSWarner Losh char * (*dv_fmtdev)(struct devdesc *); 809a0aad69fSWarner Losh int (*dv_parsedev)(struct devdesc **dev, const char *devpart, 810a0aad69fSWarner Losh const char **path); 811a07cef5aSWarner Losh bool (*dv_match)(struct devsw *dv, const char *devspec); 81245ad9557SWarner Losh}; 81345ad9557SWarner Losh.Ed 81445ad9557SWarner Losh.Bl -tag -width ".Fn dv_strategy" 81545ad9557SWarner Losh.It Fn dv_name 81645ad9557SWarner LoshThe device's name. 81745ad9557SWarner Losh.It Fn dv_type 81845ad9557SWarner LoshType of device. 81945ad9557SWarner LoshThe supported types are: 82045ad9557SWarner Losh.Bl -tag -width "DEVT_NONE" 82145ad9557SWarner Losh.It DEVT_NONE 82245ad9557SWarner Losh.It DEVT_DISK 82345ad9557SWarner Losh.It DEVT_NET 82445ad9557SWarner Losh.It DEVT_CD 82545ad9557SWarner Losh.It DEVT_ZFS 82645ad9557SWarner Losh.It DEVT_FD 82745ad9557SWarner Losh.El 82845ad9557SWarner LoshEach type may have its own associated (struct type_devdesc), 82945ad9557SWarner Loshwhich has the generic (struct devdesc) as its first member. 83045ad9557SWarner Losh.It Fn dv_init 83145ad9557SWarner LoshDriver initialization routine. 83245ad9557SWarner LoshThis routine should probe for available units. 83345ad9557SWarner LoshDrivers are responsible for maintaining lists of units for later enumeration. 83445ad9557SWarner LoshNo other driver routines may be called before 83545ad9557SWarner Losh.Fn dv_init 83645ad9557SWarner Loshreturns. 83745ad9557SWarner Losh.It Fn dv_open 83845ad9557SWarner LoshThe driver open routine. 83945ad9557SWarner Losh.It Fn dv_close 84045ad9557SWarner LoshThe driver close routine. 84145ad9557SWarner Losh.It Fn dv_ioctl 84245ad9557SWarner LoshThe driver ioctl routine. 84345ad9557SWarner Losh.It Fn dv_print 84445ad9557SWarner LoshPrints information about the available devices. 84545ad9557SWarner LoshInformation should be presented with 84645ad9557SWarner Losh.Fn pager_output . 84745ad9557SWarner Losh.It Fn dv_cleanup 84845ad9557SWarner LoshCleans up any memory used by the device before the next stage is run. 84945ad9557SWarner Losh.It Fn dv_fmtdev 85045ad9557SWarner LoshConverts the specified devdesc to the canonical string representation 85145ad9557SWarner Loshfor that device. 852a0aad69fSWarner Losh.It Fn dv_parsedev 853a0aad69fSWarner LoshParses the device portion of a file path. 854a0aad69fSWarner LoshThe 855a0aad69fSWarner Losh.Dv devpart 856a0aad69fSWarner Loshwill point to the 857a0aad69fSWarner Losh.Sq tail 858a0aad69fSWarner Loshof device name, possibly followed by a colon and a path within the device. 859a0aad69fSWarner LoshThe 860a0aad69fSWarner Losh.Sq tail 861a0aad69fSWarner Loshis, by convention, the part of the device specification that follows the 862a0aad69fSWarner Losh.Fa dv_name 863a0aad69fSWarner Loshpart of the string. 864781ca0afSWarner LoshSo when 865781ca0afSWarner Losh.Fa devparse 866781ca0afSWarner Loshis parsing the string 867781ca0afSWarner Losh.Dq disk3p5:/xxx , 868a0aad69fSWarner Losh.Dv devpart 869a0aad69fSWarner Loshwill point to the 870a0aad69fSWarner Losh.Sq 3 871a0aad69fSWarner Loshin that string. 872a0aad69fSWarner LoshThe parsing routine is expected to allocate a new 873a0aad69fSWarner Losh.Dv struct devdesc 874a0aad69fSWarner Loshor subclass and return it in 875a0aad69fSWarner Losh.Dv dev 876a0aad69fSWarner Loshwhen successful. 877a0aad69fSWarner LoshThis routine should set 878a0aad69fSWarner Losh.Dv path 879a0aad69fSWarner Loshto point to the portion of the string after device specification, or 880a0aad69fSWarner Losh.Dq /xxx 881a0aad69fSWarner Loshin the earlier example. 882781ca0afSWarner LoshGenerally, code needing to parse a path will use 883781ca0afSWarner Losh.Fa devparse 884781ca0afSWarner Loshinstead of calling this routine directly. 885a07cef5aSWarner Losh.It Fn dv_match 886a07cef5aSWarner Losh.Dv NULL 887a07cef5aSWarner Loshto specify that all device paths starting with 888a07cef5aSWarner Losh.Fa dv_name 889a07cef5aSWarner Loshmatch. 890a07cef5aSWarner LoshOtherwise, this function returns 0 for a match and a non-zero 891a07cef5aSWarner Losh.Dv errno 892a07cef5aSWarner Loshto indicate why it didn't match. 893a07cef5aSWarner LoshThis is helpful when you claim the device path after using it to query 894a07cef5aSWarner Loshproperties on systems that have uniform naming for different types of 895a07cef5aSWarner Loshdevices. 89645ad9557SWarner Losh.El 8973a7d8294SWarner Losh.Sh HISTORY 8983a7d8294SWarner LoshThe 8993a7d8294SWarner Losh.Nm 9003a7d8294SWarner Loshlibrary contains contributions from many sources, including: 9013a7d8294SWarner Losh.Bl -bullet -compact 9023a7d8294SWarner Losh.It 9033a7d8294SWarner Losh.Nm libsa 9043a7d8294SWarner Loshfrom 9053a7d8294SWarner Losh.Nx 9063a7d8294SWarner Losh.It 9073a7d8294SWarner Losh.Nm libc 9083a7d8294SWarner Loshand 9093a7d8294SWarner Losh.Nm libkern 9103a7d8294SWarner Loshfrom 9113a7d8294SWarner Losh.Fx 3.0 . 9123a7d8294SWarner Losh.It 9133a7d8294SWarner Losh.Nm zalloc 9143a7d8294SWarner Loshfrom 9153a7d8294SWarner Losh.An Matthew Dillon Aq Mt dillon@backplane.com 9163a7d8294SWarner Losh.El 9173a7d8294SWarner Losh.Pp 9183a7d8294SWarner LoshThe reorganisation and port to 9193a7d8294SWarner Losh.Fx 3.0 , 9203a7d8294SWarner Loshthe environment functions and this manpage were written by 9213a7d8294SWarner Losh.An Mike Smith Aq Mt msmith@FreeBSD.org . 9223a7d8294SWarner Losh.Sh BUGS 9233a7d8294SWarner LoshThe lack of detailed memory usage data is unhelpful. 924