RamDrive.OsfMount 3.1.1001.4

.NET 6.0 .NET Framework 4.6.2
dotnet add package RamDrive.OsfMount --version 3.1.1001.4
NuGet\Install-Package RamDrive.OsfMount -Version 3.1.1001.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RamDrive.OsfMount" Version="3.1.1001.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RamDrive.OsfMount --version 3.1.1001.4
#r "nuget: RamDrive.OsfMount, 3.1.1001.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RamDrive.OsfMount as a Cake Addin
#addin nuget:?package=RamDrive.OsfMount&version=3.1.1001.4

// Install RamDrive.OsfMount as a Cake Tool
#tool nuget:?package=RamDrive.OsfMount&version=3.1.1001.4

RamDrive.OsfMount

RamDrive.OsfMount is a wrapper library for OSForensics OSFMount that allows you to create and manage disks mounted in RAM (no other features provided by design). Supports Windows 11, 10, 8 (theoretical, not tested), 7 SP1 (theoretical, not tested), only 64 bit (there is OSFMount v2 for 32-bit support, but this library does not support this outdated version).

Get Started

Requirements

Library targeting:

  • .NET Framework (4.6.2, 4.7, 4.7.1, 4.7.2, 4.8)
  • .NET (6-windows-only, 7-windows-only)

If the target platform of the project in which you are going to use this library is not Windows, then there is no point in using it. In the case of a cross-platform project, you will need to use the Conditional PackageReference, where for Windows will be used this library.

Install Package

Using Package Manager Console:

PM> Install-Package RamDrive.OsfMount

Using .NET CLI:

dotnet add package RamDrive.OsfMount

Usage

Please note that all operations require your application to have administrator privileges.

Mount ram drive with size 1.5Gb, under drive letter 'X' and file system NTFS:

using RamDrive.OsfMount;
using ByteSizeLib;

var possibleError = await OsfMountRamDrive.Mount(
    ByteSize.FromGibiBytes(1.5),
    DriveLetter.X,
    FileSystemType.NTFS
);

Unmount ram drive under drive letter 'X':

using RamDrive.OsfMount;
using ByteSizeLib;

var possibleError = await OsfMountRamDrive.Unmount(DriveLetter.X);

Force unmount ram drive under drive letter 'X' (force unmount will be abort all drive under letter 'X' operations from other processes in system if exists):

using RamDrive.OsfMount;
using ByteSizeLib;

var possibleError = await OsfMountRamDrive.ForceUnmount(DriveLetter.X);

How to handle errors? Type of returned objects — types of errors described using discriminated union (OneOf type library), which have Switch and Match methods (for pattern matching). See:

using RamDrive.OsfMount;
using ByteSizeLib;
using OneOf;

var result = await OsfMountRamDrive.Mount(
     ByteSize.FromMebiBytes(300),
     DriveLettersForUsage.First(),
     FileSystemType.NTFS);
 
// Log if some error
result?.Switch(
    driveLetterInUseOrNotAllowed => Logger.LogDriveLetterIllegal(driveLetterInUseOrNotAllowed.DriveLetter),
    tooLowSize => Logger.TooLowSizeForDrive(tooLowSize.Size),
    driveSizeCannotBeGreaterThenRamCapacity => Logger.TooBigDriveSize(driveSizeCannotBeGreaterThenRamCapacity.Size)
);

// Or create error message or nothing if some error
string? message = result?.Match(
    case1 => $"Drive letter {case1.DriveLetter} in use or not allowed",
    case2 => $"Drive size {case2.Size} too low",
    case3 => "Drive size cannot be greater then total ram capacity"
);

Or, you can use object-oriented approach with disposable object:

using (var drive = await OsfMountRamDrive.New(ByteSize.FromMebiBytes(512), FileSystemType.NTFS))
{
  string drivePath = drive.Path;
  DriveLetter driveLetter = drive.DriveLetter;
  
  // use drive ...
} 

Contributing

See CONTRIBUTION.md.

Changelog/Version history

See VERSION_HISTORY.md

License

RamDrive.OsfMount is Copyright © 2023 flexxxxer Aleksandr under the Apache License, Version 2.0.

Product Compatible and additional computed target framework versions.
.NET net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.1001.4 530 4/21/2023
3.1.1001.3 485 4/8/2023
3.1.1001.2 542 1/28/2023
3.1.1001.1 537 1/28/2023
3.1.1001 554 1/22/2023