From a0852d93e5b6643a3dcfc535e5e89fed1ad89568 Mon Sep 17 00:00:00 2001 From: Marcio Barbosa Date: Tue, 24 Jan 2023 14:39:20 +0000 Subject: [PATCH] fs: Avoid unnecessary lstat() for -literal Currently, GetLastComponent() always stats (lstat) the file received as an argument. However, the status information about this file is only used when 'literal' is false. That said, skip lstat() when 'literal' is true. While here, zero out 'statbuff' at the beginning of GetLastComponent() just to make sure it won't be used uninitialized in the future. Change-Id: I3f332c53ae688d6f74276bcdbf2f9f61605ec9ad Reviewed-on: https://gerrit.openafs.org/14840 Reviewed-by: Mark Vitale Reviewed-by: Cheyenne Wills Reviewed-by: Andrew Deason Reviewed-by: Michael Meffie Tested-by: BuildBot --- src/venus/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/venus/fs.c b/src/venus/fs.c index 62bc2f5a00..6f2c4dbe7e 100644 --- a/src/venus/fs.c +++ b/src/venus/fs.c @@ -1743,6 +1743,7 @@ GetLastComponent(const char *data, char **outdir, char **outbase, *outbase = NULL; *outdir = NULL; + memset(&statbuff, 0, sizeof(statbuff)); if (thru_symlink) *thru_symlink = 0; @@ -1750,7 +1751,7 @@ GetLastComponent(const char *data, char **outdir, char **outbase, snprintf(orig_name, sizeof(orig_name), "%s%s", (data[0] == '/') ? "" : "./", data); - if (lstat(orig_name, &statbuff) < 0) { + if (!literal && lstat(orig_name, &statbuff) < 0) { /* if lstat fails, we should still try the pioctl, since it * may work (for example, lstat will fail, but pioctl will * work if the volume of offline (returning ENODEV). */