2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Threading;
|
|
|
|
using Microsoft.Singularity.Directory;
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.Singularity.FileSystem;
|
|
|
|
using Microsoft.Singularity.V1.Services;
|
|
|
|
|
|
|
|
using Microsoft.SingSharp.Reflection;
|
|
|
|
using Microsoft.Singularity.Applications;
|
|
|
|
using Microsoft.Singularity.Io;
|
|
|
|
using Microsoft.Singularity.Configuration;
|
|
|
|
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
|
|
|
|
|
|
|
namespace Microsoft.Singularity.Applications
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
[ConsoleCategory(HelpMessage="Mount CD device", DefaultAction=true)]
|
|
|
|
internal class Parameters
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
[InputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
|
|
|
|
|
|
|
[OutputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
|
|
|
|
|
|
|
[Endpoint]
|
|
|
|
public readonly TRef<DirectoryServiceContract.Imp:Start> nsRef;
|
|
|
|
|
|
|
|
[StringParameter( "devName", Mandatory=true, Position=0, HelpMessage="Name of device.")]
|
|
|
|
internal string device;
|
|
|
|
|
|
|
|
[StringParameter( "location", Mandatory=true, Position=1, HelpMessage="Mount Location.")]
|
|
|
|
internal string location;
|
|
|
|
|
|
|
|
[BoolParameter( "s", Default=false, HelpMessage="Silent.")]
|
|
|
|
internal bool silent;
|
2008-11-17 18:29:00 -05:00
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
reflective internal Parameters();
|
|
|
|
|
|
|
|
internal int AppMain() {
|
|
|
|
return CdMount.AppMain(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CdMount
|
2008-11-17 18:29:00 -05:00
|
|
|
{
|
2008-03-05 09:52:00 -05:00
|
|
|
public static void WriteLineWrapper(string format, params object[] args) {
|
|
|
|
if (!silent) {
|
|
|
|
Console.WriteLine(format, args);
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
public static void WriteWrapper(string format, params object[] args) {
|
|
|
|
if (!silent) {
|
|
|
|
Console.Write(format, args);
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
public static bool silent = false;
|
2008-11-17 18:29:00 -05:00
|
|
|
public const string ControlLocation = "/service/services/iso9660";
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
internal static int AppMain(Parameters! config)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
String! rawDevice;
|
|
|
|
String! location;
|
|
|
|
|
|
|
|
DirectoryServiceContract.Imp ds = ((!)config.nsRef).Acquire();
|
|
|
|
if (ds == null) {
|
|
|
|
throw new Exception("Unable to acquire handle to the Directory Service root");
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
ds.RecvSuccess();
|
2008-11-17 18:29:00 -05:00
|
|
|
|
|
|
|
rawDevice = (!)config.device;
|
|
|
|
location = (!)config.location;
|
|
|
|
|
|
|
|
WriteLineWrapper(" Mounting " + rawDevice + " at " +
|
2008-03-05 09:52:00 -05:00
|
|
|
location);
|
2008-11-17 18:29:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
FileSystemControllerContract.Imp! controlClient;
|
|
|
|
FileSystemControllerContract.Exp! controlServer;
|
|
|
|
FileSystemControllerContract.NewChannel(out controlClient, out controlServer);
|
|
|
|
|
|
|
|
ErrorCode errorOut;
|
2008-03-05 09:52:00 -05:00
|
|
|
bool ok = SdsUtils.Bind(ControlLocation, ds, controlServer, out errorOut);
|
|
|
|
if (!ok) {
|
|
|
|
Console.WriteLine("Bind failed on " + ControlLocation);
|
|
|
|
Console.WriteLine("Is iso9660 complied and running?");
|
2008-11-17 18:29:00 -05:00
|
|
|
delete controlClient;
|
|
|
|
delete ds;
|
|
|
|
return 0;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
controlClient.RecvSuccess();
|
|
|
|
|
|
|
|
delete ds;
|
|
|
|
|
|
|
|
WriteLineWrapper("Sending mount request...");
|
|
|
|
controlClient.SendMount(Bitter.FromString2(rawDevice), Bitter.FromString2(location));
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
switch receive {
|
2008-11-17 18:29:00 -05:00
|
|
|
case controlClient.Ok():
|
2008-03-05 09:52:00 -05:00
|
|
|
Console.WriteLine("Mount succeeded.");
|
2008-11-17 18:29:00 -05:00
|
|
|
delete controlClient;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case controlClient.RequestFailed(error):
|
|
|
|
Console.WriteLine("Mount failed: " + SdsUtils.ErrorCodeToString(error));
|
|
|
|
delete controlClient;
|
|
|
|
return -1;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|