From a7c4f7b570a2843e158de98cce2dd148e631ce65 Mon Sep 17 00:00:00 2001 From: William Baker Date: Wed, 12 Sep 2018 11:04:21 -0700 Subject: [PATCH 1/9] Enable RebaseTests --- GVFS/GVFS.FunctionalTests/Tests/GitCommands/RebaseTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/RebaseTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/RebaseTests.cs index 72b1726d60..4f7a62926d 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/RebaseTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/RebaseTests.cs @@ -4,7 +4,6 @@ namespace GVFS.FunctionalTests.Tests.GitCommands { [TestFixture] [Category(Categories.GitCommands)] - [Category(Categories.MacTODO.M3)] public class RebaseTests : GitRepoTests { public RebaseTests() : base(enlistmentPerTest: true) From dc40d25baa58c3cef5fbf73a094f5272a97919dc Mon Sep 17 00:00:00 2001 From: William Baker Date: Wed, 12 Sep 2018 11:30:08 -0700 Subject: [PATCH 2/9] Enable CheckoutTests.CheckoutBranchThatHasFolderShouldGetDeleted --- GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs index 0fb311fc65..59debe779d 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs @@ -251,7 +251,6 @@ public void CheckoutBranchAfterReadingAllFilesAndVerifyContentsCorrect() } [TestCase] - [Category(Categories.MacTODO.M3)] public void CheckoutBranchThatHasFolderShouldGetDeleted() { // this.ControlGitRepo.Commitish should not have the folder Test_ConflictTests\AddedFiles From 1376a8802b61e0c40989e147b7af27f426b4b5a1 Mon Sep 17 00:00:00 2001 From: William Baker Date: Wed, 12 Sep 2018 14:40:35 -0700 Subject: [PATCH 3/9] Update PowerShellRunner to support creating hardlinks --- .../FileSystemRunners/PowerShellRunner.cs | 10 ++++++++++ .../ModifiedPathsTests.cs | 20 ++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs b/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs index 9d6a1da971..46b86aa40d 100644 --- a/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs +++ b/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs @@ -32,6 +32,11 @@ public class PowerShellRunner : ShellRunner "PermissionDenied" }; + public override bool SupportsHardlinkCreation + { + get { return true; } + } + protected override string FileName { get @@ -105,6 +110,11 @@ public override void CreateEmptyFile(string path) this.RunProcess(string.Format("-Command \"&{{ New-Item -ItemType file {0}}}\"", path)); } + public override void CreateHardLink(string newLinkFilePath, string existingFilePath) + { + this.RunProcess(string.Format("-Command \"&{{ New-Item -ItemType HardLink -Path {0} -Value {1}}}\"", newLinkFilePath, existingFilePath)); + } + public override void WriteAllText(string path, string contents) { this.RunProcess(string.Format("-Command \"&{{ Out-File -FilePath {0} -InputObject '{1}' -Encoding ascii -NoNewline}}\"", path, contents)); diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs index 53a655a540..ba72a6a093 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs @@ -3,10 +3,9 @@ using GVFS.FunctionalTests.Tools; using GVFS.Tests.Should; using NUnit.Framework; -using System; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; namespace GVFS.FunctionalTests.Tests.EnlistmentPerTestCase { @@ -172,15 +171,22 @@ public static object[] Runners { get { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + List hardLinkRunners = new List(); + foreach (object[] runner in FileSystemRunner.Runners.ToList()) { - return new[] + FileSystemRunner fileSystem = runner.ToList().First() as FileSystemRunner; + if (fileSystem.SupportsHardlinkCreation) { - new object[] { new CmdRunner() }, - new object[] { new BashRunner() }, - }; + hardLinkRunners.Add(new object[] { fileSystem }); + } } + if (hardLinkRunners.Count > 0) + { + return hardLinkRunners.ToArray(); + } + + // Always return at least one runner that supports creating hard links return new[] { new object[] { new BashRunner() } }; } } From d5f4519fd496b40b9cf2f5e1c9cefef36181b410 Mon Sep 17 00:00:00 2001 From: William Baker Date: Wed, 12 Sep 2018 15:34:11 -0700 Subject: [PATCH 4/9] Add comment to DeleteFileThenCheckout --- GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs index 59debe779d..ec5db6744a 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/CheckoutTests.cs @@ -802,6 +802,7 @@ public void SuccessfullyChecksOutDirectoryToFileToDirectory() this.ShouldNotExistOnDisk("d", "c"); } + // TODO(Mac): This test needs the fix for issue #264 [TestCase] [Category(Categories.MacTODO.M3)] public void DeleteFileThenCheckout() From c05bb8cfe25a1a24622175906e85173f04699263 Mon Sep 17 00:00:00 2001 From: William Baker Date: Thu, 13 Sep 2018 14:25:33 -0700 Subject: [PATCH 5/9] Remove SupportsHardlinkCreation and update SystemIORunner to PInvoke to native hard link API --- .../FileSystemRunners/BashRunner.cs | 5 --- .../FileSystemRunners/CmdRunner.cs | 5 --- .../FileSystemRunners/FileSystemRunner.cs | 11 +------ .../FileSystemRunners/PowerShellRunner.cs | 5 --- .../FileSystemRunners/SystemIORunner.cs | 24 +++++++++++++- .../EnlistmentPerFixture/GitFilesTests.cs | 5 --- .../ModifiedPathsTests.cs | 31 +------------------ .../Tests/GitCommands/AddStageTests.cs | 5 --- .../Tests/GitCommands/GitRepoTests.cs | 10 ++---- 9 files changed, 27 insertions(+), 74 deletions(-) diff --git a/GVFS/GVFS.FunctionalTests/FileSystemRunners/BashRunner.cs b/GVFS/GVFS.FunctionalTests/FileSystemRunners/BashRunner.cs index 40f2fbc126..7da4e85839 100644 --- a/GVFS/GVFS.FunctionalTests/FileSystemRunners/BashRunner.cs +++ b/GVFS/GVFS.FunctionalTests/FileSystemRunners/BashRunner.cs @@ -47,11 +47,6 @@ public BashRunner() } } - public override bool SupportsHardlinkCreation - { - get { return true; } - } - protected override string FileName { get diff --git a/GVFS/GVFS.FunctionalTests/FileSystemRunners/CmdRunner.cs b/GVFS/GVFS.FunctionalTests/FileSystemRunners/CmdRunner.cs index cb5184c066..fd40bef8a9 100644 --- a/GVFS/GVFS.FunctionalTests/FileSystemRunners/CmdRunner.cs +++ b/GVFS/GVFS.FunctionalTests/FileSystemRunners/CmdRunner.cs @@ -27,11 +27,6 @@ public class CmdRunner : ShellRunner "The process cannot access the file because it is being used by another process" }; - public override bool SupportsHardlinkCreation - { - get { return true; } - } - protected override string FileName { get diff --git a/GVFS/GVFS.FunctionalTests/FileSystemRunners/FileSystemRunner.cs b/GVFS/GVFS.FunctionalTests/FileSystemRunners/FileSystemRunner.cs index b8a2f9cc63..e064be50ab 100644 --- a/GVFS/GVFS.FunctionalTests/FileSystemRunners/FileSystemRunner.cs +++ b/GVFS/GVFS.FunctionalTests/FileSystemRunners/FileSystemRunner.cs @@ -47,11 +47,6 @@ public static FileSystemRunner DefaultRunner get { return defaultRunner; } } - public virtual bool SupportsHardlinkCreation - { - get { return false; } - } - // File methods public abstract bool FileExists(string path); public abstract string MoveFile(string sourcePath, string targetPath); @@ -74,11 +69,7 @@ public virtual bool SupportsHardlinkCreation public abstract void ReadAllText_FileShouldNotBeFound(string path); public abstract void CreateEmptyFile(string path); - - public virtual void CreateHardLink(string newLinkFilePath, string existingFilePath) - { - Assert.Fail($"This runner does not support {nameof(this.CreateHardLink)}"); - } + public abstract void CreateHardLink(string newLinkFilePath, string existingFilePath); /// /// Write the specified contents to the specified file. By calling this method the caller is diff --git a/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs b/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs index 46b86aa40d..6c3208b46f 100644 --- a/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs +++ b/GVFS/GVFS.FunctionalTests/FileSystemRunners/PowerShellRunner.cs @@ -32,11 +32,6 @@ public class PowerShellRunner : ShellRunner "PermissionDenied" }; - public override bool SupportsHardlinkCreation - { - get { return true; } - } - protected override string FileName { get diff --git a/GVFS/GVFS.FunctionalTests/FileSystemRunners/SystemIORunner.cs b/GVFS/GVFS.FunctionalTests/FileSystemRunners/SystemIORunner.cs index 8ad8bdffe4..6d947b510d 100644 --- a/GVFS/GVFS.FunctionalTests/FileSystemRunners/SystemIORunner.cs +++ b/GVFS/GVFS.FunctionalTests/FileSystemRunners/SystemIORunner.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using GVFS.Tests.Should; +using NUnit.Framework; using System; using System.Diagnostics; using System.IO; @@ -75,6 +76,18 @@ public override void CreateEmptyFile(string path) } } + public override void CreateHardLink(string newLinkFilePath, string existingFilePath) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + WindowsCreateHardLink(newLinkFilePath, existingFilePath, IntPtr.Zero).ShouldBeTrue($"Failed to create hard link: {Marshal.GetLastWin32Error()}"); + } + else + { + MacCreateHardLink(existingFilePath, newLinkFilePath).ShouldEqual(0, $"Failed to create hard link: {Marshal.GetLastWin32Error()}"); + } + } + public override void WriteAllText(string path, string contents) { File.WriteAllText(path, contents); @@ -178,6 +191,15 @@ public override void ReadAllText_FileShouldNotBeFound(string path) [DllImport("kernel32", SetLastError = true)] private static extern bool MoveFileEx(string existingFileName, string newFileName, int flags); + [DllImport("libc", EntryPoint = "link", SetLastError = true)] + private static extern int MacCreateHardLink(string oldPath, string newPath); + + [DllImport("kernel32.dll", EntryPoint = "CreateHardLink", SetLastError = true, CharSet = CharSet.Unicode)] + private static extern bool WindowsCreateHardLink( + string newLinkFileName, + string existingFileName, + IntPtr securityAttributes); + private static void RetryOnException(Action action) { for (int i = 0; i < 10; i++) diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs index d1b56fc487..55961a00cc 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/GitFilesTests.cs @@ -42,11 +42,6 @@ public void CreateFileTest() [TestCase, Order(2)] public void CreateHardLinkTest() { - if (!this.fileSystem.SupportsHardlinkCreation) - { - return; - } - string existingFileName = "fileToLinkTo.txt"; string existingFilePath = this.Enlistment.GetVirtualPathTo(existingFileName); GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, existingFileName); diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs index ba72a6a093..0dc57253c5 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs @@ -120,7 +120,7 @@ public void ModifiedPathsSavedAfterRemount(FileSystemRunner fileSystem) } } - [TestCaseSource(typeof(HardLinkRunners), HardLinkRunners.TestRunners)] + [TestCaseSource(typeof(FileSystemRunner), FileSystemRunner.TestRunners)] public void ModifiedPathsCorrectAfterHardLinking(FileSystemRunner fileSystem) { const string ExpectedModifiedFilesContentsAfterHardlinks = @@ -162,34 +162,5 @@ A LinkToFileOutsideSrc.txt reader.ReadToEnd().ShouldEqual(ExpectedModifiedFilesContentsAfterHardlinks); } } - - private class HardLinkRunners - { - public const string TestRunners = "Runners"; - - public static object[] Runners - { - get - { - List hardLinkRunners = new List(); - foreach (object[] runner in FileSystemRunner.Runners.ToList()) - { - FileSystemRunner fileSystem = runner.ToList().First() as FileSystemRunner; - if (fileSystem.SupportsHardlinkCreation) - { - hardLinkRunners.Add(new object[] { fileSystem }); - } - } - - if (hardLinkRunners.Count > 0) - { - return hardLinkRunners.ToArray(); - } - - // Always return at least one runner that supports creating hard links - return new[] { new object[] { new BashRunner() } }; - } - } - } } } diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs index e8a36a23c5..f0d4305f68 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs @@ -32,11 +32,6 @@ public void StageBasicTest() [TestCase, Order(3)] public void AddAndStageHardLinksTest() { - if (!this.FileSystem.SupportsHardlinkCreation) - { - return; - } - this.CreateHardLink("ReadmeLink.md", "Readme.md"); this.ValidateGitCommand("add ReadmeLink.md"); this.RunGitCommand("commit -m \"Created ReadmeLink.md\""); diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitRepoTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitRepoTests.cs index 932ee1eaa7..9200be7c55 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitRepoTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitRepoTests.cs @@ -224,14 +224,8 @@ protected void CreateHardLink(string newLinkFileName, string existingFileName) string virtualNewLinkFile = Path.Combine(this.Enlistment.RepoRoot, newLinkFileName); string controlNewLinkFile = Path.Combine(this.ControlGitRepo.RootPath, newLinkFileName); - // GitRepoTests are only run with SystemIORunner (which does not support hardlink - // creation) so use a BashRunner instead. - this.FileSystem.SupportsHardlinkCreation.ShouldBeFalse( - "If this.FileSystem.SupportsHardlinkCreation is true, CreateHardLink no longer needs to create a BashRunner"); - FileSystemRunner runner = new BashRunner(); - - runner.CreateHardLink(virtualNewLinkFile, virtualExistingFile); - runner.CreateHardLink(controlNewLinkFile, controlExistingFile); + this.FileSystem.CreateHardLink(virtualNewLinkFile, virtualExistingFile); + this.FileSystem.CreateHardLink(controlNewLinkFile, controlExistingFile); } protected void SetFileAsReadOnly(string filePath) From bff758ce9a3219fa5b975c1bd4f036ce39c402e6 Mon Sep 17 00:00:00 2001 From: William Baker Date: Thu, 13 Sep 2018 14:29:33 -0700 Subject: [PATCH 6/9] Remove unused using statements --- .../Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs index 0dc57253c5..5348ce2685 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerTestCase/ModifiedPathsTests.cs @@ -3,9 +3,7 @@ using GVFS.FunctionalTests.Tools; using GVFS.Tests.Should; using NUnit.Framework; -using System.Collections.Generic; using System.IO; -using System.Linq; namespace GVFS.FunctionalTests.Tests.EnlistmentPerTestCase { From efa70da9cf608c75a8b9c1ec284c46762b164eb4 Mon Sep 17 00:00:00 2001 From: William Baker Date: Thu, 13 Sep 2018 16:47:59 -0700 Subject: [PATCH 7/9] Fix AddStageTests on Windows --- GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs index f0d4305f68..d4e834dad4 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/AddStageTests.cs @@ -56,7 +56,7 @@ public void StageAllowsPlaceholderCreation() private void CommandAllowsPlaceholderCreation(string command, params string[] fileToReadPathParts) { string fileToRead = Path.Combine(fileToReadPathParts); - this.EditFile($"Some new content for {command}.", "Readme.md"); + this.EditFile($"Some new content for {command}.", "Protocol.md"); ManualResetEventSlim resetEvent = GitHelpers.RunGitCommandWithWaitAndStdIn(this.Enlistment, resetTimeout: 3000, command: $"{command} -p", stdinToQuit: "q", processId: out _); this.FileContentsShouldMatch(fileToRead); this.ValidateGitCommand("--no-optional-locks status"); From bc6f8962f4b638b7ca4114c4cf892757d78fe663 Mon Sep 17 00:00:00 2001 From: William Baker Date: Fri, 14 Sep 2018 08:23:58 -0700 Subject: [PATCH 8/9] Temporary fix: look up vnode path earlier in callback --- .../PrjFSKext/PrjFSKext/KauthHandler.cpp | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp b/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp index acce65bce3..3fbf03713d 100644 --- a/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp +++ b/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp @@ -48,6 +48,7 @@ static bool TrySendRequestAndWaitForResponse( const VirtualizationRoot* root, MessageType messageType, const vnode_t vnode, + const char* vnodePath, int pid, const char* procname, int* kauthResult, @@ -253,14 +254,23 @@ static int HandleVnodeOperation( vnode_t currentVnode = reinterpret_cast(arg1); // arg2 is the (vnode_t) parent vnode int* kauthError = reinterpret_cast(arg3); + int kauthResult = KAUTH_RESULT_DEFER; + + const char* vnodePath = nullptr; + char vnodePathBuffer[PrjFSMaxPath]; + int vnodePathLength = PrjFSMaxPath; VirtualizationRoot* root = nullptr; vtype vnodeType; uint32_t currentVnodeFileFlags; int pid; char procname[MAXCOMLEN + 1]; - - int kauthResult = KAUTH_RESULT_DEFER; + + // TODO(Mac): Issue #271 - Reduce reliance on vn_getpath + if (0 == vn_getpath(currentVnode, vnodePathBuffer, &vnodePathLength)) + { + vnodePath = vnodePathBuffer; + } if (!ShouldHandleVnodeOpEvent( context, @@ -292,6 +302,7 @@ static int HandleVnodeOperation( root, MessageType_KtoU_EnumerateDirectory, currentVnode, + vnodePath, pid, procname, &kauthResult, @@ -308,6 +319,7 @@ static int HandleVnodeOperation( root, MessageType_KtoU_NotifyDirectoryPreDelete, currentVnode, + vnodePath, pid, procname, &kauthResult, @@ -325,6 +337,7 @@ static int HandleVnodeOperation( root, MessageType_KtoU_NotifyFilePreDelete, currentVnode, + vnodePath, pid, procname, &kauthResult, @@ -351,6 +364,7 @@ static int HandleVnodeOperation( root, MessageType_KtoU_HydrateFile, currentVnode, + vnodePath, pid, procname, &kauthResult, @@ -428,6 +442,7 @@ static int HandleFileOpOperation( root, messageType, currentVnodeFromPath, + newPath, pid, procname, &kauthResult, @@ -439,7 +454,7 @@ static int HandleFileOpOperation( else if (KAUTH_FILEOP_CLOSE == action) { vnode_t currentVnode = reinterpret_cast(arg0); - // arg1 is the (const char *) path + const char* path = (const char*)arg1; int closeFlags = static_cast(arg2); if (vnode_isdir(currentVnode)) @@ -476,6 +491,7 @@ static int HandleFileOpOperation( root, MessageType_KtoU_NotifyFileModified, currentVnode, + path, pid, procname, &kauthResult, @@ -492,6 +508,7 @@ static int HandleFileOpOperation( root, MessageType_KtoU_NotifyFileCreated, currentVnode, + path, pid, procname, &kauthResult, @@ -647,6 +664,7 @@ static bool TrySendRequestAndWaitForResponse( const VirtualizationRoot* root, MessageType messageType, const vnode_t vnode, + const char* vnodePath, int pid, const char* procname, int* kauthResult, @@ -657,11 +675,10 @@ static bool TrySendRequestAndWaitForResponse( OutstandingMessage message; message.receivedResponse = false; - char vnodePath[PrjFSMaxPath]; - int vnodePathLength = PrjFSMaxPath; - if (vn_getpath(vnode, vnodePath, &vnodePathLength)) + if (nullptr == vnodePath) { - KextLog_Error("Unable to resolve a vnode to its path"); + // Default error code is EACCES. See errno.h for more codes. + *kauthError = EAGAIN; *kauthResult = KAUTH_RESULT_DENY; return false; } From 1d0beff80599463ee944bd42a518494e04ee292d Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 17 Sep 2018 08:40:03 -0700 Subject: [PATCH 9/9] Add comment --- ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp b/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp index 3fbf03713d..6868047a9d 100644 --- a/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp +++ b/ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp @@ -267,6 +267,8 @@ static int HandleVnodeOperation( char procname[MAXCOMLEN + 1]; // TODO(Mac): Issue #271 - Reduce reliance on vn_getpath + // Call vn_getpath first when the cache is hottest to increase the chances + // of successfully getting the path if (0 == vn_getpath(currentVnode, vnodePathBuffer, &vnodePathLength)) { vnodePath = vnodePathBuffer;