xref: /freebsd/share/man/man9/vn_fullpath.9 (revision 571dba6ec9f25ecf7582dc2192daf1ceea70065f)
19b1faf0aSRobert Watson.\"
29b1faf0aSRobert Watson.\" Copyright (c) 2003 Robert N. M. Watson.
39b1faf0aSRobert Watson.\" All rights reserved.
49b1faf0aSRobert Watson.\"
59b1faf0aSRobert Watson.\" Redistribution and use in source and binary forms, with or without
69b1faf0aSRobert Watson.\" modification, are permitted provided that the following conditions
79b1faf0aSRobert Watson.\" are met:
89b1faf0aSRobert Watson.\" 1. Redistributions of source code must retain the above copyright
99b1faf0aSRobert Watson.\"    notice(s), this list of conditions and the following disclaimer as
109b1faf0aSRobert Watson.\"    the first lines of this file unmodified other than the possible
119b1faf0aSRobert Watson.\"    addition of one or more copyright notices.
129b1faf0aSRobert Watson.\" 2. Redistributions in binary form must reproduce the above copyright
139b1faf0aSRobert Watson.\"    notice(s), this list of conditions and the following disclaimer in the
149b1faf0aSRobert Watson.\"    documentation and/or other materials provided with the distribution.
159b1faf0aSRobert Watson.\"
169b1faf0aSRobert Watson.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
179b1faf0aSRobert Watson.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
189b1faf0aSRobert Watson.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
199b1faf0aSRobert Watson.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
209b1faf0aSRobert Watson.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
219b1faf0aSRobert Watson.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
229b1faf0aSRobert Watson.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
239b1faf0aSRobert Watson.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249b1faf0aSRobert Watson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259b1faf0aSRobert Watson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
269b1faf0aSRobert Watson.\" DAMAGE.
279b1faf0aSRobert Watson.\"
289b1faf0aSRobert Watson.\" $FreeBSD$
299b1faf0aSRobert Watson.\"
309b1faf0aSRobert Watson.Dd January 11, 2004
319b1faf0aSRobert Watson.Dt VN_FULLPATH 9
329b1faf0aSRobert Watson.Os
339b1faf0aSRobert Watson.Sh NAME
349b1faf0aSRobert Watson.Nm vn_fullpath
353f7440e2SRuslan Ermilov.Nd "convert a vnode reference to a full pathname, given a process context"
369b1faf0aSRobert Watson.Sh SYNOPSIS
379b1faf0aSRobert Watson.In sys/param.h
389b1faf0aSRobert Watson.In sys/vnode.h
399b1faf0aSRobert Watson.Ft int
403f7440e2SRuslan Ermilov.Fo vn_fullpath
413f7440e2SRuslan Ermilov.Fa "struct thread *td" "struct vnode *vp" "char **retbuf" "char **freebuf"
423f7440e2SRuslan Ermilov.Fc
439b1faf0aSRobert Watson.Sh DESCRIPTION
449b1faf0aSRobert WatsonThe
453f7440e2SRuslan Ermilov.Fn vn_fullpath
463f7440e2SRuslan Ermilovfunction makes a
473f7440e2SRuslan Ermilov.Dq "best effort"
483f7440e2SRuslan Ermilovattempt to generate a string pathname for
499b1faf0aSRobert Watsonthe passed (locked) vnode; the resulting path, if any, will be relative to
509b1faf0aSRobert Watsonthe root directory of the process associated with the passed thread pointer.
513f7440e2SRuslan ErmilovThe
523f7440e2SRuslan Ermilov.Fn vn_fullpath
533f7440e2SRuslan Ermilovfunction
54480a1cc8SRobert Watsonis implemented by inspecting the VFS name cache, and attempting to
559b1faf0aSRobert Watsonreconstruct a path from the process root to the object.
569b1faf0aSRobert Watson.Pp
579b1faf0aSRobert WatsonThis process is necessarily unreliable for several reasons: intermediate
589b1faf0aSRobert Watsonentries in the path may not be found in the cache; files may have more
599b1faf0aSRobert Watsonthan one name (hard links), not all file systems use the name cache
603f7440e2SRuslan Ermilov(specifically, most synthetic file systems do not); a single name may
619b1faf0aSRobert Watsonbe used for more than one file (in the context of file systems covering
629b1faf0aSRobert Watsonother file systems); a file may have no name (if deleted but still
639b1faf0aSRobert Watsonopen or referenced).
649b1faf0aSRobert WatsonHowever, the resulting string may still be more useable to a user than
659b1faf0aSRobert Watsona vnode pointer value, or a device number and inode number.
669b1faf0aSRobert WatsonCode consuming the results of this function should anticipate (and
679b1faf0aSRobert Watsonproperly handle) failure.
689b1faf0aSRobert Watson.Pp
699b1faf0aSRobert WatsonIts arguments are:
703f7440e2SRuslan Ermilov.Bl -tag -width ".Fa freebuf"
719b1faf0aSRobert Watson.It Fa td
729b1faf0aSRobert WatsonThe thread performing the call; this pointer will be dereferenced to find
739b1faf0aSRobert Watsonthe process and its file descriptor structure, in order to identify the
749b1faf0aSRobert Watsonroot vnode to use.
759b1faf0aSRobert Watson.It Fa vp
769b1faf0aSRobert WatsonThe vnode to search for; must be locked by the caller.
779b1faf0aSRobert Watson.It Fa retbuf
783f7440e2SRuslan ErmilovPointer to a
793f7440e2SRuslan Ermilov.Vt "char *"
803f7440e2SRuslan Ermilovthat
813f7440e2SRuslan Ermilov.Fn vn_fullpath
823f7440e2SRuslan Ermilovmay (on success) point at a newly
839b1faf0aSRobert Watsonallocated buffer containing the resulting pathname.
849b1faf0aSRobert Watson.It Fa freebuf
853f7440e2SRuslan ErmilovPointer to a
863f7440e2SRuslan Ermilov.Vt "char *"
873f7440e2SRuslan Ermilovthat
883f7440e2SRuslan Ermilov.Fn vn_fullpath
893f7440e2SRuslan Ermilovmay (on success) point at a buffer
909b1faf0aSRobert Watsonto be freed, when the caller is done with
919b1faf0aSRobert Watson.Fa retbuf .
929b1faf0aSRobert Watson.El
939b1faf0aSRobert Watson.Pp
943f7440e2SRuslan ErmilovTypical consumers will declare two character pointers:
953f7440e2SRuslan Ermilov.Va fullpath
963f7440e2SRuslan Ermilovand
973f7440e2SRuslan Ermilov.Va freepath ;
983f7440e2SRuslan Ermilovthey will set
993f7440e2SRuslan Ermilov.Va freepath
1003f7440e2SRuslan Ermilovto
1019b1faf0aSRobert Watson.Dv NULL ,
1023f7440e2SRuslan Ermilovand
1033f7440e2SRuslan Ermilov.Va fullpath
1043f7440e2SRuslan Ermilovto a name to use
1059b1faf0aSRobert Watsonin the event that the call to
1063f7440e2SRuslan Ermilov.Fn vn_fullpath
1079b1faf0aSRobert Watsonfails.
1083f7440e2SRuslan ErmilovAfter done with the value of
1093f7440e2SRuslan Ermilov.Va fullpath ,
1103f7440e2SRuslan Ermilovthe caller will check if
1113f7440e2SRuslan Ermilov.Va freepath
1123f7440e2SRuslan Ermilovis
1133f7440e2SRuslan Ermilov.Pf non- Dv NULL ,
1143f7440e2SRuslan Ermilovand if so, invoke
1159b1faf0aSRobert Watson.Xr free 9
1169b1faf0aSRobert Watsonwith a pool type of
1179b1faf0aSRobert Watson.Dv M_TEMP .
1189b1faf0aSRobert Watson.Sh RETURN VALUES
1199b1faf0aSRobert WatsonIf the vnode is successfully converted to a pathname, 0 is returned;
1209b1faf0aSRobert Watsonotherwise, an error number is returned.
1219b1faf0aSRobert Watson.Sh SEE ALSO
1229b1faf0aSRobert Watson.Xr free 9
1239b1faf0aSRobert Watson.Sh AUTHORS
124571dba6eSHiten PandyaThis manual page was written by
1259b1faf0aSRobert Watson.An Robert Watson Aq rwatson@FreeBSD.org .
126