Re: Classify VNODE SCOPE actions for file operations
Re: Classify VNODE SCOPE actions for file operations
- Subject: Re: Classify VNODE SCOPE actions for file operations
- From: Paul Nelson <email@hidden>
- Date: Thu, 07 Apr 2011 10:44:47 -0500
On Apr 7, 2011, at 9:39 AM, Ken Hornstein wrote:
>>
>> 1. When I create a new file I get KAUTH_VNODE_ADD_FILE. Here vp is
>> returned as the directory in which the file gets created and dvp is
>> NULL. Is there a way for me to get the name of the newly created file.
>
> It would seem the answer is ... no. At least not via kauth. It looks like
> it would require some changes internally; right now you would need to get
> passed in the struct nameidata down, and vnode_authorize only takes two
> vnodes as arguments.
You could use vn_getpath (see vnode.h) but it does not ask the filesystem for names, so it can't handle hard link nodes, and might return an error.
It is not that hard to use getattrlist inside a kernel. This is the best way to get the name of a vnode.
Just fill out the vnop_getattr_args and call VNOP_GETATTRLIST. For example:
given vp is the vnode pointer:
struct vnop_getattr a;
VATTR_INIT(&a);
VATTR_WANTED(&a, va_name);
// MAXPATHLEN is what vnode.h says to pass
MALLOC( a.va_name, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
int res = VNOP_GETATTR( vp, &a, context);
if( res == 0 )
{
if( VATTR_IS_SUPPORTED(&a, va_name) )
printf("vp %p is %s\n", vp, a.va_name ? a.va_name : "//not available//");
else
printf("filesystem does not support getting va_name\n");
}
if( a.va_name )
FREE(a.va_name, M_TEMP);
If you don't have a context, you can make one yourself using vfs_context_create(NULL), release with vfs_context_rele(context)
This only returns the name of the vnode. If you want to build a path, you have to do that yourself, but be aware that hard links can be tricky. Look at Apple's source code for build_path in bsd/vfs/vfs_cache.c
Using getattrlist stuff is MUCH easier inside the kernel than from user space since there is no packing and unpacking. VNOP_GETATTR has almost zero overhead, taking you right into the file system. The filesystem may not always cooperate however.
Paul Nelson
Thursby Software Systems, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden