Martin Carpenter
2008-Jan-04 18:08 UTC
[dtrace-discuss] Obtaining file attributes from open()
Hello all, I''m trying to determine the file attributes (mode, owner, group) from an open() via the syscall probe. I have found fds[] and fileinfo_t and also curthread->t_procp->p_user.u_finfo.fi_list[arg0].uf_file->f_vnode which gets me as far as the vnode. But I don''t see how to get to struct vattr from there, or if there is a function that will enable me to access these in the predicate. Many thanks for any illumination, Martin.
On Fri, Jan 04, 2008 at 07:08:55PM +0100, Martin Carpenter wrote:> > Hello all, > > I''m trying to determine the file attributes (mode, owner, group) from an > open() via the syscall probe. I have found fds[] and fileinfo_t and also > > curthread->t_procp->p_user.u_finfo.fi_list[arg0].uf_file->f_vnode > > which gets me as far as the vnode. But I don''t see how to get to struct > vattr from there, or if there is a function that will enable me to access > these in the predicate. > > Many thanks for any illumination, > > Martin.There is no way to statically examine that data because it''s up to each filesystem to implement a function, VOP_GETATTR(), that fills that structure in, and there is no requirement everything in sitting in an in-core vattr_t already. And if the object is not in core, that function will need to read it in from disk etc. So you can''t generically use DTrace to examine in-memory data and be assured of getting this data. You''ll need to look at the code for the underlying filesystem of your open() and, assuming all the data is in-memory, write a function for that filesystem to get what you need. As one example if you look at ufs_getattr(), you will see that you can do a relatively straightforward conversion from f_vnode to the ufs inode structure, and from there get at i_uid, i_gid, i_mode, etc. ZFS is more complicated due to the use of FUIDs, but in the common case you should be able to get what you need from the znode. -Mike -- Mike Shapiro, Solaris Kernel Development. blogs.sun.com/mws/
Martin Carpenter
2008-Jan-08 07:48 UTC
[dtrace-discuss] Obtaining file attributes from open()
Oops, I forgot to copy the list. Martin. On Sun, 2008-01-06 at 18:22 +0100, Martin Carpenter wrote:> On Fri, 2008-01-04 at 10:15 -0800, Mike Shapiro wrote: > > As one example if you look at ufs_getattr(), you will see that you > > can do a relatively straightforward conversion from f_vnode to the > > ufs inode structure, and from there get at i_uid, i_gid, i_mode, etc. > > Thanks for that rapid and pedagogic response - that just enough to get > me out of my rut. Fortunately I''m on UFS, so this: > > inode > (struct inode > *)curthread->t_procp->p_user.u_finfo.fi_list[arg1].uf_file->f_vnode->v_data; > printf("%-5d", inode->i_ic.ic_uid); > > was all I needed. > > Thanks again. > > Martin. > >