Ejemplo n.º 1
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));
                }
            }
        }
Ejemplo n.º 2
0
        public int get_fh_acess(nfs_fh4 file_handle)
        {
            uint32_t access = new uint32_t(0);

            //all acsses possible
            access.value = access.value +
                           NFSv4Protocol.ACCESS4_READ +
                           NFSv4Protocol.ACCESS4_LOOKUP +
                           NFSv4Protocol.ACCESS4_MODIFY +
                           NFSv4Protocol.ACCESS4_EXTEND +
                           NFSv4Protocol.ACCESS4_DELETE; //+
            //NFSv4Protocol.ACCESS4_EXECUTE;

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


            ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                 _sequenceID.value.value, 12, 0));
            ops.Add(PutfhStub.generateRequest(file_handle));
            ops.Add(AcessStub.generateRequest(access));


            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                return(compound4res.resarray[2].opaccess.resok4.access.value);
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Ejemplo n.º 3
0
 public void xdrDecode(XdrDecodingStream xdr)
 {
     cna_fh = new nfs_fh4(xdr);
     { int _size = xdr.xdrDecodeInt(); cna_changes = new notify4[_size]; for (int _idx = 0; _idx < _size; ++_idx)
       {
           cna_changes[_idx] = new notify4(xdr);
       }
     }
 }
Ejemplo n.º 4
0
 public void CompleteIO()
 {
     if (_cwf != null || _CurrentItem != string.Empty)
     {
         closeFile(_cwf, currentState);
         _CurrentItem = string.Empty;
         _cwf         = null;
     }
 }
Ejemplo n.º 5
0
        public List <String> GetItemListByFH(nfs_fh4 dir_fh)
        {
            //should return result
            int acess = get_fh_acess(dir_fh);


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

            //has read acess
            if (acess % 2 == 1)
            {
                bool done   = false;
                long cookie = 0;

                verifier4 verifier = new verifier4(0);

                do
                {
                    List <nfs_argop4> ops = new List <nfs_argop4>();
                    ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                         _sequenceID.value.value, 12, 0));
                    ops.Add(PutfhStub.generateRequest(dir_fh));
                    ops.Add(ReadDirStub.generateRequest(cookie, verifier));

                    COMPOUND4res compound4res = sendCompound(ops, "");

                    if (compound4res.status == nfsstat4.NFS4_OK)
                    {
                        verifier = compound4res.resarray[2].opreaddir.resok4.cookieverf;
                        done     = compound4res.resarray[2].opreaddir.resok4.reply.eof;

                        entry4 dirEntry = compound4res.resarray[2].opreaddir.resok4.reply.entries;
                        while (dirEntry != null)
                        {
                            cookie = dirEntry.cookie.value.value;
                            string name = System.Text.Encoding.UTF8.GetString(dirEntry.name.value.value.value);
                            ItemsList.Add(name);
                            dirEntry = dirEntry.nextentry;
                        }
                    }
                    else
                    {
                        throw new NFSGeneralException(nfsstat4.getErrorString(compound4res.status));
                    }
                } while (!done);
                //now do the lookups (maintained by the nfsclient)
            }
            else
            {
                throw new NFSGeneralException(nfsstat4.getErrorString(nfsstat4.NFS4ERR_ACCESS));
            }


            return(ItemsList);
        }
Ejemplo n.º 6
0
        public static nfs_argop4 generateRequest(nfs_fh4 fh)
        {
            nfs_argop4 op = new nfs_argop4();

            op.opputfh         = new PUTFH4args();
            op.opputfh.object1 = fh;

            op.argop = nfs_opnum4.OP_PUTFH;

            return(op);
        }
Ejemplo n.º 7
0
    public static nfs_argop4 generateRequest( nfs_fh4 fh) {


        nfs_argop4 op = new nfs_argop4();
        op.opputfh = new PUTFH4args();
        op.opputfh.object1 = fh;

        op.argop = nfs_opnum4.OP_PUTFH;

        return op;

    }
Ejemplo n.º 8
0
        public void Connect(IPAddress Address, int UserID, int GroupID, int ClientTimeout, System.Text.Encoding characterEncoding, bool useSecurePort, bool useCache)
        {
            if (ClientTimeout == 0)
            {
                ClientTimeout = 60000;
            }

            if (characterEncoding == null)
            {
                characterEncoding = System.Text.Encoding.ASCII;
            }

            _CurrentItem = String.Empty;

            useFHCache = useCache;


            if (useFHCache)
            {
                cached_attrs = new Hashtable();//new Dictionary<string, NFSAttributes>();
            }
            _rootFH = null;

            //_cwd = null;

            _cwf = null;

            //_cwhTree = new List<nfs_fh4>();
            //treePosition = 0;

            _GroupID = GroupID;
            _UserID  = UserID;

            _ProtocolV4 = new NFSv4ProtocolClient(Address, OncRpcProtocols.ONCRPC_TCP, useSecurePort);

            OncRpcClientAuthUnix authUnix = new OncRpcClientAuthUnix(Address.ToString(), UserID, GroupID);

            _ProtocolV4.GetClient().setAuth(authUnix);
            _ProtocolV4.GetClient().setTimeout(ClientTimeout);
            _ProtocolV4.GetClient().setCharacterEncoding(characterEncoding.WebName);

            //send null dummy procedure to see if server is responding
            sendNullPRocedure();
        }
Ejemplo n.º 9
0
        private void closeFile(nfs_fh4 fh, stateid4 stateid)
        {
            List <nfs_argop4> ops = new List <nfs_argop4>();

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

            ops.Add(PutfhStub.generateRequest(fh));
            ops.Add(CloseStub.generateRequest(stateid));

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                //close file ok
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Ejemplo n.º 10
0
        private void getRootFh()
        {
            List <int> attrs = new List <int>(1);

            attrs.Add(NFSv4Protocol.FATTR4_LEASE_TIME);
            List <nfs_argop4> ops = new List <nfs_argop4>();

            ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                 _sequenceID.value.value, 0, 0));
            ops.Add(PutrootfhStub.generateRequest());
            ops.Add(GetfhStub.generateRequest());
            ops.Add(GetattrStub.generateRequest(attrs));

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                _rootFH = compound4res.resarray[2].opgetfh.resok4.object1;
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Ejemplo n.º 11
0
 public void xdrDecode(XdrDecodingStream xdr) {
     truncate = xdr.xdrDecodeBoolean();
     fh = new nfs_fh4(xdr);
 }
Ejemplo n.º 12
0
 public void xdrDecode(XdrDecodingStream xdr) {
     cna_fh = new nfs_fh4(xdr);
     { int _size = xdr.xdrDecodeInt(); cna_changes = new notify4[_size]; for ( int _idx = 0; _idx < _size; ++_idx ) { cna_changes[_idx] = new notify4(xdr); } }
 }
Ejemplo n.º 13
0
 public void xdrDecode(XdrDecodingStream xdr)
 {
     truncate = xdr.xdrDecodeBoolean();
     fh       = new nfs_fh4(xdr);
 }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }