Files
mirror-processhacker/1.x/trunk/ProcessHacker.Native/Objects/EnlistmentHandle.cs
T
dmex 323d02277c fixed most API signatures, fixed multiple 4b NtStatus allocations in various functions
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4256 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2011-06-22 06:42:44 +00:00

175 lines
5.3 KiB
C#

/*
* Process Hacker -
* enlistment handle
*
* Copyright (C) 2009 wj32
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Runtime.InteropServices;
using ProcessHacker.Native.Api;
using ProcessHacker.Native.Security;
namespace ProcessHacker.Native.Objects
{
public class EnlistmentHandle : NativeHandle<EnlistmentAccess>
{
public static EnlistmentHandle Create(
EnlistmentAccess access,
string name,
ObjectFlags objectFlags,
DirectoryHandle rootDirectory,
ResourceManagerHandle resourceManagerHandle,
TransactionHandle transactionHandle,
EnlistmentOptions createOptions,
NotificationMask notificationMask,
IntPtr enlistmentKey
)
{
NtStatus status;
ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
IntPtr handle;
try
{
if ((status = Win32.NtCreateEnlistment(
out handle,
access,
resourceManagerHandle,
transactionHandle,
ref oa,
createOptions,
notificationMask,
enlistmentKey
)) >= NtStatus.Error)
Win32.Throw(status);
}
finally
{
oa.Dispose();
}
return new EnlistmentHandle(handle, true);
}
public static EnlistmentHandle FromHandle(IntPtr handle)
{
return new EnlistmentHandle(handle, false);
}
private EnlistmentHandle(IntPtr handle, bool owned)
: base(handle, owned)
{ }
public EnlistmentHandle(
string name,
ObjectFlags objectFlags,
DirectoryHandle rootDirectory,
ResourceManagerHandle resourceManagerHandle,
Guid guid,
EnlistmentAccess access
)
{
ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
IntPtr handle;
try
{
Win32.NtOpenEnlistment(out handle, access, resourceManagerHandle, guid, ref oa).ThrowIf();
}
finally
{
oa.Dispose();
}
this.Handle = handle;
}
public void Commit(long virtualClock)
{
Win32.NtCommitEnlistment(this, ref virtualClock).ThrowIf();
}
public void CommitComplete(long virtualClock)
{
Win32.NtCommitComplete(this, ref virtualClock).ThrowIf();
}
public EnlistmentBasicInformation GetBasicInformation()
{
EnlistmentBasicInformation basicInfo;
int retLength;
Win32.NtQueryInformationEnlistment(
this,
EnlistmentInformationClass.EnlistmentBasicInformation,
out basicInfo,
Marshal.SizeOf(typeof(EnlistmentBasicInformation)),
out retLength
).ThrowIf();
return basicInfo;
}
public void Prepare(long virtualClock)
{
Win32.NtPrepareEnlistment(this, ref virtualClock).ThrowIf();
}
public void PrepareComplete(long virtualClock)
{
Win32.NtPrepareComplete(this, ref virtualClock).ThrowIf();
}
public void PrePrepare(long virtualClock)
{
Win32.NtPrePrepareEnlistment(this, ref virtualClock).ThrowIf();
}
public void PrePrepareComplete(long virtualClock)
{
Win32.NtPrePrepareComplete(this, ref virtualClock).ThrowIf();
}
public void ReadOnly(long virtualClock)
{
Win32.NtReadOnlyEnlistment(this, ref virtualClock).ThrowIf();
}
public void Recover(IntPtr enlistmentKey)
{
Win32.NtRecoverEnlistment(this, enlistmentKey).ThrowIf();
}
public void RejectSinglePhase(long virtualClock)
{
Win32.NtSinglePhaseReject(this, ref virtualClock).ThrowIf();
}
public void Rollback(long virtualClock)
{
Win32.NtRollbackEnlistment(this, ref virtualClock).ThrowIf();
}
public void RollbackComplete(long virtualClock)
{
Win32.NtRollbackComplete(this, ref virtualClock).ThrowIf();
}
}
}