From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 13 22:33:32 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8C1D51065742 for ; Wed, 13 Apr 2011 22:33:32 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 1A85F8FC12 for ; Wed, 13 Apr 2011 22:33:31 +0000 (UTC) Received: by wyf23 with SMTP id 23so1078221wyf.13 for ; Wed, 13 Apr 2011 15:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=CIJ+3rGVwXdh7BD/Nd+RI2OMNZXXnfJf1ZwdfNLhtKQ=; b=wEX5KjRzwqjE2hLXLdhhG6lwXvHORhbdKEHI1+f5Ulqt/1lWc1vkyfykWPGGQfSESh fIGSSz8d2jYXgQApppWzn0MXqF5vzIYetbBW0CYSjLaOgngayyXBM3iaVmcQ3wNHevNd Ovop8DMEbBGGemlEU8gHwOJyhst5m8FuZr0FM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=sPpERmkpL9r7w0WwpubYHrIruZTT9c/GUmYcUpKBrDp3ATkqBSXy+cAUdo/B25GqIq RxSZwRkW/0M98hI7KimVS41zl0guBF2dKjVdhyNSxHV981ijOMumRkeSOi5lrlHEpm0l /Ko+xCR11wrwjib78D55fGv9RY/BYv0Z/AoJ8= MIME-Version: 1.0 Received: by 10.216.64.139 with SMTP id c11mr5792280wed.46.1302734010990; Wed, 13 Apr 2011 15:33:30 -0700 (PDT) Received: by 10.216.123.15 with HTTP; Wed, 13 Apr 2011 15:33:30 -0700 (PDT) In-Reply-To: <32AB5C9615CC494997D9ABB1DB12783C024E929FE5@SJ-EXCH-1.adaranet.com> References: <32AB5C9615CC494997D9ABB1DB12783C024E929F93@SJ-EXCH-1.adaranet.com> <32AB5C9615CC494997D9ABB1DB12783C024E929FD0@SJ-EXCH-1.adaranet.com> <32AB5C9615CC494997D9ABB1DB12783C024E929FDC@SJ-EXCH-1.adaranet.com> <32AB5C9615CC494997D9ABB1DB12783C024E929FE5@SJ-EXCH-1.adaranet.com> Date: Wed, 13 Apr 2011 15:33:30 -0700 Message-ID: From: Matthew Fleming To: Jonathan Stuart Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "freebsd-hackers@freebsd.org" Subject: Re: Getting vnode + credentials of a file from a struct mount and UFS inode # X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Apr 2011 22:33:32 -0000 On Wed, Apr 13, 2011 at 3:25 PM, Jonathan Stuart wro= te: > Hi, > > Yes, I am.. that was my suspicion (e.g., that it was the parameters of th= e process which called open()/creat()/socket()/... originally). =A0What's t= he 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 =3D VFS_VGET(mp, ino, LK_SHARED, &vp); if (error !=3D 0) { printf("Got error %d\n", error); return; } ip =3D 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 ty= pe 0x0. > What is odd is that the only way I can get a vnode for VFS_VGET is throug= h struct file, and then shouldn't I be able to use that? =A0I tried using t= he flipping that vnode->inode with VTOI() and it was also giving me zeros f= or 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:mdf356@gmail.com] > Sent: Wednesday, April 13, 2011 3:20 PM > To: Jonathan Stuart > Cc: freebsd-hackers@freebsd.org > Subject: Re: Getting vnode + credentials of a file from a struct mount an= d UFS inode # > > On Wed, Apr 13, 2011 at 2:37 PM, Jonathan Stuart w= rote: >> Yes, however getvnode() does initialize a struct file *.. but f_cred see= ms 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.). =A0Are you > running this as root/wheel? > > Cheers, > matthew > >> -----Original Message----- >> From: Matthew Fleming [mailto:mdf356@gmail.com] >> Sent: Wednesday, April 13, 2011 2:35 PM >> To: Jonathan Stuart >> Cc: freebsd-hackers@freebsd.org >> Subject: Re: Getting vnode + credentials of a file from a struct mount a= nd UFS inode # >> >> On Wed, Apr 13, 2011 at 2:18 PM, Jonathan Stuart = wrote: >>> Hi Matthew, >>> >>> Thanks, I'll give it a shot.. for some reason f_cred off the vnode is r= eturning 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:mdf356@gmail.com] >>> Sent: Wednesday, April 13, 2011 1:48 PM >>> To: Jonathan Stuart >>> Cc: freebsd-hackers@freebsd.org >>> 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 wrote: >>>> Hi, >>>> >>>> I'd like to pull the owner/group ownership from a file (the informatio= n I have about the file is it's UFS inode # and it's struct mount *). =A0I'= m sure there's got to be a function that would return a vnode and I could V= TOI() 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 >>> >> >