Esempio n. 1
0
        public int Write(String FileFullName, long Offset, int Count, Byte[] Buffer)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            int rCount = 0;

            if (_CurrentItem != FileFullName)
            {
                NFSAttributes Attributes = GetItemAttributes(FileFullName);
                _CurrentItemHandleObject = new NFSHandle(Attributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);
                _CurrentItem             = FileFullName;
            }

            if (Count < Buffer.Length)
            {
                Array.Resize <byte>(ref Buffer, Count);
            }

            WriteArguments dpArgWrite = new WriteArguments();

            dpArgWrite.File   = _CurrentItemHandleObject;
            dpArgWrite.Offset = (int)Offset;
            dpArgWrite.Data   = Buffer;

            FileStatus pAttrStat =
                _ProtocolV2.NFSPROC_WRITE(dpArgWrite);

            if (pAttrStat != null)
            {
                if (pAttrStat.Status != NFSStats.NFS_OK)
                {
                    ExceptionHelpers.ThrowException(pAttrStat.Status);
                }

                rCount = Count;
            }
            else
            {
                throw new NFSGeneralException("NFSPROC_WRITE: failure");
            }

            return(rCount);
        }
Esempio n. 2
0
        public void CreateDirectory(string DirectoryFullName, NFSPermission Mode)
        {
            if (_ProtocolV3 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            if (Mode == null)
            {
                Mode = new NFSPermission(7, 7, 7);
            }

            string ParentDirectory = System.IO.Path.GetDirectoryName(DirectoryFullName);
            string DirectoryName   = System.IO.Path.GetFileName(DirectoryFullName);

            NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory);

            MakeFolderArguments dpArgCreate = new MakeFolderArguments();

            dpArgCreate.Attributes = new MakeAttributes();
            dpArgCreate.Attributes.LastAccessedTime = new NFSTimeValue();
            dpArgCreate.Attributes.ModifiedTime     = new NFSTimeValue();
            dpArgCreate.Attributes.Mode             = Mode;
            dpArgCreate.Attributes.SetMode          = true;
            dpArgCreate.Attributes.UserID           = this._UserID;
            dpArgCreate.Attributes.SetUserID        = true;
            dpArgCreate.Attributes.GroupID          = this._GroupID;
            dpArgCreate.Attributes.SetGroupID       = true;
            dpArgCreate.Where           = new ItemOperationArguments();
            dpArgCreate.Where.Directory = new NFSHandle(ParentItemAttributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3);
            dpArgCreate.Where.Name      = new Name(DirectoryName);

            ResultObject <MakeFolderAccessOK, MakeFolderAccessFAIL> pDirOpRes =
                _ProtocolV3.NFSPROC3_MKDIR(dpArgCreate);

            if (pDirOpRes == null ||
                pDirOpRes.Status != NFSStats.NFS_OK)
            {
                if (pDirOpRes == null)
                {
                    throw new NFSGeneralException("NFSPROC3_MKDIR: failure");
                }

                ExceptionHelpers.ThrowException(pDirOpRes.Status);
            }
        }
Esempio n. 3
0
        public void CreateFile(string FileFullName, NFSPermission Mode)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            if (Mode == null)
            {
                Mode = new NFSPermission(7, 7, 7);
            }

            string ParentDirectory = System.IO.Path.GetDirectoryName(FileFullName);
            string FileName        = System.IO.Path.GetFileName(FileFullName);

            NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory);

            CreateArguments dpArgCreate = new CreateArguments();

            dpArgCreate.Attributes = new CreateAttributes();
            dpArgCreate.Attributes.LastAccessedTime = new NFSTimeValue();
            dpArgCreate.Attributes.ModifiedTime     = new NFSTimeValue();
            dpArgCreate.Attributes.Mode             = Mode;
            dpArgCreate.Attributes.UserID           = this._UserID;
            dpArgCreate.Attributes.GroupID          = this._GroupID;
            dpArgCreate.Attributes.Size             = 0;
            dpArgCreate.Where           = new ItemOperationArguments();
            dpArgCreate.Where.Directory = new NFSHandle(ParentItemAttributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);
            dpArgCreate.Where.Name      = new Name(FileName);

            ItemOperationStatus pDirOpRes =
                _ProtocolV2.NFSPROC_CREATE(dpArgCreate);

            if (pDirOpRes == null ||
                pDirOpRes.Status != NFSStats.NFS_OK)
            {
                if (pDirOpRes == null)
                {
                    throw new NFSGeneralException("NFSPROC_CREATE: failure");
                }

                ExceptionHelpers.ThrowException(pDirOpRes.Status);
            }
        }
Esempio n. 4
0
        public int Read(String FileFullName, long Offset, int Count, ref Byte[] Buffer)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            int rCount = 0;

            if (_CurrentItem != FileFullName)
            {
                NFSAttributes Attributes = GetItemAttributes(FileFullName);
                _CurrentItemHandleObject = new NFSHandle(Attributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);
                _CurrentItem             = FileFullName;
            }

            ReadArguments dpArgRead = new ReadArguments();

            dpArgRead.File   = _CurrentItemHandleObject;
            dpArgRead.Offset = (int)Offset;
            dpArgRead.Count  = Count;

            ReadStatus pReadRes =
                _ProtocolV2.NFSPROC_READ(dpArgRead);

            if (pReadRes != null)
            {
                if (pReadRes.Status != NFSStats.NFS_OK)
                {
                    ExceptionHelpers.ThrowException(pReadRes.Status);
                }

                rCount = pReadRes.OK.Data.Length;

                Array.Copy(pReadRes.OK.Data, Buffer, rCount);
            }
            else
            {
                throw new NFSGeneralException("NFSPROC_READ: failure");
            }

            return(rCount);
        }
Esempio n. 5
0
        public bool IsDirectory(string DirectoryFullName)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            NFSAttributes Attributes = GetItemAttributes(DirectoryFullName);

            return(Attributes != null && Attributes.NFSType == NFSItemTypes.NFDIR);
        }
Esempio n. 6
0
        public void CreateDirectory(string DirectoryFullName, NFSPermission Mode)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            int user  = 7;
            int group = 7;
            int other = 7;

            if (Mode != null)
            {
                user  = Mode.UserAccess;
                group = Mode.GroupAccess;
                other = Mode.OtherAccess;
            }

            string        ParentDirectory      = System.IO.Path.GetDirectoryName(DirectoryFullName);
            string        fileName             = System.IO.Path.GetFileName(DirectoryFullName);
            NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory);

            //create item attributes now
            fattr4 attr = new fattr4();

            attr.attrmask        = OpenStub.openFattrBitmap();
            attr.attr_vals       = new attrlist4();
            attr.attr_vals.value = OpenStub.openAttrs(user, group, other, 4096);

            List <nfs_argop4> ops = new List <nfs_argop4>();

            ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                 _sequenceID.value.value, 12, 0));
            ops.Add(PutfhStub.generateRequest(new nfs_fh4(ParentItemAttributes.Handle)));
            ops.Add(CreateStub.generateRequest(fileName, attr));

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                //create directory ok
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Esempio n. 7
0
        public List <String> GetItemList(String DirectoryFullName)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            /*if (DirectoryFullName == ".")
             * {
             *  //root
             *  _cwd = _rootFH;
             *  _cwhTree.Add(_cwd);
             * }
             * else if (_currentFolder == DirectoryFullName)
             * {
             *  //do nothing just recheck folder
             * }
             * else if (DirectoryFullName.IndexOf(_currentFolder) != -1)
             * {
             *  //one level up
             *
             *  NFSAttributes itemAttributes = GetItemAttributes(DirectoryFullName);
             *  _cwd = itemAttributes.fh;
             *  _cwhTree.Add(_cwd);
             *  treePosition++;
             * }
             * else
             * {
             *  //level down
             *  _cwhTree.RemoveAt(treePosition);
             *  treePosition--;
             *  _cwd =_cwhTree[treePosition];
             * }*/

            //_currentFolder = DirectoryFullName;
            if (String.IsNullOrEmpty(DirectoryFullName) || DirectoryFullName == ".")
            {
                return(GetItemListByFH(_rootFH));
            }

            //simpler way than tree
            NFSAttributes itemAttributes = GetItemAttributes(DirectoryFullName);

            //true dat
            return(GetItemListByFH(new nfs_fh4(itemAttributes.Handle)));
        }
