vn_fullpath (9)
Leading comments
Copyright (c) 2003 Robert N. M. Watson. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice(s), this list of conditions and the following disclaimer as the first lines of this file unmodified other than the possible addition of one or more copyright notices. 2. Redistributions in binary form must repr...
NAME
vn_fullpath - convert a vnode reference to a full pathname, given a process contextSYNOPSIS
In sys/param.h In sys/vnode.h Ft int Fo vn_fullpath Fa struct thread *td struct vnode *vp char **retbuf char **freebuf FcDESCRIPTION
The Fn vn_fullpath function makes a ``best effort'' attempt to generate a string pathname for the passed vnode; the resulting path, if any, will be relative to the root directory of the process associated with the passed thread pointer. The Fn vn_fullpath function is implemented by inspecting the VFS name cache, and attempting to reconstruct a path from the process root to the object.This process is necessarily unreliable for several reasons: intermediate entries in the path may not be found in the cache; files may have more than one name (hard links), not all file systems use the name cache (specifically, most synthetic file systems do not); a single name may be used for more than one file (in the context of file systems covering other file systems); a file may have no name (if deleted but still open or referenced). However, the resulting string may still be more useable to a user than a vnode pointer value, or a device number and inode number. Code consuming the results of this function should anticipate (and properly handle) failure.
Its arguments are:
- Fa td
- The thread performing the call; this pointer will be dereferenced to find the process and its file descriptor structure, in order to identify the root vnode to use.
- Fa vp
- The vnode to search for. No need to be locked by the caller.
- Fa retbuf
- Pointer to a Vt char * that Fn vn_fullpath may (on success) point at a newly allocated buffer containing the resulting pathname.
- Fa freebuf
- Pointer to a Vt char * that Fn vn_fullpath may (on success) point at a buffer to be freed, when the caller is done with Fa retbuf .
Typical consumers will declare two character pointers: fullpath and freepath they will set freepath to NULL and fullpath to a name to use in the event that the call to Fn vn_fullpath fails. After done with the value of fullpath the caller will check if freepath is non- NULL and if so, invoke free(9) with a pool type of M_TEMP