Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
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));
                }
            }
        }
Exemplo n.º 3
0
        public void DeleteFile(string FileFullName)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }


            // it seems acess doesent work ok in the server
            //delete acess isn't showed but file can be deleted and should be deleted!

            /*NFSAttributes atrs = GetItemAttributes(FileFullName);
             *
             * int acess = get_fh_acess(atrs.fh);
             *
             * //delete support
             * if ((acess >> 4) % 2 == 1)
             * {*/


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

            NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory);


            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(RemoveStub.generateRequest(fileName));

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                //ok - deleted
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }


            /* }
             * else
             * {
             *   throw new NFSGeneralException("Acess Denied");
             * }*/


            //only if we support caching
            if (useFHCache)
            {
                cached_attrs.Remove(FileFullName);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        private void destroy_clientId()
        {
            if (_clientIdByServer != null)
            {
                List <nfs_argop4> ops = new List <nfs_argop4>();

                ops.Add(DestroyClientIdStub.standard(_clientIdByServer));

                COMPOUND4res compound4res = sendCompound(ops, "");
                _clientIdByServer = null;
            }
        }
Exemplo n.º 6
0
        private void destroy_session()
        {
            if (_sessionid != null)
            {
                List <nfs_argop4> ops = new List <nfs_argop4>();

                ops.Add(DestroySessionStub.standard(_sessionid));

                COMPOUND4res compound4res = sendCompound(ops, "");
                _sessionid = null;
            }
        }
Exemplo n.º 7
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));
            }
        }
Exemplo n.º 8
0
 public void processSequence(COMPOUND4res compound4res, COMPOUND4args compound4args)
 {
     if (compound4res.resarray != null && compound4res.resarray.Length != 0 && compound4res.resarray[0].resop == nfs_opnum4.OP_SEQUENCE &&
         compound4res.resarray[0].opsequence.sr_status == nfsstat4.NFS4_OK)
     {
         _lastUpdate = GetGMTInMS();
         ++_sequenceID.value.value;
         //let's try this also
         if (compound4res.status == nfsstat4.NFS4ERR_DELAY)
         {
             compound4args.argarray[0].opsequence.sa_sequenceid.value.value++;
         }
     }
 }
Exemplo n.º 9
0
        private void send_only_sequence()
        {
            List <nfs_argop4> ops = new List <nfs_argop4>();

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

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                //reclaim complete
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Exemplo n.º 10
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));
            }
        }
Exemplo n.º 11
0
        private void create_session()
        {
            List <nfs_argop4> ops = new List <nfs_argop4>();

            ops.Add(CreateSessionStub.standard(_clientIdByServer, _sequenceID));

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                _sessionid = compound4res.resarray[0].opcreate_session.csr_resok4.csr_sessionid;
                // FIXME: no idea why, but other wise server reply MISORDER
                _sequenceID.value.value = 0;

                maxTRrate = compound4res.resarray[0].opcreate_session.csr_resok4.csr_fore_chan_attrs.ca_maxrequestsize.value.value;
                maxRXrate = compound4res.resarray[0].opcreate_session.csr_resok4.csr_fore_chan_attrs.ca_maxresponsesize.value.value;
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Exemplo n.º 12
0
        private void exchange_ids()
        {
            List <nfs_argop4> ops = new List <nfs_argop4>();

            String domain = "localhost";
            String name   = "NFS Client ";

            //String guid = System.Environment.MachineName + "@" + domain;
            String guid = System.Guid.NewGuid().ToString();

            ops.Add(ExchengeIDStub.normal(domain, name, guid, NFSv4Protocol.EXCHGID4_FLAG_SUPP_MOVED_REFER + NFSv4Protocol.EXCHGID4_FLAG_USE_NON_PNFS, state_protect_how4.SP4_NONE));

            COMPOUND4res compound4res = sendCompound(ops, "");

            if (compound4res.status == nfsstat4.NFS4_OK)
            {
                /*if (compound4res.resarray[0].opexchange_id.eir_resok4.eir_server_impl_id.Length > 0)
                 * {
                 *  string serverId = System.Text.Encoding.UTF8.GetString(compound4res.resarray[0].opexchange_id.eir_resok4.eir_server_impl_id[0].nii_name.value.value);
                 * }
                 * else
                 * {
                 *  if (compound4res.resarray[0].opexchange_id.eir_resok4.eir_server_owner.so_major_id.Length > 0)
                 *  {
                 *      string serverId = System.Text.Encoding.UTF8.GetString(compound4res.resarray[0].opexchange_id.eir_resok4.eir_server_owner.so_major_id);
                 *      //throw new NFSConnectionException("Server name: ="+serverId);
                 *  }
                 * }*/

                _clientIdByServer = compound4res.resarray[0].opexchange_id.eir_resok4.eir_clientid;
                _sequenceID       = compound4res.resarray[0].opexchange_id.eir_resok4.eir_sequenceid;
            }
            else
            {
                throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
            }
        }
Exemplo n.º 13
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));
            }
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }