/////////////////////////////////////////////////////////////////////////////// // // Microsoft Research Singularity // // Copyright (c) Microsoft Corporation. All rights reserved. // // File: Attr.sg // // Note: // using FileSystem.Utils; using System; using System.Text; using System.Threading; using Microsoft.Singularity; using Microsoft.Singularity.Directory; using Microsoft.Singularity.Channels; using Microsoft.Singularity.FileSystem; using Microsoft.Singularity.V1.Services; using Microsoft.Contracts; using Microsoft.SingSharp.Reflection; using Microsoft.Singularity.Applications; using Microsoft.Singularity.Io; using Microsoft.Singularity.Configuration; [assembly: Transform(typeof(ApplicationResourceTransform))] namespace Microsoft.Singularity.Applications { [ConsoleCategory(HelpMessage="Show attributes associated with a file", DefaultAction=true)] internal class Parameters { [InputEndpoint("data")] public readonly TRef Stdin; [OutputEndpoint("data")] public readonly TRef Stdout; [Endpoint] public readonly TRef nsRef; [StringParameter( "filename", Mandatory=true, Position=0, HelpMessage="Name of file.")] internal string fileName; reflective internal Parameters(); internal int AppMain() { return FsAttributes.AppMain(this); } } public class FsAttributes { internal static int AppMain(Parameters! config) { long size; NodeType nodeType; DirectoryServiceContract.Imp rootNS = (config.nsRef).Acquire(); if (rootNS == null) { throw new Exception("Unable to acquire handle to the Directory Service root"); } rootNS.RecvSuccess(); ErrorCode error; bool ok = FileUtils.GetAttributes(config.fileName, rootNS, out size, out nodeType, out error); delete rootNS; if (ok) { Console.WriteLine("GetAttributes for " + config.fileName); Console.WriteLine(" Size: " + size); Console.WriteLine(" NodeType: {0}", SdsUtils.NodeTypeToString(nodeType) ); return 0; } else { Console.WriteLine(" Attr for ({0}) failed. reason:{1}", config.fileName, SdsUtils.ErrorCodeToString(error) ); } return -1; } private static void Usage() { Console.WriteLine("type displays output of file on console."); } } // class Test }