Esempio n. 8
0
        /// <summary>
        /// Copy a file from a remote directory to a stream
        /// </summary>
        /// <param name="SourceFileFullName">The remote file name</param>
        /// <param name="OutputStream"></param>
        public void Read(String SourceFileFullName, ref System.IO.Stream OutputStream)
        {
            if (OutputStream != null)
            {
                SourceFileFullName = CorrectPath(SourceFileFullName);

                if (!FileExists(SourceFileFullName))
                {
                    throw new System.IO.FileNotFoundException();
                }
                NFSAttributes nfsAttributes = GetItemAttributes(SourceFileFullName, true);
                long          TotalRead = nfsAttributes.Size, ReadOffset = 0;

                Byte[] ChunkBuffer = (Byte[])Array.CreateInstance(typeof(Byte), this._blockSize);
                int    ReadCount, ReadLength = this._blockSize;

                do
                {
                    if (TotalRead < ReadLength)
                    {
                        ReadLength = (int)TotalRead;
                    }

                    ReadCount = this._nfsInterface.Read(SourceFileFullName, ReadOffset, ReadLength, ref ChunkBuffer);

                    if (this.DataEvent != null)
                    {
                        this.DataEvent(this, new NFSEventArgs(ReadCount));
                    }

                    OutputStream.Write(ChunkBuffer, 0, ReadCount);

                    TotalRead -= ReadCount; ReadOffset += ReadCount;
                }while (ReadCount != 0);

                OutputStream.Flush();

                CompleteIO();
            }
            else
            {
                throw new NullReferenceException("OutputStream parameter must not be null!");
            }
        }
Esempio n. 9
0
        public void SetFileSize(string FileFullName, long Size)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            NFSAttributes Attributes = GetItemAttributes(FileFullName);

            FileArguments dpArgSAttr = new FileArguments();

            dpArgSAttr.Attributes = new CreateAttributes();
            dpArgSAttr.Attributes.LastAccessedTime             = new NFSTimeValue();
            dpArgSAttr.Attributes.LastAccessedTime.Seconds     = -1;
            dpArgSAttr.Attributes.LastAccessedTime.UnixSeconds = -1;
            dpArgSAttr.Attributes.ModifiedTime             = new NFSTimeValue();
            dpArgSAttr.Attributes.ModifiedTime.Seconds     = -1;
            dpArgSAttr.Attributes.ModifiedTime.UnixSeconds = -1;
            dpArgSAttr.Attributes.Mode    = new NFSPermission(0xff, 0xff, 0xff);
            dpArgSAttr.Attributes.UserID  = -1;
            dpArgSAttr.Attributes.GroupID = -1;
            dpArgSAttr.Attributes.Size    = (int)Size;
            dpArgSAttr.File = new NFSHandle(Attributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);

            FileStatus pAttrStat =
                _ProtocolV2.NFSPROC_SETATTR(dpArgSAttr);

            if (pAttrStat == null || pAttrStat.Status != NFSStats.NFS_OK)
            {
                if (pAttrStat == null)
                {
                    throw new NFSGeneralException("NFSPROC_SETATTR: failure");
                }

                ExceptionHelpers.ThrowException(pAttrStat.Status);
            }
        }
