Skip to contentSkip to conversation

[2.4.19] How to get the path name of a struct dentry

DISCUSSION Torsten Foertsch 3 participants 11 messages Mar 12, 2003

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Assuming I have got a particular (struct dentry*)dp, how can I get it's full path name.

I understand that dp->d_name.name contain the relative path name. Then I can cycle through dp->d_parent while( !IS_ROOT(dp) ).

But that cycle finishes when the mount point of the current file system is hit.

How can I get the mount point's struct dentry of the parent file system basing on the root dentry of mounted file system?

Thanks
Torsten
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+bv7UwicyCTir8T4RAjCRAKCJaTNRnOQ4oXYPZIXIYeaH8X15xwCeNyMI ftq5TknzeKMMPJIj4as3PaI=
=nm/0
-----END PGP SIGNATURE-----

#1 lore raw
Quoted 7 lines · Torsten Foertsch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Assuming I have got a particular (struct dentry*)dp, how can I get it's full path name.

You can't. See d_path() for the information needed to get an absolute path.

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Torsten Foertsch

Assuming I have got a particular (struct dentry*)dp, how can I get it's full path name.

You can't. See d_path() for the information needed to get an absolute path.

Thanks, that helped.

Next question, is there a way to get the dentry and vfsmount of /? I mean not current->fs->root and current->fs->rootmnt. They can be chrooted. I mean the real /.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+bw4nwicyCTir8T4RAkc3AJ9W1k9rwLF44E5dVawOeePbNcf1pACfR/J7 giuLC13yRuO+z/wPLpCbtNs=
=UcIU
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 3 lines · Torsten Foertsch

Next question, is there a way to get the dentry and vfsmount of /? I mean not current->fs->root and current->fs->rootmnt. They can be chrooted. I mean the real /.

No. Esecially as there is not single "real" root.

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Torsten Foertsch

Next question, is there a way to get the dentry and vfsmount of /? I mean not current->fs->root and current->fs->rootmnt. They can be chrooted. I mean the real /.

No. Esecially as there is not single "real" root.

That means one can build a system with 2 (or more) completely independent file system areas combining chroot() and pivot_root(), doesn't it?

                                 fork()
                                   |
                   +---------------+--------------+
                   |                              |
             chroot /area1                        |
                   |                              |
             signal parent ====================> pause
                   |                              |
                  ...                        pivot_root /area2
                                                  |
                                                 ...

Torsten
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+bypWwicyCTir8T4RAuZ6AJ9ACvyIrNDm0dNLNHeTCZzlbJHqSwCeIIAf 8bMEv3HTsutmMpfACakcMlI=
=mNdh
-----END PGP SIGNATURE-----

#5 lore raw
Quoted 4 lines · Torsten Foertsch
Quoted 1 line

No. Esecially as there is not single "real" root.

That means one can build a system with 2 (or more) completely independent file system areas combining chroot() and pivot_root(), doesn't it?

I'm talking about namesapce. Clone a new process with CLONE_NEWNS and all modifications to the namespace are private to this process and it's children.

This way you can have e.g. process-private mounts.

#6 lore raw
In reply to Christoph Hellwig

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Torsten Foertsch

Next question, is there a way to get the dentry and vfsmount of /? I mean not current->fs->root and current->fs->rootmnt. They can be chrooted. I mean the real /.

No. Esecially as there is not single "real" root.

How about that slightly modified d_path()?

