xref: /netbsd-src/share/man/man9/pathbuf.9 (revision fab6ef23746436b78c62492ff18ea0ec5399c49f)
1.\"     $NetBSD: pathbuf.9,v 1.2 2010/11/30 10:32:46 dholland Exp $
2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by David A. Holland.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd November 30, 2010
31.Dt PATHBUF 9
32.Os
33.Sh NAME
34.Nm pathbuf ,
35.Nm pathbuf_create ,
36.Nm pathbuf_assimilate ,
37.Nm pathbuf_copyin ,
38.Nm pathbuf_destroy
39.Nd path buffer abstraction
40.Sh SYNOPSIS
41.In sys/namei.h
42.Ft struct pathbuf *
43.Fn pathbuf_create "const char *path"
44.Ft struct pathbuf *
45.Fn pathbuf_assimilate "char *pnbuf"
46.Ft int
47.Fn pathbuf_copyin "const char *userpath" "struct pathbuf **ret"
48.Ft void
49.Fn pathbuf_destroy "struct pathbuf *path"
50.Sh DESCRIPTION
51The
52.Nm
53interface is used to carry around pathnames.
54This helps simplify the
55.Xr namei 9
56interface.
57A pathbuf should be thought of as a path name string combined with
58whatever flags and metadata are needed to interpret it correctly.
59It is an abstract type; the internals are hidden within the
60.Xr namei 9
61implementation.
62.Pp
63The
64.Fn pathbuf_create
65function allocates and initializes a new pathbuf containing a copy of
66the path string
67.Fa path ,
68which should be a kernel pointer.
69The return value should be checked for being
70.Dv NULL
71in case the system is out of memory.
72Passing a path name larger than
73.Dv PATH_MAX
74will cause an assertion failure.
75.Pp
76The
77.Fn pathbuf_copyin
78function allocates and initializes a new pathbuf containing a path
79string copied from user space with
80.Xr copyinstr 9 .
81It returns an error code.
82.Pp
83The
84.Fn pathbuf_assimilate
85function creates a pathbuf using the string buffer provided as
86.Fa pnbuf .
87This buffer must be of size
88.Dv PATH_MAX
89and must have been allocated with
90.Fn PNBUF_GET .
91The buffer is
92.Dq taken over
93by the returned pathbuf and will be released when the pathbuf is
94destroyed.
95Note: to avoid confusion and pointer bugs,
96.Fn pathbuf_assimilate
97should only be used where absolutely necessary; e.g. the NFS server
98code uses it to generate pathbufs from strings fetched from mbufs.
99.Pp
100The
101.Fn pathbuf_destroy
102function deallocates a pathbuf.
103Caution: because calling
104.Xr namei 9
105loads pointers to memory belonging to the pathbuf into the nameidata
106structure, a pathbuf should only be destroyed by the
107.Fn namei
108caller once all manipulations of the nameidata are complete.
109.Pp
110Also note that calling
111.Fn namei
112destroys the contents of the pathbuf.
113Do not reuse a pathbuf for a second call to
114.Fn namei .
115.Sh CODE REFERENCES
116The
117.Nm
118code is part of the name lookup code in
119.Pa sys/kern/vfs_lookup.c .
120.Sh SEE ALSO
121.Xr namei 9
122.Sh BUGS
123There are cases where it is necessary to get the path string left
124behind after
125.Fn namei
126has run.
127This produces an effect similar to
128.Xr realpath 3 .
129The interface for doing this is, for the time being, intentionally
130undocumented and subject to change.
131