Compare commits

..

No commits in common. "ba0d08a89edb6e731bd9f81e61be38ec7e4117f2" and "4e076e90cf429456701a2e06ba93c08e1967628c" have entirely different histories.

9 changed files with 201 additions and 555 deletions

View File

@ -21,49 +21,20 @@ A C# application designed to facilitate backup and restore operations to an LTO
1. Clone the repository: 1. Clone the repository:
```bash ```bash
git clone https://github.com/MAKS-IT-COM/maksit-lto-backup git clone https://github.com/your-username/MaksIT.LTO.Backup.git
``` ```
2. Ensure `.NET8 SDK` is installed on your system. 2. Ensure `.NET Core` is installed on your system.
3. Prepare a `configuration.json` file in the application directory with the following structure: 3. Prepare a `configuration.json` file in the application directory with the following structure:
```json ```json
{ {
"TapePath": "\\\\.\\Tape0", "TapePath": "YourTapePath",
"WriteDelay": 100,
"Backups": [ "Backups": [
{ {
"Name": "Normal test", "Name": "BackupName",
"Barcode": "", "Barcode": "123456",
"LTOGen": "LTO5", "Source": "path/to/source",
"Source": { "Destination": "path/to/destination",
"LocalPath": { "LTOGen": "LTO6"
"Path": "F:\\LTO\\Backup"
}
},
"Destination": {
"LocalPath": {
"Path": "F:\\LTO\\Restore"
}
}
},
{
"Name": "Network test",
"Barcode": "",
"LTOGen": "LTO5",
"Source": {
"RemotePath": {
"Path": "\\\\nassrv0001.corp.maks-it.com\\data-1\\Users",
"PasswordCredentials": {
"Username": "",
"Password": ""
},
"Protocol": "SMB"
}
},
"Destination": {
"LocalPath": {
"Path": "F:\\LTO\\Restore"
}
}
} }
] ]
} }
@ -86,11 +57,7 @@ Upon running, the following options will be presented:
2. **Backup**: Prompts the user to select a backup task from the configured list and initiates the backup process. 2. **Backup**: Prompts the user to select a backup task from the configured list and initiates the backup process.
3. **Restore**: Restores a previously backed-up directory from the tape. 3. **Restore**: Restores a previously backed-up directory from the tape.
4. **Eject Tape**: Ejects the tape from the drive safely. 4. **Eject Tape**: Ejects the tape from the drive safely.
5. **Get device status**: Mostly used for debugging to understand if device is able to write 5. **Exit**: Exits the application.
6. **Tape Erase (Short)**:
7. **Reload configurations**
6. **Exit**: Exits the application.
### Code Overview ### Code Overview
@ -105,42 +72,13 @@ Below is an example configuration setup for an LTO-6 tape generation backup oper
```json ```json
{ {
"TapePath": "\\\\.\\Tape0", "TapePath": "\\\\.\\Tape0",
"WriteDelay": 100,
"Backups": [ "Backups": [
{ {
"Name": "Normal test", "Name": "Monthly Backup",
"Barcode": "", "Barcode": "MB12345",
"LTOGen": "LTO5", "Source": "/path/to/source",
"Source": { "Destination": "/path/to/restore",
"LocalPath": { "LTOGen": "LTO6"
"Path": "F:\\LTO\\Backup"
}
},
"Destination": {
"LocalPath": {
"Path": "F:\\LTO\\Restore"
}
}
},
{
"Name": "Network test",
"Barcode": "",
"LTOGen": "LTO5",
"Source": {
"RemotePath": {
"Path": "\\\\nassrv0001.corp.maks-it.com\\data-1\\Users",
"PasswordCredentials": {
"Username": "",
"Password": ""
},
"Protocol": "SMB"
}
},
"Destination": {
"LocalPath": {
"Path": "F:\\LTO\\Restore\\Users"
}
}
} }
] ]
} }

View File

@ -4,7 +4,6 @@ using System.Diagnostics.CodeAnalysis;
using MaksIT.LTO.Core; using MaksIT.LTO.Core;
using MaksIT.LTO.Backup.Entities; using MaksIT.LTO.Backup.Entities;
using System.Net;
namespace MaksIT.LTO.Backup; namespace MaksIT.LTO.Backup;
public class Application { public class Application {
@ -59,74 +58,7 @@ public class Application {
Console.WriteLine("Tape ejected."); Console.WriteLine("Tape ejected.");
} }
public void TapeErase() { public void CreateDescriptor(string directoryPath, string descriptorFilePath, uint blockSize) {
using var handler = new TapeDeviceHandler(_tapePath);
LoadTape(handler);
handler.SetMediaParams(LTOBlockSizes.LTO5);
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
Thread.Sleep(2000);
handler.Prepare(TapeDeviceHandler.TAPE_TENSION);
Thread.Sleep(2000);
handler.Prepare(TapeDeviceHandler.TAPE_LOCK);
Thread.Sleep(2000);
handler.Erase(TapeDeviceHandler.TAPE_ERASE_SHORT);
Thread.Sleep(2000);
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
Thread.Sleep(2000);
Console.WriteLine("Tape erased.");
}
public void GetDeviceStatus() {
using var handler = new TapeDeviceHandler(_tapePath);
handler.GetStatus();
}
public void PathAccessWrapper(WorkingFolder workingFolder, Action<string> myAction) {
if (workingFolder.LocalPath != null) {
var localPath = workingFolder.LocalPath.Path;
var path = workingFolder.LocalPath.Path;
myAction(path);
}
else if (workingFolder.RemotePath != null) {
var remotePath = workingFolder.RemotePath;
if (remotePath.Protocol == "SMB") {
NetworkCredential? networkCredential = default;
if (remotePath.PasswordCredentials != null) {
var username = remotePath.PasswordCredentials.Username;
var password = remotePath.PasswordCredentials.Password;
networkCredential = new NetworkCredential(username, password);
}
var smbPath = remotePath.Path;
if (networkCredential == null) {
throw new InvalidOperationException("Network credentials are required for remote paths.");
}
using (new NetworkConnection(smbPath, networkCredential)) {
myAction(smbPath);
}
}
}
}
public void CreateDescriptor(WorkingFolder workingFolder, string descriptorFilePath, uint blockSize) {
PathAccessWrapper(workingFolder, (directoryPath) => {
var files = Directory.GetFiles(directoryPath, "*.*", SearchOption.AllDirectories); var files = Directory.GetFiles(directoryPath, "*.*", SearchOption.AllDirectories);
// Define list to hold file descriptors // Define list to hold file descriptors
@ -171,26 +103,19 @@ public class Application {
}); });
File.WriteAllText(descriptorFilePath, descriptorJson); File.WriteAllText(descriptorFilePath, descriptorJson);
});
} }
private void ZeroFillBlocks(TapeDeviceHandler handler, int blocks, uint blockSize) { private void ZeroFillBlocks(TapeDeviceHandler handler, int blocks, uint blockSize) {
Console.WriteLine($"Writing {blocks} zero-filled blocks to tape."); Console.WriteLine($"Writing {blocks} zero-filled blocks to tape.");
Console.WriteLine($"Block Size: {blockSize}."); Console.WriteLine($"Block Size: {blockSize}.");
var writeError = 0;
for (int i = 0; i < blocks; i++) { for (int i = 0; i < blocks; i++) {
writeError = handler.WriteData(new byte[blockSize]); handler.WriteData(new byte[blockSize]);
if (writeError != 0) Thread.Sleep(100);
return;
Thread.Sleep(_configuration.WriteDelay);
} }
} }
public void WriteFilesToTape(WorkingFolder workingFolder, string descriptorFilePath, uint blockSize) { public void WriteFilesToTape(string directoryPath, string descriptorFilePath, uint blockSize) {
PathAccessWrapper(workingFolder, (directoryPath) => {
Console.WriteLine($"Writing files to tape from: {directoryPath}."); Console.WriteLine($"Writing files to tape from: {directoryPath}.");
Console.WriteLine($"Block Size: {blockSize}."); Console.WriteLine($"Block Size: {blockSize}.");
@ -221,9 +146,6 @@ public class Application {
var currentTapeBlock = (descriptorJson.Length + blockSize - 1) / blockSize; var currentTapeBlock = (descriptorJson.Length + blockSize - 1) / blockSize;
int writeError = 0;
foreach (var file in descriptor.Files) { foreach (var file in descriptor.Files) {
var filePath = Path.Combine(directoryPath, file.FilePath); var filePath = Path.Combine(directoryPath, file.FilePath);
using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
@ -237,22 +159,15 @@ public class Application {
// Zero-fill the remaining part of the buffer if the last block is smaller than blockSize // Zero-fill the remaining part of the buffer if the last block is smaller than blockSize
Array.Clear(buffer, bytesRead, buffer.Length - bytesRead); Array.Clear(buffer, bytesRead, buffer.Length - bytesRead);
} }
handler.WriteData(buffer);
writeError = handler.WriteData(buffer);
if (writeError != 0) {
Console.WriteLine($"Failed to write file: {filePath}");
return;
}
currentTapeBlock++; currentTapeBlock++;
Thread.Sleep(_configuration.WriteDelay); // Small delay between blocks Thread.Sleep(100); // Small delay between blocks
} }
} }
// write mark to indicate end of files // write mark to indicate end of files
handler.WriteMarks(TapeDeviceHandler.TAPE_FILEMARKS, 1); handler.WriteMarks(TapeDeviceHandler.TAPE_FILEMARKS, 1);
Thread.Sleep(_configuration.WriteDelay);
// write descriptor to tape // write descriptor to tape
var descriptorData = Encoding.UTF8.GetBytes(descriptorJson); var descriptorData = Encoding.UTF8.GetBytes(descriptorJson);
@ -262,13 +177,9 @@ public class Application {
var length = Math.Min(blockSize, descriptorData.Length - startIndex); var length = Math.Min(blockSize, descriptorData.Length - startIndex);
byte[] block = new byte[blockSize]; // Initialized with zeros by default byte[] block = new byte[blockSize]; // Initialized with zeros by default
Array.Copy(descriptorData, startIndex, block, 0, length); Array.Copy(descriptorData, startIndex, block, 0, length);
handler.WriteData(block);
writeError = handler.WriteData(block);
if (writeError != 0)
return;
currentTapeBlock++; currentTapeBlock++;
Thread.Sleep(_configuration.WriteDelay); // Small delay between blocks Thread.Sleep(100); // Small delay between blocks
} }
// write 3 0 filled blocks to indicate end of backup // write 3 0 filled blocks to indicate end of backup
@ -276,11 +187,8 @@ public class Application {
handler.Prepare(TapeDeviceHandler.TAPE_UNLOCK); handler.Prepare(TapeDeviceHandler.TAPE_UNLOCK);
Thread.Sleep(2000); Thread.Sleep(2000);
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND); handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
Thread.Sleep(2000); Thread.Sleep(2000);
});
} }
public BackupDescriptor? FindDescriptor(uint blockSize) { public BackupDescriptor? FindDescriptor(uint blockSize) {
@ -342,16 +250,13 @@ public class Application {
handler.Prepare(TapeDeviceHandler.TAPE_UNLOCK); handler.Prepare(TapeDeviceHandler.TAPE_UNLOCK);
Thread.Sleep(2000); Thread.Sleep(2000);
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND); handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
Thread.Sleep(2000); Thread.Sleep(2000);
return null; return null;
} }
public void RestoreDirectory(BackupDescriptor descriptor, WorkingFolder workingFolder) { public void RestoreDirectory(BackupDescriptor descriptor, string restoreDirectoryPath) {
PathAccessWrapper(workingFolder, (restoreDirectoryPath) => {
Console.WriteLine("Restoring files to directory: " + restoreDirectoryPath); Console.WriteLine("Restoring files to directory: " + restoreDirectoryPath);
Console.WriteLine("Block Size: " + descriptor.BlockSize); Console.WriteLine("Block Size: " + descriptor.BlockSize);
@ -364,6 +269,8 @@ public class Application {
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND); handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
Thread.Sleep(2000); Thread.Sleep(2000);
handler.WaitForTapeReady();
foreach (var file in descriptor.Files) { foreach (var file in descriptor.Files) {
// Set position to the start block of the file // Set position to the start block of the file
handler.SetPosition(TapeDeviceHandler.TAPE_ABSOLUTE_BLOCK, 0, file.StartBlock); handler.SetPosition(TapeDeviceHandler.TAPE_ABSOLUTE_BLOCK, 0, file.StartBlock);
@ -408,7 +315,6 @@ public class Application {
handler.SetPosition(TapeDeviceHandler.TAPE_REWIND); handler.SetPosition(TapeDeviceHandler.TAPE_REWIND);
Thread.Sleep(2000); Thread.Sleep(2000);
});
} }
public int CheckMediaSize(string ltoGen) { public int CheckMediaSize(string ltoGen) {
@ -445,7 +351,7 @@ public class Application {
Console.WriteLine("\nSelect a backup to perform:"); Console.WriteLine("\nSelect a backup to perform:");
for (int i = 0; i < _configuration.Backups.Count; i++) { for (int i = 0; i < _configuration.Backups.Count; i++) {
var backupInt = _configuration.Backups[i]; var backupInt = _configuration.Backups[i];
Console.WriteLine($"{i + 1}. Backup Name: {backupInt.Name}, Bar code {(string.IsNullOrEmpty(backupInt.Barcode) ? "None" : backupInt.Barcode)}, Source: {backupInt.Source}, Destination: {backupInt.Destination}"); Console.WriteLine($"{i + 1}. Backup Name: {backupInt.Name}, Bar code {backupInt.Barcode}, Source: {backupInt.Source}, Destination: {backupInt.Destination}");
} }
Console.Write("Enter your choice (or '0' to go back): "); Console.Write("Enter your choice (or '0' to go back): ");
@ -486,7 +392,7 @@ public class Application {
Console.WriteLine("\nSelect a backup to restore:"); Console.WriteLine("\nSelect a backup to restore:");
for (int i = 0; i < _configuration.Backups.Count; i++) { for (int i = 0; i < _configuration.Backups.Count; i++) {
var backupInt = _configuration.Backups[i]; var backupInt = _configuration.Backups[i];
Console.WriteLine($"{i + 1}. Backup Name: {backupInt.Name}, Bar code {(string.IsNullOrEmpty(backupInt.Barcode) ? "None" : backupInt.Barcode)}, Source: {backupInt.Source}, Destination: {backupInt.Destination}"); Console.WriteLine($"{i + 1}. Backup Name: {backupInt.Name}, Bar code {backupInt.Barcode}, Source: {backupInt.Source}, Destination: {backupInt.Destination}");
} }
Console.Write("Enter your choice (or '0' to go back): "); Console.Write("Enter your choice (or '0' to go back): ");

View File

@ -1,40 +1,14 @@
using System.Security; namespace MaksIT.LTO.Backup;
namespace MaksIT.LTO.Backup;
public abstract class PathBase {
public required string Path { get; set; }
}
public class LocalPath : PathBase {
// Additional properties specific to local paths can be added here
}
public class PasswordCredentials {
public required string Username { get; set; }
public required string Password { get; set; }
}
public class RemotePath : PathBase {
public PasswordCredentials? PasswordCredentials { get; set; }
public required string Protocol { get; set; } // e.g., SMB, FTP, etc.
}
public class WorkingFolder {
public LocalPath? LocalPath { get; set; }
public RemotePath? RemotePath { get; set; }
}
public class BackupItem { public class BackupItem {
public required string Name { get; set; } public required string Name { get; set; }
public required string Barcode { get; set; } public required string Barcode { get; set; }
public required WorkingFolder Source { get; set; } public required string Source { get; set; }
public required WorkingFolder Destination { get; set; } public required string Destination { get; set; }
public required string LTOGen { get; set; } public required string LTOGen { get; set; }
} }
public class Configuration { public class Configuration {
public required string TapePath { get; set; } public required string TapePath { get; set; }
public required int WriteDelay { get; set; }
public required List<BackupItem> Backups { get; set; } public required List<BackupItem> Backups { get; set; }
} }

View File

@ -18,10 +18,8 @@ class Program {
Console.WriteLine("2. Backup"); Console.WriteLine("2. Backup");
Console.WriteLine("3. Restore"); Console.WriteLine("3. Restore");
Console.WriteLine("4. Eject tape"); Console.WriteLine("4. Eject tape");
Console.WriteLine("5. Get device status"); Console.WriteLine("5. Reload configurations");
Console.WriteLine("6. Tape Erase (Short)"); Console.WriteLine("6. Exit");
Console.WriteLine("7. Reload configurations");
Console.WriteLine("8. Exit");
Console.Write("Enter your choice: "); Console.Write("Enter your choice: ");
var choice = Console.ReadLine(); var choice = Console.ReadLine();
@ -40,16 +38,11 @@ class Program {
case "4": case "4":
app.EjectTape(); app.EjectTape();
break; break;
case "5": case "5":
app.GetDeviceStatus();
break;
case "6":
app.TapeErase();
break;
case "7":
app.LoadConfiguration(); app.LoadConfiguration();
break; break;
case "8": case "6":
Console.WriteLine("Exiting..."); Console.WriteLine("Exiting...");
return; return;
default: default:

View File

@ -1,41 +1,19 @@
{ {
"TapePath": "\\\\.\\Tape0", "TapePath": "\\\\.\\Tape0",
"WriteDelay": 100,
"Backups": [ "Backups": [
{ {
"Name": "Normal test", "Name": "Test",
"Barcode": "", "Barcode": "",
"LTOGen": "LTO5", "Source": "F:\\LTO\\Backup",
"Source": { "Destination": "F:\\LTO\\Restore",
"LocalPath": { "LTOGen": "LTO5"
"Path": "F:\\LTO\\Backup"
}
},
"Destination": {
"LocalPath": {
"Path": "F:\\LTO\\Restore"
}
}
}, },
{ {
"Name": "Network test", "Name": "Drivers",
"Barcode": "", "Barcode": "",
"LTOGen": "LTO5", "Source": "D:\\Drivers",
"Source": { "Destination": "F:\\LTO\\Restore",
"RemotePath": { "LTOGen": "LTO5"
"Path": "\\\\nassrv0002.corp.maks-it.com\\data-1\\Users",
"PasswordCredentials": {
"Username": "",
"Password": ""
},
"Protocol": "SMB"
}
},
"Destination": {
"LocalPath": {
"Path": "F:\\LTO\\Restore"
}
}
} }
] ]
} }

View File

@ -1,37 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MaksIT.LTO.Core;
public class DriverManager {
public static void RestartDriver(string deviceName) {
string script = $@"
$device = Get-PnpDevice -FriendlyName '{deviceName}'
Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
Start-Sleep -Seconds 5
Enable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
";
ProcessStartInfo psi = new ProcessStartInfo {
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy Bypass -Command \"{script}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
using (Process process = Process.Start(psi)) {
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
Console.WriteLine(output);
if (!string.IsNullOrEmpty(error)) {
Console.WriteLine($"Error: {error}");
}
}
}
}

View File

@ -1,102 +0,0 @@
using System.Net;
using System.Runtime.InteropServices;
namespace MaksIT.LTO.Core;
//public void RestoreFilesFromSmbShare(string smbPath, string username, string password, string domain, string restoreDirectory) {
// var credentials = new NetworkCredential(username, password, domain);
// using (new NetworkConnection(smbPath, credentials)) {
// var files = Directory.GetFiles(smbPath, "*.*", SearchOption.AllDirectories);
// foreach (var file in files) {
// var relativePath = Path.GetRelativePath(smbPath, file);
// var destinationPath = Path.Combine(restoreDirectory, relativePath);
// Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
// File.Copy(file, destinationPath, overwrite: true);
// Console.WriteLine($"Restored file: {file} to {destinationPath}");
// }
// }
//}
public class NetworkConnection : IDisposable {
private readonly string _networkName;
public NetworkConnection(string networkName, NetworkCredential credentials) {
_networkName = networkName;
var netResource = new NetResource {
Scope = ResourceScope.GlobalNetwork,
ResourceType = ResourceType.Disk,
DisplayType = ResourceDisplayType.Share,
RemoteName = networkName
};
var result = WNetAddConnection2(netResource, credentials.Password, credentials.UserName, 0);
if (result != 0) {
throw new InvalidOperationException($"Error connecting to remote share: {result}");
}
}
~NetworkConnection() {
Dispose(false);
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
WNetCancelConnection2(_networkName, 0, true);
}
[DllImport("mpr.dll")]
private static extern int WNetAddConnection2(NetResource netResource, string password, string username, int flags);
[DllImport("mpr.dll")]
private static extern int WNetCancelConnection2(string name, int flags, bool force);
[StructLayout(LayoutKind.Sequential)]
public class NetResource {
public ResourceScope Scope;
public ResourceType ResourceType;
public ResourceDisplayType DisplayType;
public int Usage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
public enum ResourceScope : int {
Connected = 1,
GlobalNetwork,
Remembered,
Recent,
Context
}
public enum ResourceType : int {
Any = 0,
Disk = 1,
Print = 2,
Reserved = 8
}
public enum ResourceDisplayType : int {
Generic = 0x0,
Domain = 0x01,
Server = 0x02,
Share = 0x03,
File = 0x04,
Group = 0x05,
Network = 0x06,
Root = 0x07,
Shareadmin = 0x08,
Directory = 0x09,
Tree = 0x0a,
Ndscontainer = 0x0b
}
}

View File

@ -82,7 +82,7 @@ public partial class TapeDeviceHandler : IDisposable {
} }
public int WriteData(byte[] data) { public void WriteData(byte[] data) {
IntPtr unmanagedPointer = Marshal.AllocHGlobal(data.Length); IntPtr unmanagedPointer = Marshal.AllocHGlobal(data.Length);
try { try {
Marshal.Copy(data, 0, unmanagedPointer, data.Length); Marshal.Copy(data, 0, unmanagedPointer, data.Length);
@ -94,14 +94,11 @@ public partial class TapeDeviceHandler : IDisposable {
else { else {
int error = Marshal.GetLastWin32Error(); int error = Marshal.GetLastWin32Error();
Console.WriteLine($"Write Data: Failed with error code {error}"); Console.WriteLine($"Write Data: Failed with error code {error}");
return error;
} }
} }
finally { finally {
Marshal.FreeHGlobal(unmanagedPointer); Marshal.FreeHGlobal(unmanagedPointer);
} }
return 0;
} }
public byte[] ReadData(uint length) { public byte[] ReadData(uint length) {
@ -154,8 +151,10 @@ public partial class TapeDeviceHandler : IDisposable {
if (errorCode == 0) // Assuming 0 means success/ready if (errorCode == 0) // Assuming 0 means success/ready
{ {
isReady = true; isReady = true;
Console.WriteLine("Tape is ready.");
} }
else { else {
Console.WriteLine($"Tape not ready, status code: {errorCode}. Retrying...");
Thread.Sleep(1000); // Wait 1 second before checking again Thread.Sleep(1000); // Wait 1 second before checking again
} }
} }

View File

@ -325,7 +325,7 @@ public partial class TapeDeviceHandler : IDisposable {
/// Erase the tape /// Erase the tape
/// </summary> /// </summary>
/// <param name="type">The type of erase operation. Valid values are <see cref="TAPE_ERASE_SHORT"/> and <see cref="TAPE_ERASE_LONG"/>.</param> /// <param name="type">The type of erase operation. Valid values are <see cref="TAPE_ERASE_SHORT"/> and <see cref="TAPE_ERASE_LONG"/>.</param>
public int Erase(uint type) { public void Erase(uint type) {
TAPE_ERASE erase = new TAPE_ERASE { TAPE_ERASE erase = new TAPE_ERASE {
Type = type, Type = type,
Immediate = 0 Immediate = 0
@ -343,14 +343,11 @@ public partial class TapeDeviceHandler : IDisposable {
else { else {
int error = Marshal.GetLastWin32Error(); int error = Marshal.GetLastWin32Error();
Console.WriteLine($"Erase Tape: Failed with error code {error}"); Console.WriteLine($"Erase Tape: Failed with error code {error}");
return error;
} }
} }
finally { finally {
Marshal.FreeHGlobal(inBuffer); Marshal.FreeHGlobal(inBuffer);
} }
return 0;
} }
/// <summary> /// <summary>