xref: /netbsd-src/share/man/man9/pathbuf.9 (revision fab6ef23746436b78c62492ff18ea0ec5399c49f)
1*fab6ef23Sdholland.\"     $NetBSD: pathbuf.9,v 1.2 2010/11/30 10:32:46 dholland Exp $
28f6ed30dSdholland.\"
38f6ed30dSdholland.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
48f6ed30dSdholland.\" All rights reserved.
58f6ed30dSdholland.\"
68f6ed30dSdholland.\" This code is derived from software contributed to The NetBSD Foundation
78f6ed30dSdholland.\" by David A. Holland.
88f6ed30dSdholland.\"
98f6ed30dSdholland.\" Redistribution and use in source and binary forms, with or without
108f6ed30dSdholland.\" modification, are permitted provided that the following conditions
118f6ed30dSdholland.\" are met:
128f6ed30dSdholland.\" 1. Redistributions of source code must retain the above copyright
138f6ed30dSdholland.\"    notice, this list of conditions and the following disclaimer.
148f6ed30dSdholland.\" 2. Redistributions in binary form must reproduce the above copyright
158f6ed30dSdholland.\"    notice, this list of conditions and the following disclaimer in the
168f6ed30dSdholland.\"    documentation and/or other materials provided with the distribution.
178f6ed30dSdholland.\"
188f6ed30dSdholland.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
198f6ed30dSdholland.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
208f6ed30dSdholland.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
218f6ed30dSdholland.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
228f6ed30dSdholland.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
238f6ed30dSdholland.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
248f6ed30dSdholland.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
258f6ed30dSdholland.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
268f6ed30dSdholland.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
278f6ed30dSdholland.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
288f6ed30dSdholland.\" POSSIBILITY OF SUCH DAMAGE.
298f6ed30dSdholland.\"
30*fab6ef23Sdholland.Dd November 30, 2010
318f6ed30dSdholland.Dt PATHBUF 9
328f6ed30dSdholland.Os
338f6ed30dSdholland.Sh NAME
348f6ed30dSdholland.Nm pathbuf ,
358f6ed30dSdholland.Nm pathbuf_create ,
36*fab6ef23Sdholland.Nm pathbuf_assimilate ,
378f6ed30dSdholland.Nm pathbuf_copyin ,
388f6ed30dSdholland.Nm pathbuf_destroy
398f6ed30dSdholland.Nd path buffer abstraction
408f6ed30dSdholland.Sh SYNOPSIS
418f6ed30dSdholland.In sys/namei.h
428f6ed30dSdholland.Ft struct pathbuf *
438f6ed30dSdholland.Fn pathbuf_create "const char *path"
44*fab6ef23Sdholland.Ft struct pathbuf *
45*fab6ef23Sdholland.Fn pathbuf_assimilate "char *pnbuf"
468f6ed30dSdholland.Ft int
478f6ed30dSdholland.Fn pathbuf_copyin "const char *userpath" "struct pathbuf **ret"
488f6ed30dSdholland.Ft void
498f6ed30dSdholland.Fn pathbuf_destroy "struct pathbuf *path"
508f6ed30dSdholland.Sh DESCRIPTION
518f6ed30dSdhollandThe
528f6ed30dSdholland.Nm
538f6ed30dSdhollandinterface is used to carry around pathnames.
548f6ed30dSdhollandThis helps simplify the
558f6ed30dSdholland.Xr namei 9
568f6ed30dSdhollandinterface.
578f6ed30dSdhollandA pathbuf should be thought of as a path name string combined with
588f6ed30dSdhollandwhatever flags and metadata are needed to interpret it correctly.
598f6ed30dSdhollandIt is an abstract type; the internals are hidden within the
608f6ed30dSdholland.Xr namei 9
618f6ed30dSdhollandimplementation.
628f6ed30dSdholland.Pp
638f6ed30dSdhollandThe
648f6ed30dSdholland.Fn pathbuf_create
658f6ed30dSdhollandfunction allocates and initializes a new pathbuf containing a copy of
668f6ed30dSdhollandthe path string
678f6ed30dSdholland.Fa path ,
688f6ed30dSdhollandwhich should be a kernel pointer.
698f6ed30dSdhollandThe return value should be checked for being
708f6ed30dSdholland.Dv NULL
718f6ed30dSdhollandin case the system is out of memory.
728f6ed30dSdhollandPassing a path name larger than
738f6ed30dSdholland.Dv PATH_MAX
748f6ed30dSdhollandwill cause an assertion failure.
758f6ed30dSdholland.Pp
768f6ed30dSdhollandThe
778f6ed30dSdholland.Fn pathbuf_copyin
788f6ed30dSdhollandfunction allocates and initializes a new pathbuf containing a path
798f6ed30dSdhollandstring copied from user space with
808f6ed30dSdholland.Xr copyinstr 9 .
818f6ed30dSdhollandIt returns an error code.
828f6ed30dSdholland.Pp
838f6ed30dSdhollandThe
84*fab6ef23Sdholland.Fn pathbuf_assimilate
85*fab6ef23Sdhollandfunction creates a pathbuf using the string buffer provided as
86*fab6ef23Sdholland.Fa pnbuf .
87*fab6ef23SdhollandThis buffer must be of size
88*fab6ef23Sdholland.Dv PATH_MAX
89*fab6ef23Sdhollandand must have been allocated with
90*fab6ef23Sdholland.Fn PNBUF_GET .
91*fab6ef23SdhollandThe buffer is
92*fab6ef23Sdholland.Dq taken over
93*fab6ef23Sdhollandby the returned pathbuf and will be released when the pathbuf is
94*fab6ef23Sdhollanddestroyed.
95*fab6ef23SdhollandNote: to avoid confusion and pointer bugs,
96*fab6ef23Sdholland.Fn pathbuf_assimilate
97*fab6ef23Sdhollandshould only be used where absolutely necessary; e.g. the NFS server
98*fab6ef23Sdhollandcode uses it to generate pathbufs from strings fetched from mbufs.
99*fab6ef23Sdholland.Pp
100*fab6ef23SdhollandThe
1018f6ed30dSdholland.Fn pathbuf_destroy
1028f6ed30dSdhollandfunction deallocates a pathbuf.
1038f6ed30dSdhollandCaution: because calling
1048f6ed30dSdholland.Xr namei 9
1058f6ed30dSdhollandloads pointers to memory belonging to the pathbuf into the nameidata
1068f6ed30dSdhollandstructure, a pathbuf should only be destroyed by the
1078f6ed30dSdholland.Fn namei
1088f6ed30dSdhollandcaller once all manipulations of the nameidata are complete.
1098f6ed30dSdholland.Pp
1108f6ed30dSdhollandAlso note that calling
1118f6ed30dSdholland.Fn namei
1128f6ed30dSdhollanddestroys the contents of the pathbuf.
1138f6ed30dSdhollandDo not reuse a pathbuf for a second call to
1148f6ed30dSdholland.Fn namei .
1158f6ed30dSdholland.Sh CODE REFERENCES
1168f6ed30dSdhollandThe
1178f6ed30dSdholland.Nm
1188f6ed30dSdhollandcode is part of the name lookup code in
1198f6ed30dSdholland.Pa sys/kern/vfs_lookup.c .
1208f6ed30dSdholland.Sh SEE ALSO
1218f6ed30dSdholland.Xr namei 9
1228f6ed30dSdholland.Sh BUGS
1238f6ed30dSdhollandThere are cases where it is necessary to get the path string left
1248f6ed30dSdhollandbehind after
1258f6ed30dSdholland.Fn namei
1268f6ed30dSdhollandhas run.
1278f6ed30dSdhollandThis produces an effect similar to
1288f6ed30dSdholland.Xr realpath 3 .
1298f6ed30dSdhollandThe interface for doing this is, for the time being, intentionally
1308f6ed30dSdhollandundocumented and subject to change.
131