1.\" 2.\" Copyright (c) 2003 Robert N. M. Watson. 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice(s), this list of conditions and the following disclaimer as 10.\" the first lines of this file unmodified other than the possible 11.\" addition of one or more copyright notices. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice(s), this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 17.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 20.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26.\" DAMAGE. 27.\" 28.\" $FreeBSD$ 29.\" 30.Dd January 11, 2004 31.Dt VN_FULLPATH 9 32.Os 33.Sh NAME 34.Nm vn_fullpath 35.Nd "Convert a vnode reference to a full pathname, given a process context" 36.Sh SYNOPSIS 37.In sys/param.h 38.In sys/vnode.h 39.Ft int 40.Fn vn_fullpath "struct thread *td" "struct vnode *vp" "char **retbuf" "char **freebuf" 41.Sh DESCRIPTION 42The 43.Fn 44function makes a "best effort" attempt to generate a string pathname for 45the passed (locked) vnode; the resulting path, if any, will be relative to 46the root directory of the process associated with the passed thread pointer. 47.Fn 48is implemented by inspecting the VFS name cache, and attempting to 49reconstruct a path from the process root to the object. 50.Pp 51This process is necessarily unreliable for several reasons: intermediate 52entries in the path may not be found in the cache; files may have more 53than one name (hard links), not all file systems use the name cache 54(specifically, most synthetic file systems don't); a single name may 55be used for more than one file (in the context of file systems covering 56other file systems); a file may have no name (if deleted but still 57open or referenced). 58However, the resulting string may still be more useable to a user than 59a vnode pointer value, or a device number and inode number. 60Code consuming the results of this function should anticipate (and 61properly handle) failure. 62.Pp 63Its arguments are: 64.Bl -tag -width freebuf 65.It Fa td 66The thread performing the call; this pointer will be dereferenced to find 67the process and its file descriptor structure, in order to identify the 68root vnode to use. 69.It Fa vp 70The vnode to search for; must be locked by the caller. 71.It Fa retbuf 72Pointer to a char * that vn_fullpath may (on success) point at a newly 73allocated buffer containing the resulting pathname. 74.It Fa freebuf 75Pointer to a char * that vn_fullpath may (on success) point at a buffer 76to be freed, when the caller is done with 77.Fa retbuf . 78.El 79.Pp 80Typical consumers will declare two character pointers: fullpath and 81freepath; they will set freepath to 82.Dv NULL , 83and fullpath to a name to use 84in the event that the call to 85.Fn 86fails. 87After done with the value of fullpath, the caller will check if freepath 88is non-NULL, and if so, invoke 89.Xr free 9 90with a pool type of 91.Dv M_TEMP . 92.Sh RETURN VALUES 93If the vnode is successfully converted to a pathname, 0 is returned; 94otherwise, an error number is returned. 95.Sh SEE ALSO 96.Xr free 9 97.Sh AUTHORS 98This man page was written by 99.An Robert Watson Aq rwatson@FreeBSD.org . 100