mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [2.4.19] How to get the path name of a struct dentry
@ 2003-03-12  9:33 Torsten Foertsch
  2003-03-12 10:11 ` Christoph Hellwig
  2003-03-12 10:13 ` Arjan van de Ven
  0 siblings, 2 replies; 11+ messages in thread
From: Torsten Foertsch @ 2003-03-12  9:33 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12  9:33 [2.4.19] How to get the path name of a struct dentry Torsten Foertsch
@ 2003-03-12 10:11 ` Christoph Hellwig
  2003-03-12 10:38   ` Torsten Foertsch
  2003-03-12 10:13 ` Arjan van de Ven
  1 sibling, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2003-03-12 10:11 UTC (permalink / raw)
  To: Torsten Foertsch; +Cc: linux-kernel

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12  9:33 [2.4.19] How to get the path name of a struct dentry Torsten Foertsch
  2003-03-12 10:11 ` Christoph Hellwig
@ 2003-03-12 10:13 ` Arjan van de Ven
  1 sibling, 0 replies; 11+ messages in thread
From: Arjan van de Ven @ 2003-03-12 10:13 UTC (permalink / raw)
  To: Torsten Foertsch; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

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.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 10:11 ` Christoph Hellwig
@ 2003-03-12 10:38   ` Torsten Foertsch
  2003-03-12 10:47     ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: Torsten Foertsch @ 2003-03-12 10:38 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 10:38   ` Torsten Foertsch
@ 2003-03-12 10:47     ` Christoph Hellwig
  2003-03-12 12:38       ` Torsten Foertsch
  2003-03-12 13:04       ` Torsten Foertsch
  0 siblings, 2 replies; 11+ messages in thread
From: Christoph Hellwig @ 2003-03-12 10:47 UTC (permalink / raw)
  To: Torsten Foertsch; +Cc: linux-kernel

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 10:47     ` Christoph Hellwig
@ 2003-03-12 12:38       ` Torsten Foertsch
  2003-03-12 12:53         ` Christoph Hellwig
  2003-03-12 13:04       ` Torsten Foertsch
  1 sibling, 1 reply; 11+ messages in thread
From: Torsten Foertsch @ 2003-03-12 12:38 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 12:38       ` Torsten Foertsch
@ 2003-03-12 12:53         ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2003-03-12 12:53 UTC (permalink / raw)
  To: Torsten Foertsch; +Cc: linux-kernel

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.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 10:47     ` Christoph Hellwig
  2003-03-12 12:38       ` Torsten Foertsch
@ 2003-03-12 13:04       ` Torsten Foertsch
  2003-03-12 13:32         ` Torsten Foertsch
  1 sibling, 1 reply; 11+ messages in thread
From: Torsten Foertsch @ 2003-03-12 13:04 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 13:04       ` Torsten Foertsch
@ 2003-03-12 13:32         ` Torsten Foertsch
  2003-03-12 13:59           ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: Torsten Foertsch @ 2003-03-12 13:32 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 13:32         ` Torsten Foertsch
@ 2003-03-12 13:59           ` Christoph Hellwig
  2003-03-12 14:51             ` Torsten Foertsch
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2003-03-12 13:59 UTC (permalink / raw)
  To: Torsten Foertsch; +Cc: linux-kernel

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.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [2.4.19] How to get the path name of a struct dentry
  2003-03-12 13:59           ` Christoph Hellwig
@ 2003-03-12 14:51             ` Torsten Foertsch
  0 siblings, 0 replies; 11+ messages in thread
From: Torsten Foertsch @ 2003-03-12 14:51 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-03-12 14:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-12  9:33 [2.4.19] How to get the path name of a struct dentry Torsten Foertsch
2003-03-12 10:11 ` Christoph Hellwig
2003-03-12 10:38   ` Torsten Foertsch
2003-03-12 10:47     ` Christoph Hellwig
2003-03-12 12:38       ` Torsten Foertsch
2003-03-12 12:53         ` Christoph Hellwig
2003-03-12 13:04       ` Torsten Foertsch
2003-03-12 13:32         ` Torsten Foertsch
2003-03-12 13:59           ` Christoph Hellwig
2003-03-12 14:51             ` Torsten Foertsch
2003-03-12 10:13 ` Arjan van de Ven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®