예제 #1
0
        //Nfs3Procedure.Status TryGetShareObject(String sharePathAndName, out RootShareDirectory rootShareDirectory, out ShareObject share)



        Nfs3Procedure.Status TryGetRootSharedDirectory(String rootShareName, out RootShareDirectory rootShareDirectory)
        {
            if (rootShareName[0] == '/')
            {
                rootShareName = rootShareName.Substring(1);
            }
            if (rootShareName.Contains("/"))
            {
                rootShareDirectory = null;
                return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
            }

            for (int i = 0; i < rootShareDirectories.Length; i++)
            {
                rootShareDirectory = rootShareDirectories[i];
                if (rootShareName.Equals(rootShareDirectory.shareName))
                {
                    Nfs3Procedure.Status status = rootShareDirectory.shareObject.CheckStatus();
                    if (status != Nfs3Procedure.Status.Ok)
                    {
                        throw new InvalidOperationException(String.Format("The root share directory [{0}] has become invalid (status={1})", rootShareDirectory, status));
                    }
                    return(Nfs3Procedure.Status.Ok);
                }
            }

            rootShareDirectory = null;
            return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
        }
예제 #2
0
        public Nfs3Procedure.Status TryGetDirectory(String shareDirectoryName, out RootShareDirectory rootShareDirectory, out ShareObject shareDirectoryObject)
        {
            String subPath;
            String rootShareName = NfsPath.SplitShareNameAndSubPath(shareDirectoryName, out subPath);

            if (rootShareName == null)
            {
                rootShareDirectory   = null;
                shareDirectoryObject = null;
                return(Nfs3Procedure.Status.ErrorInvalidArgument);
            }

            Nfs3Procedure.Status status = TryGetRootSharedDirectory(rootShareName, out rootShareDirectory);
            if (status != Nfs3Procedure.Status.Ok)
            {
                shareDirectoryObject = null; return(status);
            }
            if (rootShareDirectory == null)
            {
                shareDirectoryObject = null; return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
            }

            if (subPath == null)
            {
                shareDirectoryObject = rootShareDirectory.shareObject;
            }
            else
            {
                String localPathAndName = PlatformPath.LocalCombine(rootShareDirectory.localShareDirectory, subPath);

                status = TryGetSharedObject(localPathAndName, subPath, out shareDirectoryObject);
                if (status != Nfs3Procedure.Status.Ok)
                {
                    return(status);
                }
                if (shareDirectoryObject == null)
                {
                    return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
                }

                shareDirectoryObject.RefreshFileAttributes(permissions);
            }
            return(Nfs3Procedure.Status.Ok);
        }
예제 #3
0
        public SharedFileSystem(IFileIDsAndHandlesDictionary filesDictionary, IPermissions permissions, RootShareDirectory[] rootShareDirectories)
        {
            this.filesDictionary = filesDictionary;
            this.permissions     = permissions;

            this.rootShareDirectories = rootShareDirectories;

            shareObjectsByHandle    = new Dictionary <Byte[], ShareObject>(filesDictionary);
            shareObjectsByLocalPath = new Dictionary <String, ShareObject>();
            for (int i = 0; i < rootShareDirectories.Length; i++)
            {
                RootShareDirectory rootShareDirectory = rootShareDirectories[i];
                ShareObject        shareObject        = CreateNewShareObject(FileType.Directory, rootShareDirectory.localShareDirectory, rootShareDirectory.shareName);
                if (shareObject == null)
                {
                    throw new DirectoryNotFoundException(String.Format(
                                                             "You are trying to share local directory '{0}', but it either does not exist or is not a directory", rootShareDirectory.localShareDirectory));
                }
                rootShareDirectory.shareObject = shareObject;
            }
        }
예제 #4
0
        public Nfs3Procedure.Status TryGetRootSharedDirectory(Byte[] handle, out RootShareDirectory rootShareDirectory)
        {
            ShareObject shareObject;

            Nfs3Procedure.Status status = TryGetSharedObject(handle, out shareObject);
            if (status != Nfs3Procedure.Status.Ok)
            {
                rootShareDirectory = null; return(status);
            }

            for (int i = 0; i < rootShareDirectories.Length; i++)
            {
                rootShareDirectory = rootShareDirectories[i];
                if (shareObject == rootShareDirectory.shareObject || shareObject.localPathAndName.StartsWith(rootShareDirectory.localShareDirectory))
                {
                    return(Nfs3Procedure.Status.Ok);
                }
            }
            rootShareDirectory = null;
            return(Nfs3Procedure.Status.ErrorNoSuchFileOrDirectory);
        }
