mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-12 10:19:18 +02:00
NTFileSystemAdapter: Do not handle unexpected IFileSystem exceptions
This commit is contained in:
parent
6cab13c1c9
commit
86afb5af33
4 changed files with 173 additions and 58 deletions
|
@ -24,10 +24,17 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "GetFileInformation on '{0}' failed. {1}", path, status);
|
{
|
||||||
result = null;
|
NTStatus status = ToNTStatus(ex);
|
||||||
return status;
|
Log(Severity.Verbose, "GetFileInformation on '{0}' failed. {1}", path, status);
|
||||||
|
result = null;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (informationClass)
|
switch (informationClass)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.IO;
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary
|
namespace SMBLibrary
|
||||||
|
@ -66,9 +66,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "QueryDirectory: Error querying '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "QueryDirectory: Error querying '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
entries = new List<FileSystemEntry>();
|
entries = new List<FileSystemEntry>();
|
||||||
entries.Add(entry);
|
entries.Add(entry);
|
||||||
|
|
|
@ -28,9 +28,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "SetFileInformation: Failed to set file attributes on '{0}'. {1}.", fileHandle.Path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "SetFileInformation: Failed to set file attributes on '{0}'. {1}.", fileHandle.Path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -39,9 +46,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "SetFileInformation: Failed to set file dates on '{0}'. {1}.", fileHandle.Path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "SetFileInformation: Failed to set file dates on '{0}'. {1}.", fileHandle.Path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NTStatus.STATUS_SUCCESS;
|
return NTStatus.STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -71,9 +85,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "SetFileInformation: Cannot rename '{0}' to '{1}'. {2}.", fileHandle.Path, newFileName, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "SetFileInformation: Cannot rename '{0}' to '{1}'. {2}.", fileHandle.Path, newFileName, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileHandle.Path = newFileName;
|
fileHandle.Path = newFileName;
|
||||||
return NTStatus.STATUS_SUCCESS;
|
return NTStatus.STATUS_SUCCESS;
|
||||||
|
@ -95,9 +116,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Information, "SetFileInformation: Error deleting '{0}'. {1}.", fileHandle.Path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Information, "SetFileInformation: Error deleting '{0}'. {1}.", fileHandle.Path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NTStatus.STATUS_SUCCESS;
|
return NTStatus.STATUS_SUCCESS;
|
||||||
|
@ -111,9 +139,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "SetFileInformation: Cannot set allocation for '{0}'. {1}.", fileHandle.Path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "SetFileInformation: Cannot set allocation for '{0}'. {1}.", fileHandle.Path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NTStatus.STATUS_SUCCESS;
|
return NTStatus.STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -126,9 +161,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "SetFileInformation: Cannot set end of file for '{0}'. {1}.", fileHandle.Path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "SetFileInformation: Cannot set end of file for '{0}'. {1}.", fileHandle.Path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NTStatus.STATUS_SUCCESS;
|
return NTStatus.STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "CreateFile: Error retrieving '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error retrieving '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createDisposition == CreateDisposition.FILE_OPEN)
|
if (createDisposition == CreateDisposition.FILE_OPEN)
|
||||||
|
@ -116,9 +123,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileStatus = FileStatus.FILE_CREATED;
|
fileStatus = FileStatus.FILE_CREATED;
|
||||||
}
|
}
|
||||||
|
@ -154,9 +168,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileStatus = FileStatus.FILE_CREATED;
|
fileStatus = FileStatus.FILE_CREATED;
|
||||||
}
|
}
|
||||||
|
@ -193,9 +214,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileStatus = FileStatus.FILE_OVERWRITTEN;
|
fileStatus = FileStatus.FILE_OVERWRITTEN;
|
||||||
}
|
}
|
||||||
|
@ -208,9 +236,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -228,9 +263,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileStatus = FileStatus.FILE_SUPERSEDED;
|
fileStatus = FileStatus.FILE_SUPERSEDED;
|
||||||
}
|
}
|
||||||
|
@ -282,9 +324,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString);
|
Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString);
|
||||||
|
@ -338,9 +387,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "ReadFile: Cannot read '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "ReadFile: Cannot read '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead < maxCount)
|
if (bytesRead < maxCount)
|
||||||
|
@ -370,9 +426,16 @@ namespace SMBLibrary
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||||
Log(Severity.Verbose, "WriteFile: Cannot write '{0}'. {1}.", path, status);
|
{
|
||||||
return status;
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "WriteFile: Cannot write '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
numberOfBytesWritten = data.Length;
|
numberOfBytesWritten = data.Length;
|
||||||
return NTStatus.STATUS_SUCCESS;
|
return NTStatus.STATUS_SUCCESS;
|
||||||
|
@ -444,11 +507,7 @@ namespace SMBLibrary
|
||||||
/// <param name="exception">IFileSystem exception</param>
|
/// <param name="exception">IFileSystem exception</param>
|
||||||
private static NTStatus ToNTStatus(Exception exception)
|
private static NTStatus ToNTStatus(Exception exception)
|
||||||
{
|
{
|
||||||
if (exception is ArgumentException)
|
if (exception is DirectoryNotFoundException)
|
||||||
{
|
|
||||||
return NTStatus.STATUS_OBJECT_PATH_SYNTAX_BAD;
|
|
||||||
}
|
|
||||||
else if (exception is DirectoryNotFoundException)
|
|
||||||
{
|
{
|
||||||
return NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
|
return NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue