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; } }
public static byte[] openAttrs(int user, int group, int other,long sizea) { XdrBufferEncodingStream xdr = new XdrBufferEncodingStream(1024); //starts encoding xdr.beginEncoding(null, 0); user = 7 << 6; group = 7 << 3; other = 7; mode4 fmode = new mode4(); fmode.value = new uint32_t(group + user + other); fattr4_mode mode = new fattr4_mode(fmode); fattr4_size size = new fattr4_size(new uint64_t(sizea)); size.xdrEncode(xdr); mode.xdrEncode(xdr); xdr.endEncoding(); //end encoding byte[] retBytes = new byte[xdr.getXdrLength()]; Array.Copy(xdr.getXdrData(), 0, retBytes, 0, xdr.getXdrLength()); return retBytes; }
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); }