//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);
        }
        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);
        }
        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;
            }
        }
        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);
        }