From 076957fe8c12344ddae2fa4b966c7be9be232654 Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Wed, 13 Jan 2016 00:58:59 +0100 Subject: Fix O_DIRECTORY lookup on trivial translators * libdiskfs/dir-lookup.c (diskfs_S_dir_lookup): If mustbedir, make sure entry is a directory by retrying "/", or starting the translator and retrying "/". * libnetfs/dir-lookup.c (netfs_S_dir_lookup): Likewise. --- libnetfs/dir-lookup.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'libnetfs/dir-lookup.c') diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c index 8b8cd6ec..1fefd3ff 100644 --- a/libnetfs/dir-lookup.c +++ b/libnetfs/dir-lookup.c @@ -128,7 +128,9 @@ netfs_S_dir_lookup (struct protid *diruser, *do_retry = FS_RETRY_REAUTH; *retry_port = diruser->po->shadow_root_parent; *retry_port_type = MACH_MSG_TYPE_COPY_SEND; - if (! lastcomp) + if (lastcomp && mustbedir) /* Trailing slash. */ + strcpy (retry_name, "/"); + else if (!lastcomp) strcpy (retry_name, nextname); error = 0; pthread_mutex_unlock (&dnp->lock); @@ -142,7 +144,9 @@ netfs_S_dir_lookup (struct protid *diruser, *do_retry = FS_RETRY_REAUTH; *retry_port = diruser->po->root_parent; *retry_port_type = MACH_MSG_TYPE_COPY_SEND; - if (!lastcomp) + if (lastcomp && mustbedir) /* Trailing slash. */ + strcpy (retry_name, "/"); + else if (!lastcomp) strcpy (retry_name, nextname); error = 0; pthread_mutex_unlock (&dnp->lock); @@ -194,7 +198,7 @@ netfs_S_dir_lookup (struct protid *diruser, if (error) goto out; - if ((((flags & O_NOTRANS) == 0) || !lastcomp) + if ((((flags & O_NOTRANS) == 0) || !lastcomp || mustbedir) && ((np->nn_translated & S_IPTRANS) || S_ISFIFO (np->nn_translated) || S_ISCHR (np->nn_translated) @@ -288,10 +292,16 @@ netfs_S_dir_lookup (struct protid *diruser, if (error != ENOENT) { *retry_port_type = MACH_MSG_TYPE_MOVE_SEND; - if (!lastcomp && !error) + if (!error) { - strcat (retry_name, "/"); - strcat (retry_name, nextname); + char *end = strchr (retry_name, '\0'); + if (mustbedir) + *end++ = '/'; /* Trailing slash. */ + else if (!lastcomp) { + if (end != retry_name) + *end++ = '/'; + strcpy (end, nextname); + } } if (register_translator) -- cgit v1.2.3