From 2ea00da3929b9b50c3860914249b3ea7691b63c8 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Mon, 2 Sep 2013 11:37:06 +0200 Subject: libnetfs: track file name in struct peropen Track the relative path used to obtain a file handle in the struct peropen. * libnetfs/netfs.h (struct peropen): New field path. * libnetfs/make-peropen.c (netfs_make_peropen): Initialize path. * libnetfs/release-peropen.c (netfs_release_peropen): Free path. * libnetfs/fsys-getroot.c (netfs_S_fsys_getroot): Initialize path. * libnetfs/dir-lookup.c (netfs_S_dir_lookup): Preserve the path. --- libnetfs/dir-lookup.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libnetfs/dir-lookup.c') diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c index f1b6438f..10ea2d0b 100644 --- a/libnetfs/dir-lookup.c +++ b/libnetfs/dir-lookup.c @@ -1,5 +1,6 @@ /* - Copyright (C) 1995,96,97,98,99,2000,01,02 Free Software Foundation, Inc. + Copyright (C) 1995,96,97,98,99,2000,01,02,13 + Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -46,6 +47,7 @@ netfs_S_dir_lookup (struct protid *diruser, int nsymlinks = 0; struct node *dnp, *np; char *nextname; + char *relpath; error_t error; struct protid *newpi; struct iouser *user; @@ -60,6 +62,11 @@ netfs_S_dir_lookup (struct protid *diruser, while (*filename == '/') filename++; + /* Preserve the path relative to diruser->po->path. */ + relpath = strdup (filename); + if (! relpath) + return ENOMEM; + *retry_port_type = MACH_MSG_TYPE_MAKE_SEND; *do_retry = FS_RETRY_NORMAL; *retry_name = '\0'; @@ -390,6 +397,22 @@ netfs_S_dir_lookup (struct protid *diruser, goto out; } + free (newpi->po->path); + if (diruser->po->path == NULL) + { + /* diruser is the root directory. */ + newpi->po->path = relpath; + relpath = NULL; /* Do not free relpath. */ + } + else + { + newpi->po->path = NULL; + asprintf (&newpi->po->path, "%s/%s", diruser->po->path, relpath); + } + + if (! newpi->po->path) + error = errno; + *retry_port = ports_get_right (newpi); ports_port_deref (newpi); @@ -398,5 +421,6 @@ netfs_S_dir_lookup (struct protid *diruser, netfs_nput (np); if (dnp) netfs_nrele (dnp); + free (relpath); return error; } -- cgit v1.2.3