On Wed, Apr 13, 2011 at 3:25 PM, Jonathan Stuart <[email protected]> wrote:
> Hi,
>
> Yes, I am.. that was my suspicion (e.g., that it was the parameters of the
> process which called open()/creat()/socket()/... originally). What's the
> quickest way to get back to the v/inode's uid/gid?
>
Since you have a struct mount * and an inode, it should be something like:
void
test_uidgid(struct mount *mp, ino_t ino)
{
struct vnode *vp;
struct inode *ip;
int error;
error = VFS_VGET(mp, ino, LK_SHARED, &vp);
if (error != 0) {
printf("Got error %d\n", error);
return;
}
ip = VTOI(vp);
printf("For inode %x, uid is %d, gid is %d\n", ino, ip->i_uid,
ip->i_gid);
vput(vp);
}
> Also, calling VFS_VGET() seems to give me a lockmgr panic with unknown type
> 0x0.
> What is odd is that the only way I can get a vnode for VFS_VGET is through
> struct file, and then shouldn't I be able to use that? I tried using the
> flipping that vnode->inode with VTOI() and it was also giving me zeros for
> i_uid, i_gid, etc., when it shouldn't have been.
>
VFS_VGET gives you the vnode pointer; you shouldn't need getvnode() or
struct file or anything else. There are other ways to get a vnode *,
but from an ino_t that's the easiest I know of.
Cheers,
matthew
> -----Original Message-----
> From: Matthew Fleming [mailto:[email protected]]
> Sent: Wednesday, April 13, 2011 3:20 PM
> To: Jonathan Stuart
> Cc: [email protected]
> Subject: Re: Getting vnode + credentials of a file from a struct mount and
> UFS inode #
>
> On Wed, Apr 13, 2011 at 2:37 PM, Jonathan Stuart <[email protected]> wrote:
>> Yes, however getvnode() does initialize a struct file *.. but f_cred seems
>> to not contain valid/correct entries.
>> In my last post I probably should have pointed out that I have the inode
>> stored from another operation.
>
> I haven't looked at this field before, but it looks that f_cred is set
> on falloc() to the cred of the thread creating the struct file (the
> thread that called open or socket or pipe or kqueue, etc.). Are you
> running this as root/wheel?
>
> Cheers,
> matthew
>
>> -----Original Message-----
>> From: Matthew Fleming [mailto:[email protected]]
>> Sent: Wednesday, April 13, 2011 2:35 PM
>> To: Jonathan Stuart
>> Cc: [email protected]
>> Subject: Re: Getting vnode + credentials of a file from a struct mount and
>> UFS inode #
>>
>> On Wed, Apr 13, 2011 at 2:18 PM, Jonathan Stuart <[email protected]>
>> wrote:
>>> Hi Matthew,
>>>
>>> Thanks, I'll give it a shot.. for some reason f_cred off the vnode is
>>> returning all zeros for uid/gid, and
>>> pulling the VTOI does the same thing (using getvnode()).. do these not get
>>> initialized properly?
>>
>> f_cred is a field in struct file, not struct vnode, so I'm confused as
>> to what you're referring to.
>>
>> Cheers,
>> matthew
>>
>>> -----Original Message-----
>>> From: Matthew Fleming [mailto:[email protected]]
>>> Sent: Wednesday, April 13, 2011 1:48 PM
>>> To: Jonathan Stuart
>>> Cc: [email protected]
>>> Subject: Re: Getting vnode + credentials of a file from a struct mount and
>>> UFS inode #
>>>
>>> On Wed, Apr 13, 2011 at 12:31 PM, Jonathan Stuart <[email protected]>
>>> wrote:
>>>> Hi,
>>>>
>>>> I'd like to pull the owner/group ownership from a file (the information I
>>>> have about the file is it's UFS inode # and it's struct mount *). I'm
>>>> sure there's got to be a function that would return a vnode and I could
>>>> VTOI() to get this information from the inode.. but I'm having a
>>>> brainfreeze.
>>>>
>>>
>>> VFS_VGET(mp, ino, flags, &vp) is probably what you want.
>>>
>>> Cheers,
>>> matthew
>>>
>>
>
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"