public void xdrDecode(XdrDecodingStream xdr) { this._type = (NFSItemTypes)xdr.xdrDecodeInt(); switch (this._type) { case NFSItemTypes.NFCHR: this._device_chr = new DeviceData(xdr); break; case NFSItemTypes.NFBLK: this._device_blk = new DeviceData(xdr); break; case NFSItemTypes.NFSOCK: this._pipe_attributes_sock = new MakeAttributes(xdr); break; case NFSItemTypes.NFFIFO: this._pipe_attributes_fifo = new MakeAttributes(xdr); break; default: break; } }
//for nfs 4 //nfs_fh4 _fh; public NFSAttributes(int cdateTime, int adateTime, int mdateTime, NFSItemTypes type, NFSPermission mode, long size, byte[] handle) { this._cdateTime = new System.DateTime(1970, 1, 1).AddSeconds(cdateTime); this._adateTime = new System.DateTime(1970, 1, 1).AddSeconds(adateTime); this._mdateTime = new System.DateTime(1970, 1, 1).AddSeconds(mdateTime); this._type = type; this._size = size; this._mode = mode; this._handle = (Byte[])handle.Clone(); }
public NFSAttributes(int cdateTime, int adateTime, int mdateTime, NFSItemTypes type, NFSPermission mode, long size, Byte[] handle) { this._cdateTime = new System.DateTime(1970, 1, 1).AddSeconds(cdateTime); this._adateTime = new System.DateTime(1970, 1, 1).AddSeconds(adateTime); this._mdateTime = new System.DateTime(1970, 1, 1).AddSeconds(mdateTime); this._type = type; this._size = size; this._mode = mode; this._handle = (Byte[])handle.Clone(); }
public void xdrDecode(XdrDecodingStream xdr) { this._type = (NFSItemTypes)xdr.xdrDecodeInt(); this._mode = new NFSPermission(); this._mode.Mode = xdr.xdrDecodeInt(); this._nlink = xdr.xdrDecodeInt(); this._uid = xdr.xdrDecodeInt(); this._gid = xdr.xdrDecodeInt(); this._size = xdr.xdrDecodeInt(); this._blocksize = xdr.xdrDecodeInt(); this._rdev = xdr.xdrDecodeInt(); this._blocks = xdr.xdrDecodeInt(); /* Calculate File Size (>4GB) */ //int fileSize = (int)this._size; //double blockForFile = (double)fileSize / (double)this._blocksize; //double blocksOnDisk = blockForFile + 0.49; //blocksOnDisk = System.Math.Round(blocksOnDisk); ///* I think it's a bug on blocks value, cause some times blocks value // * comes 8 value greater than calculated size. // * Following fixes the related bug(?) */ //if (blocksOnDisk <= ((this._blocks / 8) - 1)) //{ this._blocks -= 8; } //double diff = (blocksOnDisk - blockForFile) * this._blocksize; //long bytesInBlock = (long)(this._blocks / 8) * (long)this._blocksize; //bytesInBlock -= (int)diff; //this._size = bytesInBlock >= 0? bytesInBlock : _size; /* ---- */ this._fsid = xdr.xdrDecodeInt(); this._fileid = xdr.xdrDecodeInt(); this._atime = new NFSTimeValue(xdr); this._mtime = new NFSTimeValue(xdr); this._ctime = new NFSTimeValue(xdr); }
public void xdrDecode(XdrDecodingStream xdr) { this._type = (NFSItemTypes)xdr.xdrDecodeInt(); this._mode = new NFSPermission(); this._mode.Mode = xdr.xdrDecodeInt(); this._nlink = xdr.xdrDecodeInt(); this._uid = xdr.xdrDecodeInt(); this._gid = xdr.xdrDecodeInt(); this._size = xdr.xdrDecodeLong(); this._used = xdr.xdrDecodeLong(); this._rdev = new SpecInformation(); this._rdev.xdrDecode(xdr); this._fsid = xdr.xdrDecodeLong(); this._fileid = xdr.xdrDecodeLong(); this._atime = new NFSTimeValue(xdr); this._mtime = new NFSTimeValue(xdr); this._ctime = new NFSTimeValue(xdr); }
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); }