Esempio n. 10
0
        public void SetFileSize(string FileFullName, long Size)
        {
            if (_ProtocolV3 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            NFSAttributes Attributes = GetItemAttributes(FileFullName);

            SetAttributeArguments dpArgSAttr = new SetAttributeArguments();

            dpArgSAttr.Handle     = new NFSHandle(Attributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3);
            dpArgSAttr.Attributes = new MakeAttributes();
            dpArgSAttr.Attributes.LastAccessedTime = new NFSTimeValue();
            dpArgSAttr.Attributes.ModifiedTime     = new NFSTimeValue();
            dpArgSAttr.Attributes.Mode             = Attributes.Mode;
            dpArgSAttr.Attributes.UserID           = -1;
            dpArgSAttr.Attributes.GroupID          = -1;
            dpArgSAttr.Attributes.Size             = Size;
            dpArgSAttr.GuardCreateTime             = new NFSTimeValue();
            dpArgSAttr.GuardCheck = false;

            ResultObject <SetAttributeAccessOK, SetAttributeAccessFAIL> pAttrStat =
                _ProtocolV3.NFSPROC3_SETATTR(dpArgSAttr);

            if (pAttrStat == null || pAttrStat.Status != NFSStats.NFS_OK)
            {
                if (pAttrStat == null)
                {
                    throw new NFSGeneralException("NFSPROC3_SETATTR: failure");
                }

                ExceptionHelpers.ThrowException(pAttrStat.Status);
            }
        }
Esempio n. 11
0
        public void CreateFile(string FileFullName, NFSPermission Mode)
        {
            if (_CurrentItem != FileFullName)
            {
                _CurrentItem = FileFullName;


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

                string        ParentDirectory  = System.IO.Path.GetDirectoryName(FileFullName);
                NFSAttributes ParentAttributes = GetItemAttributes(ParentDirectory);



                //make open here
                List <nfs_argop4> ops = new List <nfs_argop4>();
                ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                     _sequenceID.value.value, 12, 0));
                //dir  herez
                ops.Add(PutfhStub.generateRequest(new nfs_fh4(ParentAttributes.Handle)));
                //let's try with sequence 0
                ops.Add(OpenStub.normalCREATE(PathTree[PathTree.Length - 1], _sequenceID.value.value, _clientIdByServer, NFSv4Protocol.OPEN4_SHARE_ACCESS_WRITE));
                ops.Add(GetfhStub.generateRequest());


                COMPOUND4res compound4res = sendCompound(ops, "");
                if (compound4res.status == nfsstat4.NFS4_OK)
                {
                    //open ok
                    currentState = compound4res.resarray[2].opopen.resok4.stateid;

                    _cwf = compound4res.resarray[3].opgetfh.resok4.object1;
                }
                else
                {
                    throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
                }
            }
        }
Esempio n. 12
0
        public void Move(string OldDirectoryFullName, string OldFileName, string NewDirectoryFullName, string NewFileName)
        {
            if (_ProtocolV3 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

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

            NFSAttributes OldDirectory = GetItemAttributes(OldDirectoryFullName);
            NFSAttributes NewDirectory = GetItemAttributes(NewDirectoryFullName);

            RenameArguments dpArgRename = new RenameArguments();

            dpArgRename.From           = new ItemOperationArguments();
            dpArgRename.From.Directory = new NFSHandle(OldDirectory.Handle, V3.RPC.NFSv3Protocol.NFS_V3);
            dpArgRename.From.Name      = new Name(OldFileName);
            dpArgRename.To             = new ItemOperationArguments();
            dpArgRename.To.Directory   = new NFSHandle(NewDirectory.Handle, V3.RPC.NFSv3Protocol.NFS_V3);
            dpArgRename.To.Name        = new Name(NewFileName);

            ResultObject <RenameAccessOK, RenameAccessFAIL> pRenameRes =
                _ProtocolV3.NFSPROC3_RENAME(dpArgRename);

            if (pRenameRes == null || pRenameRes.Status != NFSStats.NFS_OK)
            {
                if (pRenameRes == null)
                {
                    throw new NFSGeneralException("NFSPROC3_WRITE: failure");
                }

                ExceptionHelpers.ThrowException(pRenameRes.Status);
            }
        }
Esempio n. 13
0
        public NFSAttributes GetItemAttributes(string ItemFullName, bool ThrowExceptionIfNotFound = true)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            ItemFullName = ItemFullName.Replace(".\\.\\", ".\\");

            if (useFHCache)
            {
                if (cached_attrs.ContainsKey(ItemFullName))
                {
                    return((NFSAttributes)cached_attrs[ItemFullName]);
                }
            }

            //we will return it in the old way !! ;)
            NFSAttributes attributes = null;

            if (String.IsNullOrEmpty(ItemFullName))
            {
                //should not happen
                return(attributes);
            }


            if (ItemFullName == ".\\.")
            {
                return(new NFSAttributes(0, 0, 0, NFSItemTypes.NFDIR, new NFSPermission(7, 7, 7), 4096, _rootFH.value));
            }



            nfs_fh4 currentItem = _rootFH;
            int     initial     = 1;

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

            if (useFHCache)
            {
                string parent = System.IO.Path.GetDirectoryName(ItemFullName);
                //get cached parent dir to avoid too much directory
                if (parent != ItemFullName)
                {
                    if (cached_attrs.ContainsKey(parent))
                    {
                        currentItem.value = ((NFSAttributes)cached_attrs[parent]).Handle;
                        initial           = PathTree.Length - 1;
                    }
                }
            }


            for (int pC = initial; pC < PathTree.Length; pC++)
            {
                List <int> attrs = new List <int>(1);
                attrs.Add(NFSv4Protocol.FATTR4_TIME_CREATE);
                attrs.Add(NFSv4Protocol.FATTR4_TIME_ACCESS);
                attrs.Add(NFSv4Protocol.FATTR4_TIME_MODIFY);
                attrs.Add(NFSv4Protocol.FATTR4_TYPE);
                attrs.Add(NFSv4Protocol.FATTR4_MODE);
                attrs.Add(NFSv4Protocol.FATTR4_SIZE);

                List <nfs_argop4> ops = new List <nfs_argop4>();

                ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                     _sequenceID.value.value, 12, 0));

                ops.Add(PutfhStub.generateRequest(currentItem));
                ops.Add(LookupStub.generateRequest(PathTree[pC]));

                //ops.Add(PutfhStub.generateRequest(_cwd));
                //ops.Add(LookupStub.generateRequest(PathTree[PathTree.Length-1]));

                ops.Add(GetfhStub.generateRequest());
                ops.Add(GetattrStub.generateRequest(attrs));

                COMPOUND4res compound4res = sendCompound(ops, "");

                if (compound4res.status == nfsstat4.NFS4_OK)
                {
                    currentItem = compound4res.resarray[3].opgetfh.resok4.object1;

                    //nfs_fh4 currentItem = compound4res.resarray[3].opgetfh.resok4.object1;

                    //results
                    Dictionary <int, Object> attrrs_results = GetattrStub.decodeType(compound4res.resarray[4].opgetattr.resok4.obj_attributes);

                    //times
                    nfstime4 time_acc = (nfstime4)attrrs_results[NFSv4Protocol.FATTR4_TIME_ACCESS];

                    int time_acc_int = unchecked ((int)time_acc.seconds.value);

                    nfstime4 time_modify = (nfstime4)attrrs_results[NFSv4Protocol.FATTR4_TIME_MODIFY];

                    int time_modif = unchecked ((int)time_modify.seconds.value);


                    int time_creat = 0;
                    //linux should now store create time if it is let's check it else use modify date
                    if (attrrs_results.ContainsKey(NFSv4Protocol.FATTR4_TIME_CREATE))
                    {
                        nfstime4 time_create = (nfstime4)attrrs_results[NFSv4Protocol.FATTR4_TIME_CREATE];

                        time_creat = unchecked ((int)time_create.seconds.value);
                    }
                    else
                    {
                        time_creat = time_modif;
                    }



                    //3 = type
                    NFSItemTypes nfstype = NFSItemTypes.NFREG;

                    fattr4_type type = (fattr4_type)attrrs_results[NFSv4Protocol.FATTR4_TYPE];

                    if (type.value == 2)
                    {
                        nfstype = NFSItemTypes.NFDIR;
                    }

                    //4 = mode is int also
                    mode4 mode = (mode4)attrrs_results[NFSv4Protocol.FATTR4_MODE];

                    byte other = (byte)(mode.value.value % 8);

                    byte grup = (byte)((mode.value.value >> 3) % 8);

                    byte user = (byte)((mode.value.value >> 6) % 8);

                    NFSPermission per = new NFSPermission(user, grup, other);


                    uint64_t size = (uint64_t)attrrs_results[NFSv4Protocol.FATTR4_SIZE];
                    //here we do attributes compatible with old nfs versions
                    attributes = new NFSAttributes(time_creat, time_acc_int, time_modif, nfstype, per, size.value, currentItem.value);
                }
                else if (compound4res.status == nfsstat4.NFS4ERR_NOENT)
                {
                    return(null);
                }

                else
                {
                    throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
                }
            }

            // if(attributes.NFSType == NFSItemTypes.NFDIR)
            if (useFHCache)
            {
                cached_attrs.Add(ItemFullName, attributes);
            }

            return(attributes);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public int Read(String FileFullName, long Offset, int Count, ref Byte[] Buffer)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            int rCount = 0;

            if (Count == 0)
            {
                return(0);
            }


            if (_CurrentItem != FileFullName)
            {
                NFSAttributes Attributes = GetItemAttributes(FileFullName);
                _cwf         = new nfs_fh4(Attributes.Handle);
                _CurrentItem = FileFullName;

                string        ParentDirectory  = System.IO.Path.GetDirectoryName(FileFullName);
                NFSAttributes ParentAttributes = GetItemAttributes(ParentDirectory);

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


                //make open here
                List <nfs_argop4> ops = new List <nfs_argop4>();
                ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                     _sequenceID.value.value, 12, 0));
                //dir  herez
                //ops.Add(PutfhStub.generateRequest(_cwd));
                ops.Add(PutfhStub.generateRequest(new nfs_fh4(ParentAttributes.Handle)));
                //let's try with sequence 0
                ops.Add(OpenStub.normalREAD(PathTree[PathTree.Length - 1], 0, _clientIdByServer, NFSv4Protocol.OPEN4_SHARE_ACCESS_READ));


                COMPOUND4res compound4res = sendCompound(ops, "");
                if (compound4res.status == nfsstat4.NFS4_OK)
                {
                    //open ok
                    currentState = compound4res.resarray[2].opopen.resok4.stateid;
                }
                else
                {
                    throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
                }



                //check the acess also
                if (get_fh_acess(_cwf) % 2 != 1)
                {
                    //we don't have read acess give error
                    throw new NFSConnectionException("Sorry no file READ acess !!!");
                }
            }

            List <nfs_argop4> ops2 = new List <nfs_argop4>();

            ops2.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                  _sequenceID.value.value, 12, 0));
            ops2.Add(PutfhStub.generateRequest(_cwf));
            ops2.Add(ReadStub.generateRequest(Count, Offset, currentState));



            COMPOUND4res compound4res2 = sendCompound(ops2, "");

            if (compound4res2.status == nfsstat4.NFS4_OK)
            {
                //read of offset complete
                rCount = compound4res2.resarray[2].opread.resok4.data.Length;

                ///copy the data to the output
                Array.Copy(compound4res2.resarray[2].opread.resok4.data, Buffer, rCount);
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res2.status));
            }

            return(rCount);
        }
