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.\" 28*fcb5a0a2SAlan Somers.Dd June 15, 2021 299b1faf0aSRobert Watson.Dt VN_FULLPATH 9 309b1faf0aSRobert Watson.Os 319b1faf0aSRobert Watson.Sh NAME 329b1faf0aSRobert Watson.Nm vn_fullpath 333f7440e2SRuslan Ermilov.Nd "convert a vnode reference to a full pathname, given a process context" 349b1faf0aSRobert Watson.Sh SYNOPSIS 359b1faf0aSRobert Watson.In sys/param.h 369b1faf0aSRobert Watson.In sys/vnode.h 379b1faf0aSRobert Watson.Ft int 383f7440e2SRuslan Ermilov.Fo vn_fullpath 39*fcb5a0a2SAlan Somers.Fa "struct vnode *vp" "char **retbuf" "char **freebuf" 403f7440e2SRuslan Ermilov.Fc 419b1faf0aSRobert Watson.Sh DESCRIPTION 429b1faf0aSRobert WatsonThe 433f7440e2SRuslan Ermilov.Fn vn_fullpath 443f7440e2SRuslan Ermilovfunction makes a 453f7440e2SRuslan Ermilov.Dq "best effort" 463f7440e2SRuslan Ermilovattempt to generate a string pathname for 47cc7d6b55SHiroki Satothe passed vnode; the resulting path, if any, will be relative to 489b1faf0aSRobert Watsonthe root directory of the process associated with the passed thread pointer. 493f7440e2SRuslan ErmilovThe 503f7440e2SRuslan Ermilov.Fn vn_fullpath 513f7440e2SRuslan Ermilovfunction 52480a1cc8SRobert Watsonis implemented by inspecting the VFS name cache, and attempting to 539b1faf0aSRobert Watsonreconstruct a path from the process root to the object. 549b1faf0aSRobert Watson.Pp 559b1faf0aSRobert WatsonThis process is necessarily unreliable for several reasons: intermediate 569b1faf0aSRobert Watsonentries in the path may not be found in the cache; files may have more 579b1faf0aSRobert Watsonthan one name (hard links), not all file systems use the name cache 583f7440e2SRuslan Ermilov(specifically, most synthetic file systems do not); a single name may 599b1faf0aSRobert Watsonbe used for more than one file (in the context of file systems covering 609b1faf0aSRobert Watsonother file systems); a file may have no name (if deleted but still 619b1faf0aSRobert Watsonopen or referenced). 629b1faf0aSRobert WatsonHowever, the resulting string may still be more useable to a user than 639b1faf0aSRobert Watsona vnode pointer value, or a device number and inode number. 649b1faf0aSRobert WatsonCode consuming the results of this function should anticipate (and 659b1faf0aSRobert Watsonproperly handle) failure. 669b1faf0aSRobert Watson.Pp 679b1faf0aSRobert WatsonIts arguments are: 683f7440e2SRuslan Ermilov.Bl -tag -width ".Fa freebuf" 699b1faf0aSRobert Watson.It Fa vp 707851d429SEdward Tomasz NapieralaThe vnode to search for. 717851d429SEdward Tomasz NapieralaNo need to be locked by the caller. 729b1faf0aSRobert Watson.It Fa retbuf 733f7440e2SRuslan ErmilovPointer to a 743f7440e2SRuslan Ermilov.Vt "char *" 753f7440e2SRuslan Ermilovthat 763f7440e2SRuslan Ermilov.Fn vn_fullpath 773f7440e2SRuslan Ermilovmay (on success) point at a newly 789b1faf0aSRobert Watsonallocated buffer containing the resulting pathname. 799b1faf0aSRobert Watson.It Fa freebuf 803f7440e2SRuslan ErmilovPointer to a 813f7440e2SRuslan Ermilov.Vt "char *" 823f7440e2SRuslan Ermilovthat 833f7440e2SRuslan Ermilov.Fn vn_fullpath 843f7440e2SRuslan Ermilovmay (on success) point at a buffer 859b1faf0aSRobert Watsonto be freed, when the caller is done with 869b1faf0aSRobert Watson.Fa retbuf . 879b1faf0aSRobert Watson.El 889b1faf0aSRobert Watson.Pp 893f7440e2SRuslan ErmilovTypical consumers will declare two character pointers: 903f7440e2SRuslan Ermilov.Va fullpath 913f7440e2SRuslan Ermilovand 923f7440e2SRuslan Ermilov.Va freepath ; 933f7440e2SRuslan Ermilovthey will set 943f7440e2SRuslan Ermilov.Va freepath 953f7440e2SRuslan Ermilovto 969b1faf0aSRobert Watson.Dv NULL , 973f7440e2SRuslan Ermilovand 983f7440e2SRuslan Ermilov.Va fullpath 993f7440e2SRuslan Ermilovto a name to use 1009b1faf0aSRobert Watsonin the event that the call to 1013f7440e2SRuslan Ermilov.Fn vn_fullpath 1029b1faf0aSRobert Watsonfails. 1033f7440e2SRuslan ErmilovAfter done with the value of 1043f7440e2SRuslan Ermilov.Va fullpath , 1053f7440e2SRuslan Ermilovthe caller will check if 1063f7440e2SRuslan Ermilov.Va freepath 1073f7440e2SRuslan Ermilovis 1083f7440e2SRuslan Ermilov.Pf non- Dv NULL , 1093f7440e2SRuslan Ermilovand if so, invoke 1109b1faf0aSRobert Watson.Xr free 9 1119b1faf0aSRobert Watsonwith a pool type of 1129b1faf0aSRobert Watson.Dv M_TEMP . 1139b1faf0aSRobert Watson.Sh RETURN VALUES 1149b1faf0aSRobert WatsonIf the vnode is successfully converted to a pathname, 0 is returned; 1159b1faf0aSRobert Watsonotherwise, an error number is returned. 1169b1faf0aSRobert Watson.Sh SEE ALSO 1179b1faf0aSRobert Watson.Xr free 9 1189b1faf0aSRobert Watson.Sh AUTHORS 119571dba6eSHiten PandyaThis manual page was written by 1208a7314fcSBaptiste Daroussin.An Robert Watson Aq Mt rwatson@FreeBSD.org . 121