Exemplo n.º 1
0
        public static nfs_argop4 normal(string nii_domain, string nii_name,
        string co_ownerid, int flags, int how)
        {
            //for transormation
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();


            nfs_argop4 op = new nfs_argop4();
            op.argop = nfs_opnum4.OP_EXCHANGE_ID;
            op.opexchange_id = new EXCHANGE_ID4args();


           op.opexchange_id.eia_client_impl_id = new nfs_impl_id4[1];
            nfs_impl_id4 n4 = new nfs_impl_id4();
            n4.nii_domain = new utf8str_cis(new utf8string(encoding.GetBytes(nii_domain)));
           n4.nii_name = new utf8str_cs(new utf8string(encoding.GetBytes(nii_name)));
            op.opexchange_id.eia_client_impl_id[0] = n4;

            nfstime4 releaseDate = new nfstime4();
            releaseDate.nseconds = new uint32_t(0);
            releaseDate.seconds = new int64_t((long)(DateTime.UtcNow - new DateTime
    (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds);  //seconds here

            op.opexchange_id.eia_client_impl_id[0].nii_date = releaseDate;
            op.opexchange_id.eia_clientowner = new client_owner4();

            op.opexchange_id.eia_clientowner.co_ownerid = encoding.GetBytes(co_ownerid);

            op.opexchange_id.eia_clientowner.co_verifier = new verifier4();
            op.opexchange_id.eia_clientowner.co_verifier.value = releaseDate.seconds.value;   //new byte[NFSv4Protocol.NFS4_VERIFIER_SIZE];

            //byte[] locVerifier = encoding.GetBytes(releaseDate.seconds.value.ToString("X"));


            //int len = locVerifier.Length > NFSv4Protocol.NFS4_VERIFIER_SIZE ? NFSv4Protocol.NFS4_VERIFIER_SIZE : locVerifier.Length;
           // Array.Copy(locVerifier, 0, op.opexchange_id.eia_clientowner.co_verifier.value, 0, len);

            op.opexchange_id.eia_flags = new uint32_t(flags);
            op.opexchange_id.eia_state_protect = new state_protect4_a();
            op.opexchange_id.eia_state_protect.spa_how = how;
            return op;
        }
Exemplo n.º 2
0
    static void xdr2fattr( Dictionary<int,Object> attr, int fattr , XdrDecodingStream xdr)
    {

        switch(fattr) {

            case NFSv4Protocol.FATTR4_SIZE :
                uint64_t size = new uint64_t();
                size.xdrDecode(xdr);
                attr.Add(fattr, size);
                break;
            case NFSv4Protocol.FATTR4_MODE :
                mode4 mode = new mode4();
                mode.xdrDecode(xdr);
                attr.Add(fattr, mode);
                break;
            case NFSv4Protocol.FATTR4_TYPE :
                fattr4_type type = new fattr4_type();
                type.xdrDecode(xdr);
                attr.Add(fattr,type );
                break;
            case NFSv4Protocol.FATTR4_TIME_CREATE :
                nfstime4 time = new nfstime4();
                time.xdrDecode(xdr);
                attr.Add(fattr,time);
                break;
           case NFSv4Protocol.FATTR4_TIME_ACCESS :
                nfstime4 time2 = new nfstime4();
                time2.xdrDecode(xdr);
                attr.Add(fattr,time2);
                break;
           case NFSv4Protocol.FATTR4_TIME_MODIFY :
                nfstime4 time3 = new nfstime4();
                time3.xdrDecode(xdr);
                attr.Add(fattr,time3);
                break;
            /*case NFSv4Protocol.FATTR4_OWNER :
// TODO: use princilat
utf8str_cs owner = new utf8str_cs ();
owner.xdrDecode(xdr);
String new_owner = new String(owner.value.value);
attr.Add(fattr,new_owner );
break;
case NFSv4Protocol.FATTR4_OWNER_GROUP :
// TODO: use princilat
utf8str_cs owner_group = new utf8str_cs ();
owner_group.xdrDecode(xdr);
String new_group = new String(owner_group.value.value);
attr.Add(fattr,new_group );
break;*/
            default:
                break;

        }


    }
Exemplo n.º 3
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);
        }