Esempio n. 17
0
        public int Write(String FileFullName, long Offset, int Count, Byte[] Buffer)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }


            int rCount = 0;

            //nfs_fh4 current = _cwd;



            if (_CurrentItem != FileFullName)
            {
                _CurrentItem = FileFullName;


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

                string        ParentDirectory  = System.IO.Path.GetDirectoryName(FileFullName);
                NFSAttributes ParentAttributes = GetItemAttributes(ParentDirectory);


                //make open here
                List <nfs_argop4> ops = new List <nfs_argop4>();
                ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                     _sequenceID.value.value, 12, 0));
                //dir  herez
                ops.Add(PutfhStub.generateRequest(new nfs_fh4(ParentAttributes.Handle)));
                //let's try with sequence 0
                ops.Add(OpenStub.normalOPENonly(PathTree[PathTree.Length - 1], _sequenceID.value.value, _clientIdByServer, NFSv4Protocol.OPEN4_SHARE_ACCESS_WRITE));
                ops.Add(GetfhStub.generateRequest());


                COMPOUND4res compound4res = sendCompound(ops, "");
                if (compound4res.status == nfsstat4.NFS4_OK)
                {
                    //open ok
                    currentState = compound4res.resarray[2].opopen.resok4.stateid;

                    _cwf = compound4res.resarray[3].opgetfh.resok4.object1;
                }
                else
                {
                    throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
                }
            }

            List <nfs_argop4> ops2 = new List <nfs_argop4>();

            ops2.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                  _sequenceID.value.value, 12, 0));
            ops2.Add(PutfhStub.generateRequest(_cwf));

            //make better buffer
            Byte[] Buffer2 = new Byte[Count];
            Array.Copy(Buffer, Buffer2, Count);
            ops2.Add(WriteStub.generateRequest(Offset, Buffer2, currentState));



            COMPOUND4res compound4res2 = sendCompound(ops2, "");

            if (compound4res2.status == nfsstat4.NFS4_OK)
            {
                //write of offset complete
                rCount = compound4res2.resarray[2].opwrite.resok4.count.value.value;
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res2.status));
            }

            return(rCount);
        }
Esempio n. 18
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);
        }