Skip to content

Instantly share code, notes, and snippets.

@erickt
Created October 19, 2010 22:18
Show Gist options
  • Save erickt/635260 to your computer and use it in GitHub Desktop.
Save erickt/635260 to your computer and use it in GitHub Desktop.
function __task_file_handle_filp:long(task:long, fd:long) %{ /* pure */
struct task_struct *p = (struct task_struct *)((long)THIS->task);
struct files_struct *files;
struct file *filp;
rcu_read_lock();
if ((files = kread(&p->files))) {
if ((filp = fcheck_files(files, THIS->fd))) {
THIS->__retvalue = (long)filp;
}
}
CATCH_DEREF_FAULT();
rcu_read_unlock();
%}
function __task_dentry_prepend:string(dentry:long,name:string)
{
dname = d_name(dentry)
if (name == "")
return dname
/*
* 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
return sprintf("%s/%s", dname, name)
}
function __task_d_path(task:long, dentry:long, vfsmnt:long)
{
root = & @cast(task, "task_struct")->fs->root
while (1) {
if (dentry == @cast(root, "path")->dentry &&
vfsmnt == @cast(root, "path")->mnt)
break;
if (dentry == @cast(vfsmnt, "vfsmount")->mnt_root ||
__dentry_IS_ROOT(dentry)) {
/* Global root? */
if (@cast(vfsmnt, "vfsmount")->mnt_parent == vfsmnt) {
return sprintf("/%s", name)
}
dentry = @cast(vfsmnt, "vfsmount")->mnt_mountpoint
vfsmnt = @cast(vfsmnt, "vfsmount")->mnt_parent
continue
}
name = __task_dentry_prepend(dentry, name)
dentry = @cast(dentry, "dentry")->d_parent
}
return sprintf("/%s", name)
}
function task_file_handle_d_path:string(task:long, fd:long)
{
filp = __task_file_handle_filp(task, fd)
if (filp) {
%( kernel_v >= "2.6.26" %?
dentry = @cast(filp,"file")->f_path->dentry
vfsmnt = @cast(filp,"file")->f_path->mnt
%:
dentry = @cast(filp,"file")->f_dentry
vfsmnt = @cast(filp,"file")->f_vfsmnt
%)
return __task_d_path(task, dentry, vfsmnt)
} else {
return ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment