2003-03-12 09:24:29

by Torsten Foertsch

[permalink] [raw]
Subject: [2.4.19] How to get the path name of a struct dentry

-----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-----


2003-03-12 10:00:52

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

On Wed, Mar 12, 2003 at 10:33:05AM +0100, Torsten Foertsch wrote:
> -----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.

2003-03-12 10:02:39

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

On Wed, 2003-03-12 at 10:33, Torsten Foertsch wrote:
> -----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.


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2003-03-12 10:30:39

by Torsten Foertsch

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

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

On Wednesday 12 March 2003 11:11, Christoph Hellwig wrote:
> On Wed, Mar 12, 2003 at 10:33:05AM +0100, Torsten Foertsch wrote:
> > 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-----

2003-03-12 10:37:01

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

On Wed, Mar 12, 2003 at 11:38:27AM +0100, Torsten Foertsch wrote:
> 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.

2003-03-12 12:32:02

by Torsten Foertsch

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

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

On Wednesday 12 March 2003 11:47, Christoph Hellwig wrote:
> On Wed, Mar 12, 2003 at 11:38:27AM +0100, Torsten Foertsch wrote:
> > 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-----

2003-03-12 12:43:05

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

On Wed, Mar 12, 2003 at 01:38:42PM +0100, Torsten Foertsch wrote:
> > 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.

2003-03-12 12:57:36

by Torsten Foertsch

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

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

On Wednesday 12 March 2003 11:47, Christoph Hellwig wrote:
> On Wed, Mar 12, 2003 at 11:38:27AM +0100, Torsten Foertsch wrote:
> > 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-----

2003-03-12 13:26:40

by Torsten Foertsch

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

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

On Wednesday 12 March 2003 14:04, Torsten Foertsch wrote:
> On Wednesday 12 March 2003 11:47, Christoph Hellwig wrote:
> > On Wed, Mar 12, 2003 at 11:38:27AM +0100, Torsten Foertsch wrote:
> > > 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 ) {
...
> }

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-----

2003-03-12 13:49:34

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

On Wed, Mar 12, 2003 at 02:32:47PM +0100, Torsten Foertsch wrote:
>
> 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 ); */

you want to keep this.

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

do the put once you're completly done with it

>
> 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.

2003-03-12 14:46:32

by Torsten Foertsch

[permalink] [raw]
Subject: Re: [2.4.19] How to get the path name of a struct dentry

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

On Wednesday 12 March 2003 14:59, Christoph Hellwig wrote:
> >
> > 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.


>
> > rootmnt=mntget( ns->root );
> > /* put_namespace( ns ); */
>
> do the put once you're completly done with it
>
> > 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?

> > return res;
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

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