From: Ashish Khurange Subject: get vfsmount from dentry Date: Sun, 12 Mar 2006 19:14:27 +0530 Message-ID: <441425BB.6030604@it.iitb.ac.in> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from smtp1.iitb.ac.in ([59.163.25.49]:30181 "HELO smtp1.iitb.ac.in") by vger.kernel.org with SMTP id S1750913AbWCLNob (ORCPT ); Sun, 12 Mar 2006 08:44:31 -0500 To: linux-fsdevel@vger.kernel.org Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Hi, I'm trying to develop a fmon (file monitor) patch. For that I'm trying to find complete pathname of the file/directory being changed. If you have dentry of a file and a corresponding vfsmount struct, I can find out its entire pathname using following code. Which works exactly the way I want. static char * mirror_path (struct dentry *dentry, struct vfsmount *vfsmnt, char *buffer, int buflen) { char * end = buffer+buflen; char * retval; int namelen; *--end = '\0'; buflen--; if (buflen < 1) goto Elong; /* Get '/' right */ retval = end-1; *retval = '/'; for (;;) { struct dentry * parent; if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { /* Global root? */ spin_lock(&vfsmount_lock); if (vfsmnt->mnt_parent == vfsmnt) { spin_unlock(&vfsmount_lock); break; } dentry = vfsmnt->mnt_mountpoint; vfsmnt = vfsmnt->mnt_parent; spin_unlock(&vfsmount_lock); continue; } parent = dentry->d_parent; prefetch(parent); namelen = dentry->d_name.len; buflen -= namelen + 1; if (buflen < 0) goto Elong; end -= namelen; memcpy(end, dentry->d_name.name, namelen); *--end = '/'; retval = end; dentry = parent; } namelen = dentry->d_name.len; buflen -= namelen; if (buflen < 0) goto Elong; retval -= namelen-1; /* hit the slash */ memcpy(retval, dentry->d_name.name, namelen); return retval; Elong: return NULL; } Now the only problem is in many functions in the filesystem code, I have access only to the dentry and not to its vfsmount. I can do one thing I can change the function definition and pass corresponding vfsmount as a parameter to the function, but this will lead to lot of changes. Is there any way by which I can found the vfsmount structure of a file represented by dentry structure? Regards, - Ashish