PATHBUF(9)
okay so bestie, welcome to the PATHBUF(9) page from the Kernel Developer's Manual π«Άβ¨ this one is lowkey iconic.
π NAME π
pathbuf, pathbuf_create, pathbuf_assimilate, pathbuf_copyin, pathbuf_destroy β path buffer abstraction. periodt π
πΈ SYNOPSIS πΈ
#include <sys/namei.h>
struct pathbuf *
pathbuf_create(const char *path);
struct pathbuf *
pathbuf_assimilate(char *pnbuf);
int
pathbuf_copyin(const char *userpath, struct pathbuf **ret);
void
pathbuf_destroy(struct pathbuf *path);
π¦ DESCRIPTION π¦
okay so the pathbuf interface is used to carry around pathnames, and it helps simplify the namei(9) interface β¨ A pathbuf should be thought of as a path name string combined with whatever flags and metadata are needed to interpret it correctly. It is an abstract type; the internals are hidden within the namei(9) implementation π
pathbuf_create()β allocates and initializes a newpathbufcontaining a copy of the path string path, which should be a kernel pointer. Check the return value for beingNULLin case the system is out of memory π. Passing a path name larger thanPATH_MAXwill cause an assertion failure β so do not do that bestie πpathbuf_copyin()β allocates and initializes a newpathbufcontaining a path string copied from user space withcopyinstr(9). It returns an error code.pathbuf_assimilate()β creates apathbufusing the string buffer provided as pnbuf. This buffer must be of sizePATH_MAXand must have been allocated withPNBUF_GET(). The buffer is βtaken overβ by the returnedpathbufand will be released when thepathbufis destroyed π
Note: to avoid confusion and pointer bugs,pathbuf_assimilate()should only be used where absolutely necessary; e.g. the NFS server code uses it to generate pathbufs from strings fetched frommbufs.
pathbuf_destroy()β deallocates apathbuf.
Caution: because callingnamei(9)loads pointers to memory belonging to thepathbufinto thenameidatastructure, apathbufshould only be destroyed by thenamei()caller once all manipulations of thenameidataare complete.
Also note that calling namei() destroys the contents of the pathbuf. Do not reuse a pathbuf for a second call to namei() π
π§ CODE REFERENCES π§
The pathbuf code is part of the name lookup code in sys/kern/vfs_lookup.c.
π SEE ALSO π
π BUGS π
There are cases where it is necessary to get the path string left behind after namei() has run. This produces an effect similar to realpath(3). The interface for doing this is, for the time being, intentionally undocumented and subject to change β itβs giving mystery on purpose πβ¨
okay bye bestie β this page is from Debian, dated November 30, 2010 ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms