Skip to content

Commit

Permalink
Add rdb update command
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikstengaard committed Dec 1, 2022
1 parent 1c64238 commit fc7e07d
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/Hst.Imager.ConsoleApp/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ await Execute(new RdbInitCommand(GetLogger<RdbInitCommand>(), GetCommandHelper()
await GetPhysicalDrives(), path, name, ParseSize(size), chs, rdbBlockLo));
}

public static async Task RdbUpdate(string path, uint? flags, uint? hostId, string diskProduct,
string diskRevision, string diskVendor)
{
await Execute(new RdbUpdateCommand(GetLogger<RdbUpdateCommand>(), GetCommandHelper(),
await GetPhysicalDrives(), path, flags, hostId, diskProduct, diskRevision, diskVendor));
}

public static async Task RdbFsAdd(string path, string fileSystemPath, string dosType, string fileSystemName)
{
await Execute(new RdbFsAddCommand(GetLogger<RdbFsAddCommand>(), GetCommandHelper(),
Expand Down
6 changes: 5 additions & 1 deletion src/Hst.Imager.ConsoleApp/Presenters/RdbInfoPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ public static string Present(RdbInfo rdbInfo)
{
Columns = new[]
{
new Column { Name = "Name" },
new Column { Name = "Product" },
new Column { Name = "Vendor" },
new Column { Name = "Revision" },
new Column { Name = "Size", Alignment = ColumnAlignment.Right },
new Column { Name = "Cylinders", Alignment = ColumnAlignment.Right },
new Column { Name = "Heads", Alignment = ColumnAlignment.Right },
new Column { Name = "Sectors", Alignment = ColumnAlignment.Right },
new Column { Name = "Block Size", Alignment = ColumnAlignment.Right },
new Column { Name = "Flags", Alignment = ColumnAlignment.Right },
new Column { Name = "Host Id", Alignment = ColumnAlignment.Right },
new Column { Name = "Rdb Block Lo", Alignment = ColumnAlignment.Right },
new Column { Name = "Rdb Block Hi", Alignment = ColumnAlignment.Right }
},
Expand All @@ -48,6 +50,8 @@ public static string Present(RdbInfo rdbInfo)
rigidDiskBlock.Heads.ToString(),
rigidDiskBlock.Sectors.ToString(),
rigidDiskBlock.BlockSize.ToString(),
rigidDiskBlock.Flags.ToString(),
rigidDiskBlock.HostId.ToString(),
rigidDiskBlock.RdbBlockLo.ToString(),
rigidDiskBlock.RdbBlockHi.ToString()
}
Expand Down
40 changes: 40 additions & 0 deletions src/Hst.Imager.ConsoleApp/RdbCommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static Command CreateRdbCommand()
rdbCommand.AddCommand(CreateRdbInit());
rdbCommand.AddCommand(CreateRdbFs());
rdbCommand.AddCommand(CreateRdbPart());
rdbCommand.AddCommand(CreateRdbUpdate());

return rdbCommand;
}
Expand Down Expand Up @@ -573,5 +574,44 @@ private static Command CreateRdbPartFormat()

return rdbPartFormatCommand;
}

private static Command CreateRdbUpdate()
{
var pathArgument = new Argument<string>(
name: "Path",
description: "Path to physical drive or image file.");

var flagsOption = new Option<uint?>(
new[] { "--flags", "-f" },
description: "Flags.");

var hostIdOption = new Option<uint?>(
new[] { "--host-id", "-h" },
description: "Host id.");

var diskProductOption = new Option<string>(
new[] { "--disk-product", "-dp" },
description: "Disk product.");

var diskRevisionOption = new Option<string>(
new[] { "--disk-revision", "-dr" },
description: "Disk revision.");

var diskVendorOption = new Option<string>(
new[] { "--disk-vendor", "-dv" },
description: "Disk vendor.");

var command = new Command("update", "Update Rigid Disk Block.");
command.SetHandler(CommandHandler.RdbUpdate, pathArgument, flagsOption, hostIdOption,
diskProductOption, diskRevisionOption, diskVendorOption);
command.AddArgument(pathArgument);
command.AddOption(flagsOption);
command.AddOption(hostIdOption);
command.AddOption(diskProductOption);
command.AddOption(diskRevisionOption);
command.AddOption(diskVendorOption);

return command;
}
}
}
47 changes: 42 additions & 5 deletions src/Hst.Imager.ConsoleApp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ Example of initializing Rigid Disk Block using cylinders, heads and sectors on a
hst.imager rdb init 4gb.vhd -chs 800,16,63
```

## Update Rigid Disk Block

Updates Rigid Disk Block properties:
- Flags
- Host id
- Disk product
- Disk revision
- Disk vendor

Example of displaying usage for updating Rigid Disk Block:
```
hst.imager rdb update
```

Example of updating flags property to 7 in Rigid Disk Block on a 4GB vhd image file:
```
hst.imager rdb update 4gb.vhd --flags 7
```

## Add file system to Rigid Disk Block

Adds a file system to Rigid Disk Block.
Expand Down Expand Up @@ -355,7 +374,10 @@ hst.imager rdb fs import 4gb.vhd amiga-os-310-install.adf DOS3 FastFileSystem

## Update file system in Rigid Disk Block

Updates a file system in Rigid Disk Block.
Updates file system properties in Rigid Disk Block:
- DOS type
- File system name
- File system data

DOS Type updates will also update partitions using Dos type defined for file system.

Expand All @@ -364,11 +386,16 @@ Example of displaying usage for updating a file system in Rigid Disk Block:
hst.imager rdb fs update
```