char*
full_d_path( struct dentry *dentry,

	     struct vfsmount *vfsmnt,
	     char *buf, int buflen ) {

char *res;
struct vfsmount *rootmnt;
struct dentry *root;
read_lock(&current->fs->lock);
rootmnt = mntget(current->fs->rootmnt);
read_unlock(&current->fs->lock);

  while( rootmnt!=rootmnt->mnt_parent ) {
    struct vfsmount *h=mntget( rootmnt->mnt_parent );
    mntput( rootmnt );
    rootmnt=h;
  }

  root = dget(rootmnt->mnt_root);

  spin_lock(&dcache_lock);
  res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
  spin_unlock(&dcache_lock);

dput(root);
mntput(rootmnt);
return res;
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+bzBEwicyCTir8T4RAnDGAJ9A0/e2Qz1U6ewbAZWDi5s9Xe1dYwCfUShA MWs6OWH+PXurHALosXxMdEU=
=/MHy
-----END PGP SIGNATURE-----

#7 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 14 lines · Torsten Foertsch
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Torsten Foertsch

Next question, is there a way to get the dentry and vfsmount of /? I mean not current->fs->root and current->fs->rootmnt. They can be chrooted. I mean the real /.

No. Esecially as there is not single "real" root.

How about that slightly modified d_path()?

char*
full_d_path( struct dentry *dentry,

	     struct vfsmount *vfsmnt,
	     char *buf, int buflen ) {

...

Quoted 1 line

}

or even simpler

char*
full_d_path( struct dentry *dentry,

	     struct vfsmount *vfsmnt,
	     char *buf, int buflen ) {

char *res;
struct vfsmount *rootmnt;
struct dentry *root;
struct namespace *ns;

ns=current->namespace;
/* get_namespace( ns ); */
rootmnt=mntget( ns->root );
/* put_namespace( ns ); */

  root = dget(rootmnt->mnt_root);

  spin_lock(&dcache_lock);
  res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
  spin_unlock(&dcache_lock);

dput(root);
mntput(rootmnt);
return res;
}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+bzcDwicyCTir8T4RAju7AJ4lP23Mzp+GVJHQP7XqHhNNLV9qIACdF2cO GZVG8UuSq4UwOLxA2za4W8g=
=wCJb
-----END PGP SIGNATURE-----

#8 lore raw
Quoted 5 lines · Torsten Foertsch

char*
full_d_path( struct dentry *dentry,

	     struct vfsmount *vfsmnt,
	     char *buf, int buflen ) {
Quoted 7 lines

char *res;
struct vfsmount *rootmnt;
struct dentry *root;
struct namespace *ns;

ns=current->namespace;
/* get_namespace( ns ); */

you want to keep this.

Quoted 2 lines

rootmnt=mntget( ns->root );
/* put_namespace( ns ); */

do the put once you're completly done with it

Quoted 10 lines
  root = dget(rootmnt->mnt_root);

  spin_lock(&dcache_lock);
  res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
  spin_unlock(&dcache_lock);

  dput(root);
  mntput(rootmnt);
  return res;

looks okay to me otherwise.

#9 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 5 lines · Christoph Hellwig
Quoted 3 lines

ns=current->namespace;
/* get_namespace( ns ); */

you want to keep this.

I commented it because I compile my code as a module and the inlined function put_namespace() calls umount_tree() that is not exported. So I have to copy it to my modules code.

Quoted 14 lines
Quoted 3 lines

rootmnt=mntget( ns->root );
/* put_namespace( ns ); */

do the put once you're completly done with it

Quoted 8 lines
  root = dget(rootmnt->mnt_root);

  spin_lock(&dcache_lock);
  res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
  spin_unlock(&dcache_lock);

  dput(root);
  mntput(rootmnt);

You mean put_namespace(ns) should go here?

Quoted 1 line
Quoted 1 line

return res;

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+b0mJwicyCTir8T4RAnXHAJ9d3NVrT32iH3ct5ZZLCj3ZjU25vwCglvw5 A+nWzvgKOvjKc46J4jwmAPc=
=Hyot
-----END PGP SIGNATURE-----

#10 lore raw
In reply to Torsten Foertsch
Quoted 7 lines · Torsten Foertsch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Assuming I have got a particular (struct dentry*)dp, how can I get it's full path name.

the question also is "in which namespace do you want the full path name" and which chroot and ... There is no such thing as *the* full path name.