singrdk/base/Applications/iso9660/cdunmount/cdunmount.sg

109 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

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 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="Unmount 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;
[BoolParameter( "s", Default=false, HelpMessage="Silent.")]
internal bool silent;
2008-11-17 18:29:00 -05:00
[StringParameter("path", Mandatory=true, Position=0, HelpMessage="The path to unmount.")]
public string mountPath;
2008-03-05 09:52:00 -05:00
reflective internal Parameters();
internal int AppMain() {
return CdUnmount.AppMain(this);
}
}
2008-11-17 18:29:00 -05:00
2008-03-05 09:52:00 -05:00
public class CdUnmount
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
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();
silent = config.silent;
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) {
2008-11-17 18:29:00 -05:00
delete controlClient;
2008-03-05 09:52:00 -05:00
delete ds;
2008-11-17 18:29:00 -05:00
WriteLineWrapper("Error binding to " + ControlLocation + " reason "
2008-03-05 09:52:00 -05:00
+ SdsUtils.ErrorCodeToString(errorOut) );
2008-11-17 18:29:00 -05:00
return 0;
2008-03-05 09:52:00 -05:00
}
2008-11-17 18:29:00 -05:00
2008-03-05 09:52:00 -05:00
controlClient.RecvSuccess();
2008-11-17 18:29:00 -05:00
delete ds;
WriteLineWrapper("Sending unmount request...");
controlClient.SendUnmount(Bitter.FromString2((!)config.mountPath));
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("Unmount succeeded.");
2008-11-17 18:29:00 -05:00
delete controlClient;
return 0;
case controlClient.RequestFailed(error):
Console.WriteLine("Unmount 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
}