예제 #5
0
        static void Main(String[] args)
        {
#if WindowsCE
            try
            {
#endif
            NfsServerLog.stopwatchTicksBase = Stopwatch.GetTimestamp();

            NfsServerProgramOptions options  = new NfsServerProgramOptions();
            List <String> nonOptionArguments = options.Parse(args);

            if (nonOptionArguments.Count < 2)
            {
                options.ErrorAndUsage("Expected at least 2 non-option arguments but got '{0}'", nonOptionArguments.Count);
                return;
            }
            if (nonOptionArguments.Count % 2 == 1)
            {
                options.ErrorAndUsage("Expected an even number of non-option arguments but got {0}", nonOptionArguments.Count);
            }

            //
            //



            RootShareDirectory[] rootShareDirectories = new RootShareDirectory[nonOptionArguments.Count / 2];
            for (int i = 0; i < rootShareDirectories.Length; i++)
            {
                String localSharePath  = nonOptionArguments[2 * i];
                String remoteShareName = nonOptionArguments[2 * i + 1];
                rootShareDirectories[i] = new RootShareDirectory(localSharePath, remoteShareName);
            }

            //
            // Options not exposed via command line yet
            //
            Int32 mountListenPort = 59733;
            Int32 backlog         = 4;

            UInt32 readSizeMax = 65536;
            UInt32 suggestedReadSizeMultiple = 4096;

            //
            // Listen IP Address
            //
            IPAddress listenIPAddress = options.listenIPAddress.ArgValue;

            //
            // Debug Server
            //
            IPEndPoint debugServerEndPoint = !options.debugListenPort.set ? null :
                                             new IPEndPoint(listenIPAddress, options.debugListenPort.ArgValue);

            //
            // Npc Server
            //
            IPEndPoint npcServerEndPoint = !options.npcListenPort.set ? null :
                                           new IPEndPoint(listenIPAddress, options.npcListenPort.ArgValue);

            //
            // Logging Options
            //
#if WindowsCE
            JediTimer.printJediTimerPrefix = options.jediTimer.set;
#endif
            if (options.performanceLog.set)
            {
                if (options.performanceLog.ArgValue.Equals("internal", StringComparison.CurrentCultureIgnoreCase))
                {
                    NfsServerLog.performanceLog = new InternalPerformanceLog();
                    if (!options.debugListenPort.set)
                    {
                        options.ErrorAndUsage("Invalid option combination: you cannot set '-i internal' unless you also set -d <port>");
                        return;
                    }
                }
                else
                {
                    try
                    {
                        FileStream fileStream = new FileStream(options.performanceLog.ArgValue, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
                        NfsServerLog.performanceLog = new WriterPerformanceLog(fileStream);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to create performance log file '{0}'", options.performanceLog.ArgValue);
                        throw e;
                    }
                }
            }

            TextWriter selectServerEventsLog = null;
            if (options.logLevel.ArgValue != LogLevel.None)
            {
                TextWriter logWriter;
                if (options.logFile.set)
                {
                    logWriter = new StreamWriter(new FileStream(options.logFile.ArgValue, FileMode.Create, FileAccess.Write, FileShare.Read));
                }
                else
                {
                    logWriter = Console.Out;
                }

                NfsServerLog.sharedFileSystemLogger = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;
                NfsServerLog.rpcCallLogger          = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;
                NfsServerLog.warningLogger          = (options.logLevel.ArgValue >= LogLevel.Warning) ? logWriter : null;
                NfsServerLog.npcEventsLogger        = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;

                RpcPerformanceLog.rpcMessageSerializationLogger = (options.logLevel.ArgValue >= LogLevel.Info) ? logWriter : null;

                selectServerEventsLog = (options.logLevel.ArgValue >= LogLevel.All) ? logWriter : null;
            }

            //
            // Permissions
            //
            ModeFlags defaultDirectoryPermissions =
                ModeFlags.OtherExecute | ModeFlags.OtherWrite | ModeFlags.OtherRead |
                ModeFlags.GroupExecute | ModeFlags.GroupWrite | ModeFlags.GroupRead |
                ModeFlags.OwnerExecute | ModeFlags.OwnerWrite | ModeFlags.OwnerRead;
            /*ModeFlags.SaveSwappedText | ModeFlags.SetUidOnExec | ModeFlags.SetGidOnExec;*/
            ModeFlags defaultFilePermissions =
                ModeFlags.OtherExecute | ModeFlags.OtherWrite | ModeFlags.OtherRead |
                ModeFlags.GroupExecute | ModeFlags.GroupWrite | ModeFlags.GroupRead |
                ModeFlags.OwnerExecute | ModeFlags.OwnerWrite | ModeFlags.OwnerRead;
            /*ModeFlags.SaveSwappedText | ModeFlags.SetUidOnExec | ModeFlags.SetGidOnExec;*/
            IPermissions permissions = new ConstantPermissions(defaultDirectoryPermissions, defaultFilePermissions);


            IFileIDsAndHandlesDictionary fileIDDictionary = new FreeStackFileIDDictionary(512, 512, 4096, 1024);

            SharedFileSystem sharedFileSystem = new SharedFileSystem(fileIDDictionary, permissions, rootShareDirectories);

            new RpcServicesManager().Run(
                selectServerEventsLog,
                debugServerEndPoint,
                npcServerEndPoint,
                listenIPAddress,
                backlog, sharedFileSystem,
                Ports.PortMap, mountListenPort, Ports.Nfs,
                readSizeMax, suggestedReadSizeMultiple);

#if WindowsCE
        }

        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
#endif
        }