Example of updating file system number 1 with dos type PFS3 in Rigid Disk Block on a 4GB vhd image file:
Example of updating file system number 1 with dos type property to PFS3 in Rigid Disk Block on a 4GB vhd image file:
```
hst.imager rdb fs update 4gb.vhd 1 --dos-type PFS3
```

Example of updating file system number 1 with data from file in Rigid Disk Block on a 4GB vhd image file:
```
hst.imager rdb fs update 4gb.vhd 1 --path pfs3aio
```

## Add partition to Rigid Disk Block

Adds a partition to Rigid Disk Block with a defined size.
Expand Down Expand Up @@ -473,19 +500,29 @@ hst.imager rdb part kill 4gb.vhd 1 50465301

## Update partition in Rigid Disk Block

Updates a partition in Rigid Disk Block.
Updates partition properties in Rigid Disk Block:
- Name
- DOS Type
- Reserved
- Pre alloc
- Buffers
- Max transfer
- Mask
- No mount
- Bootable
- Priority

Example of displaying usage for updating a partition in Rigid Disk Block:
```
hst.imager rdb part update
```

Example of updating partition number 1 setting it bootable in Rigid Disk Block on a 4GB vhd image file:
Example of updating partition number 1 setting bootable property to true in Rigid Disk Block on a 4GB vhd image file:
```
hst.imager rdb part update 4gb.vhd 1 --bootable true
```

Example of updating partition number 1 setting max transfer to 130560 in Rigid Disk Block on a 4GB vhd image file:
Example of updating partition number 1 setting max transfer property to 130560 in Rigid Disk Block on a 4GB vhd image file:
```
hst.imager rdb part update 4gb.vhd 1 --max-transfer 130560
```
111 changes: 111 additions & 0 deletions src/Hst.Imager.Core/Commands/RdbUpdateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
namespace Hst.Imager.Core.Commands;

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Amiga.RigidDiskBlocks;
using Hst.Core;
using Microsoft.Extensions.Logging;

public class RdbUpdateCommand : CommandBase
{
private readonly ILogger<RdbUpdateCommand> logger;
private readonly ICommandHelper commandHelper;
private readonly IEnumerable<IPhysicalDrive> physicalDrives;
private readonly string path;
private readonly uint? flags;
private readonly uint? hostId;
private readonly string diskProduct;
private readonly string diskRevision;
private readonly string diskVendor;

public RdbUpdateCommand(ILogger<RdbUpdateCommand> logger, ICommandHelper commandHelper,
IEnumerable<IPhysicalDrive> physicalDrives, string path, uint? flags, uint? hostId, string diskProduct,
string diskRevision, string diskVendor)
{
this.logger = logger;
this.commandHelper = commandHelper;
this.physicalDrives = physicalDrives;
this.path = path;
this.flags = flags;
this.hostId = hostId;
this.diskProduct = diskProduct;
this.diskRevision = diskRevision;
this.diskVendor = diskVendor;
}

public override async Task<Result> Execute(CancellationToken token)
{
OnInformationMessage($"Updating Rigid Disk Block at '{path}'");

OnDebugMessage($"Opening '{path}' as writable");

var mediaResult = commandHelper.GetWritableMedia(physicalDrives, path, allowPhysicalDrive: true);
if (mediaResult.IsFaulted)
{
return new Result(mediaResult.Error);
}

using var media = mediaResult.Value;
await using var stream = media.Stream;

OnDebugMessage("Reading Rigid Disk Block");

var rigidDiskBlock = await commandHelper.GetRigidDiskBlock(stream);

if (rigidDiskBlock == null)
{
return new Result(new Error("Rigid Disk Block not found"));
}

if (flags.HasValue)
{
OnDebugMessage($"Updating flags '{flags.Value}'");

rigidDiskBlock.Flags = flags.Value;

OnInformationMessage($"Flags '{flags.Value}'");
}

if (hostId.HasValue)
{
OnDebugMessage($"Updating host id '{hostId.Value}'");

rigidDiskBlock.HostId = hostId.Value;

OnInformationMessage($"Host id '{hostId.Value}'");
}

if (!string.IsNullOrWhiteSpace(diskProduct))
{
OnDebugMessage($"Updating disk product '{diskProduct}'");

rigidDiskBlock.DiskProduct = diskProduct;

OnInformationMessage($"Disk product '{diskProduct}'");
}

if (!string.IsNullOrWhiteSpace(diskRevision))
{
OnDebugMessage($"Updating disk revision '{diskRevision}'");

rigidDiskBlock.DiskRevision = diskRevision;

OnInformationMessage($"Disk revision '{diskRevision}'");
}

if (!string.IsNullOrWhiteSpace(diskVendor))
{
OnDebugMessage($"Updating disk vendor '{diskVendor}'");

rigidDiskBlock.DiskVendor = diskVendor;

OnInformationMessage($"Disk vendor '{diskVendor}'");
}

OnDebugMessage("Writing Rigid Disk Block");
await RigidDiskBlockWriter.WriteBlock(rigidDiskBlock, stream);

return new Result();
}
}

0 comments on commit fc7e07d

Please sign in to comment.