Exemple #1
0
        public List <String> GetItemList(String DirectoryFullName)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV2 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            List <string> ItemsList = new List <string>();

            NFSAttributes itemAttributes =
                GetItemAttributes(DirectoryFullName);

            if (itemAttributes != null)
            {
                ItemArguments dpRdArgs = new ItemArguments();

                dpRdArgs.Cookie       = new NFSCookie(0);
                dpRdArgs.Count        = 4096;
                dpRdArgs.HandleObject = new NFSHandle(itemAttributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);

                ItemStatus pReadDirRes;

                do
                {
                    pReadDirRes = _ProtocolV2.NFSPROC_READDIR(dpRdArgs);

                    if (pReadDirRes != null &&
                        pReadDirRes.Status == NFSStats.NFS_OK)
                    {
                        Entry pEntry =
                            pReadDirRes.OK.Entries;

                        while (pEntry != null)
                        {
                            ItemsList.Add(pEntry.Name.Value);
                            dpRdArgs.Cookie = pEntry.Cookie;
                            pEntry          = pEntry.NextEntry;
                        }
                    }
                    else
                    {
                        if (pReadDirRes == null)
                        {
                            throw new NFSGeneralException("NFSPROC_READDIR: failure");
                        }

                        ExceptionHelpers.ThrowException(pReadDirRes.Status);
                    }
                } while (pReadDirRes != null && !pReadDirRes.OK.EOF);
            }
            else
            {
                ExceptionHelpers.ThrowException(NFSStats.NFSERR_NOENT);
            }

            return(ItemsList);
        }
Exemple #2
0
        public NFSAttributes GetItemAttributes(String ItemFullName, bool ThrowExceptionIfNotFound = true)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV2 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            NFSAttributes attributes = null;

            if (String.IsNullOrEmpty(ItemFullName))
            {
                ItemFullName = ".";
            }

            NFSHandle currentItem = _RootDirectoryHandleObject;

            String[] PathTree = ItemFullName.Split(@"\".ToCharArray());

            for (int pC = 0; pC < PathTree.Length; pC++)
            {
                ItemOperationArguments dpDrArgs = new ItemOperationArguments();
                dpDrArgs.Directory = currentItem;
                dpDrArgs.Name      = new Name(PathTree[pC]);

                ItemOperationStatus pDirOpRes =
                    _ProtocolV2.NFSPROC_LOOKUP(dpDrArgs);

                if (pDirOpRes != null &&
                    pDirOpRes.Status == NFSStats.NFS_OK)
                {
                    currentItem = pDirOpRes.OK.HandleObject;

                    if (PathTree.Length - 1 == pC)
                    {
                        attributes = new NFSAttributes(
                            pDirOpRes.OK.Attributes.CreateTime.Seconds,
                            pDirOpRes.OK.Attributes.LastAccessedTime.Seconds,
                            pDirOpRes.OK.Attributes.ModifiedTime.Seconds,
                            pDirOpRes.OK.Attributes.Type,
                            pDirOpRes.OK.Attributes.Mode,
                            pDirOpRes.OK.Attributes.Size,
                            pDirOpRes.OK.HandleObject.Value);
                    }
                }
                else
                {
                    if (pDirOpRes == null || pDirOpRes.Status == NFSStats.NFSERR_NOENT)
                    {
                        attributes = null;
                        break;
                    }

                    if (ThrowExceptionIfNotFound)
                    {
                        ExceptionHelpers.ThrowException(pDirOpRes.Status);
                    }
                }
            }

            return(attributes);
        }
Exemple #3
0
        public List <String> GetItemList(String DirectoryFullName)
        {
            if (_ProtocolV3 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV3 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            List <string> ItemsList = new List <string>();

            NFSAttributes itemAttributes =
                GetItemAttributes(DirectoryFullName);

            if (itemAttributes != null)
            {
                ReadFolderArguments dpRdArgs = new ReadFolderArguments();

                dpRdArgs.Count        = 4096;
                dpRdArgs.Cookie       = new NFSCookie(0);
                dpRdArgs.CookieData   = new byte[NFSv3Protocol.NFS3_COOKIEVERFSIZE];
                dpRdArgs.HandleObject = new NFSHandle(itemAttributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3);

                ResultObject <ReadFolderAccessResultOK, ReadFolderAccessResultFAIL> pReadDirRes;

                do
                {
                    pReadDirRes = _ProtocolV3.NFSPROC3_READDIR(dpRdArgs);

                    if (pReadDirRes != null &&
                        pReadDirRes.Status == NFSStats.NFS_OK)
                    {
                        Entry pEntry =
                            pReadDirRes.OK.Reply.Entries;

                        Array.Copy(pReadDirRes.OK.CookieData, dpRdArgs.CookieData, NFSv3Protocol.NFS3_COOKIEVERFSIZE);
                        while (pEntry != null)
                        {
                            ItemsList.Add(pEntry.Name.Value);
                            dpRdArgs.Cookie = pEntry.Cookie;
                            pEntry          = pEntry.NextEntry;
                        }
                    }
                    else
                    {
                        if (pReadDirRes == null)
                        {
                            throw new NFSGeneralException("NFSPROC3_READDIR: failure");
                        }

                        if (pReadDirRes.Status != NFSStats.NFS_OK)
                        {
                            ExceptionHelpers.ThrowException(pReadDirRes.Status);
                        }
                    }
                } while (pReadDirRes != null && !pReadDirRes.OK.Reply.EOF);
            }
            else
            {
                ExceptionHelpers.ThrowException(NFSStats.NFSERR_NOENT);
            }

            return(ItemsList);
        }