/usr/share/systemtap/tapset/linux/dentry.stp is in systemtap-common 2.6-0.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | // dentry tapset
// Copyright (c) 2009-2010, 2012 Red Hat Inc.
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
function __dentry_IS_ROOT:long(dentry:long)
{
return (@cast(dentry, "dentry")->d_parent == dentry)
}
function __dentry_prepend:string(dentry:long,name:string)
{
dname = d_name(dentry)
/*
* In case we are following down a mount point trigger, we can get
* multiple instances of a root mount.
*/
c = substr(name, strlen(name)-1, strlen(name)-1)
if (dname == "/" && c == "/")
return name;
if (name == "") {
return dname;
} else {
return sprintf("%s/%s", dname, name);
}
}
/**
* sfunction d_name - get the dirent name
*
* Returns the dirent name (path basename).
* @dentry: Pointer to dentry.
*/
function d_name:string(dentry:long)
{
s = & @cast(dentry, "dentry")->d_name;
return kernel_string_n(s->name, s->len);
}
function __inode_first_dentry:long(inode:long)
{
/* i_dentry is an hlist_head on 3.6+, or a list_head before that. */
d_alias = @choose_defined(
@cast(inode, "struct inode")->i_dentry->first,
@cast(inode, "struct inode")->i_dentry->next)
return & @container_of(d_alias, "struct dentry", d_alias)
}
function __inode_vfsmount:long(inode:long)
{
/* s_mounts was added in kernel 3.6, commit b3d9b7a3c. */
if (@type_member_defined("struct super_block", s_mounts)) {
mnt_ns = @cast(task_current(), "struct task_struct")->nsproxy->mnt_ns
sb = @cast(inode, "struct inode")->i_sb
/* Look for the mount which matches the current namespace */
head = &sb->s_mounts
for (pos = head->next; pos != head; pos = pos->next) {
mount = & @container_of(pos, "struct mount", mnt_instance)
if (mount->mnt_ns == mnt_ns)
return & mount->mnt
}
}
return 0
}
/**
* sfunction inode_name - get the inode name
*
* Returns the first path basename associated with the given inode.
* @inode: Pointer to inode.
*/
function inode_name:string(inode:long)
{
return reverse_path_walk(__inode_first_dentry(inode))
}
/**
* sfunction inode_path - get the path to an inode
*
* Returns the full path associated with the given inode.
* @inode: Pointer to inode.
*/
function inode_path:string(inode:long)
{
dentry = __inode_first_dentry(inode)
vfsmount = __inode_vfsmount(inode)
if (vfsmount != 0)
return task_dentry_path(task_current(), dentry, vfsmount)
/* This is not really a full path... */
return reverse_path_walk(dentry)
}
/**
* sfunction reverse_path_walk - get the full dirent path
*
* Returns the path name (partial path to mount point).
* @dentry: Pointer to dentry.
*/
function reverse_path_walk:string(dentry:long)
{
while(1) {
name = __dentry_prepend(dentry, name);
dentry = @cast(dentry, "dentry")->d_parent;
if (__dentry_IS_ROOT(dentry))
return name;
}
}
/**
* sfunction real_mount - get the 'struct mount' pointer
*
* Returns the 'struct mount' pointer value for a 'struct vfsmount'
* pointer.
* @vfsmnt: Pointer to 'struct vfsmount'
*/
function real_mount:long(vfsmnt:long)
{
if (@type_member_defined("mount", mnt_parent)) {
/*
* The following is the script language equivalent of:
*
* return container_of(vfsmnt, struct mount, mnt);
*
* We can't do the above because 'struct mount' is
* defined in a private header (in fs/mount.h). But,
* we can do the script language equivalent (because
* we've got dwarf info).
*
* More spelled out in C, the above would look like:
*
* return (vfsmnt - offsetof(struct mount, mnt));
*
* but here we're also making sure it won't wrap around.
*/
offset = @offsetof("mount", mnt)
if (vfsmnt < 0 || vfsmnt > offset)
return (vfsmnt - offset)
}
return 0
}
/**
* sfunction task_dentry_path - get the full dentry path
*
* Returns the full dirent name (full path to the root), like
* the kernel d_path function.
* @task: task_struct pointer.
* @dentry: direntry pointer.
* @vfsmnt: vfsmnt pointer.
*/
function task_dentry_path:string(task:long,dentry:long,vfsmnt:long)
{
/*
* There are various synthetic filesystems that never get
* mounted. Filesystems needing to implement special "root
* names" do so with dentry->d_op->d_dname(). Unfortunately,
* it isn't really safe for us to call
* dentry->d_op->d_dname(). We can't really validate the
* function pointer or know that it can be called safely in
* the current context.
*
* Some pseudo inodes are mountable. When they are mounted,
* dentry == vfsmnt->mnt_root. In that case, we'll just go
* ahead and handle them normally.
*/
dentry = & @cast(dentry, "dentry")
vfsmnt = & @cast(vfsmnt, "vfsmount")
if (@type_member_defined("dentry", d_op->d_dname)
&& dentry->d_op && dentry->d_op->d_dname
&& (!__dentry_IS_ROOT(dentry) || dentry != vfsmnt->mnt_root))
return sprintf("UNKNOWN:[%p]", dentry)
root = & @cast(task, "task_struct")->fs->root
while (1) {
# If we've found the right dentry/vfsmnt, we're done.
if (dentry == root->dentry && vfsmnt == root->mnt)
break;
if (dentry == vfsmnt->mnt_root || __dentry_IS_ROOT(dentry)) {
if (! @type_member_defined("vfsmount", mnt_parent)) {
mnt = & @cast(real_mount(vfsmnt), "mount")
if (mnt == 0)
return "<unknown>"
/* Global root? */
if (mnt->mnt_parent == vfsmnt)
return sprintf("/%s", name);
dentry = mnt->mnt_mountpoint
vfsmnt = & mnt->mnt_parent->mnt
}
else {
/* Global root? */
if (vfsmnt->mnt_parent == vfsmnt)
return sprintf("/%s", name);
dentry = vfsmnt->mnt_mountpoint
vfsmnt = vfsmnt->mnt_parent
}
continue;
}
name = __dentry_prepend(dentry, name);
dentry = dentry->d_parent;
}
return sprintf("/%s", name);
}
/**
* sfunction d_path - get the full nameidata path
*
* Returns the full dirent name (full path to the root), like
* the kernel d_path function.
* @nd: Pointer to nameidata.
*/
function d_path:string(nd:long)
{
dentry = @choose_defined(@cast(nd,"nameidata")->path->dentry,
@cast(nd,"nameidata")->dentry)
vfsmnt = @choose_defined(@cast(nd,"nameidata")->path->mnt,
@cast(nd,"nameidata")->mnt)
return sprintf("%s/", task_dentry_path(task_current(), dentry, vfsmnt))
}
|