//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 void CreateFile(string FileFullName, NFSPermission Mode) { if (_ProtocolV2 == null) { throw new NFSConnectionException("NFS Client not connected!"); } if (_MountProtocolV2 == null) { throw new NFSMountConnectionException("NFS Device not connected!"); } if (Mode == null) { Mode = new NFSPermission(7, 7, 7); } string ParentDirectory = System.IO.Path.GetDirectoryName(FileFullName); string FileName = System.IO.Path.GetFileName(FileFullName); NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory); CreateArguments dpArgCreate = new CreateArguments(); dpArgCreate.Attributes = new CreateAttributes(); dpArgCreate.Attributes.LastAccessedTime = new NFSTimeValue(); dpArgCreate.Attributes.ModifiedTime = new NFSTimeValue(); dpArgCreate.Attributes.Mode = Mode; dpArgCreate.Attributes.UserID = this._UserID; dpArgCreate.Attributes.GroupID = this._GroupID; dpArgCreate.Attributes.Size = 0; dpArgCreate.Where = new ItemOperationArguments(); dpArgCreate.Where.Directory = new NFSHandle(ParentItemAttributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION); dpArgCreate.Where.Name = new Name(FileName); ItemOperationStatus pDirOpRes = _ProtocolV2.NFSPROC_CREATE(dpArgCreate); if (pDirOpRes == null || pDirOpRes.Status != NFSStats.NFS_OK) { if (pDirOpRes == null) { throw new NFSGeneralException("NFSPROC_CREATE: failure"); } ExceptionHelpers.ThrowException(pDirOpRes.Status); } }
public void CreateFile(string FileFullName, NFSPermission Mode) { if (_ProtocolV3 == null) { throw new NFSConnectionException("NFS Client not connected!"); } if (_MountProtocolV3 == null) { throw new NFSMountConnectionException("NFS Device not connected!"); } if (Mode == null) { Mode = new NFSPermission(7, 7, 7); } string ParentDirectory = System.IO.Path.GetDirectoryName(FileFullName); string FileName = System.IO.Path.GetFileName(FileFullName); NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory); MakeFileArguments dpArgCreate = new MakeFileArguments(); dpArgCreate.How = new MakeFileHow(); dpArgCreate.How.Mode = MakeFileHow.MakeFileModes.UNCHECKED; dpArgCreate.How.Attributes = new MakeAttributes(); dpArgCreate.How.Attributes.LastAccessedTime = new NFSTimeValue(); dpArgCreate.How.Attributes.ModifiedTime = new NFSTimeValue(); dpArgCreate.How.Attributes.Mode = Mode; dpArgCreate.How.Attributes.SetMode = true; dpArgCreate.How.Attributes.UserID = this._UserID; dpArgCreate.How.Attributes.SetUserID = true; dpArgCreate.How.Attributes.GroupID = this._GroupID; dpArgCreate.How.Attributes.SetGroupID = true; dpArgCreate.How.Attributes.Size = 0; dpArgCreate.How.Attributes.SetSize = true; dpArgCreate.How.Verification = new byte[NFSv3Protocol.NFS3_CREATEVERFSIZE]; dpArgCreate.Where = new ItemOperationArguments(); dpArgCreate.Where.Directory = new NFSHandle(ParentItemAttributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3); dpArgCreate.Where.Name = new Name(FileName); ResultObject<MakeFileAccessOK, MakeFileAccessFAIL> pCreateRes = _ProtocolV3.NFSPROC3_CREATE(dpArgCreate); if (pCreateRes == null || pCreateRes.Status != NFSStats.NFS_OK) { if (pCreateRes == null) { throw new NFSGeneralException("NFSPROC3_CREATE: failure"); } ExceptionHelpers.ThrowException(pCreateRes.Status); } }
public void CreateDirectory(string DirectoryFullName, NFSPermission Mode) { if (_ProtocolV3 == null) { throw new NFSConnectionException("NFS Client not connected!"); } if (_MountProtocolV3 == null) { throw new NFSMountConnectionException("NFS Device not connected!"); } if (Mode == null) { Mode = new NFSPermission(7, 7, 7); } string ParentDirectory = System.IO.Path.GetDirectoryName(DirectoryFullName); string DirectoryName = System.IO.Path.GetFileName(DirectoryFullName); NFSAttributes ParentItemAttributes = GetItemAttributes(ParentDirectory); MakeFolderArguments dpArgCreate = new MakeFolderArguments(); dpArgCreate.Attributes = new MakeAttributes(); dpArgCreate.Attributes.LastAccessedTime = new NFSTimeValue(); dpArgCreate.Attributes.ModifiedTime = new NFSTimeValue(); dpArgCreate.Attributes.Mode = Mode; dpArgCreate.Attributes.SetMode = true; dpArgCreate.Attributes.UserID = this._UserID; dpArgCreate.Attributes.SetUserID = true; dpArgCreate.Attributes.GroupID = this._GroupID; dpArgCreate.Attributes.SetGroupID = true; dpArgCreate.Where = new ItemOperationArguments(); dpArgCreate.Where.Directory = new NFSHandle(ParentItemAttributes.Handle, V3.RPC.NFSv3Protocol.NFS_V3); dpArgCreate.Where.Name = new Name(DirectoryName); ResultObject<MakeFolderAccessOK, MakeFolderAccessFAIL> pDirOpRes = _ProtocolV3.NFSPROC3_MKDIR(dpArgCreate); if (pDirOpRes == null || pDirOpRes.Status != NFSStats.NFS_OK) { if (pDirOpRes == null) { throw new NFSGeneralException("NFSPROC3_MKDIR: failure"); } ExceptionHelpers.ThrowException(pDirOpRes.Status); } }
/// <summary> /// Create a new file with permission /// </summary> /// <param name="FileFullName">File full name</param> /// <param name="Mode">File permission</param> public void CreateFile(String FileFullName, NFSPermission Mode) { FileFullName = CorrectPath(FileFullName); this._nfsInterface.CreateFile(FileFullName, Mode); }
/// <summary> /// Create a new directory with Permission /// </summary> /// <param name="DirectoryFullName">Directory full name</param> /// <param name="Mode">Directory permissions</param> public void CreateDirectory(String DirectoryFullName, NFSPermission Mode) { DirectoryFullName = CorrectPath(DirectoryFullName); String ParentPath = System.IO.Path.GetDirectoryName(DirectoryFullName); if (!String.IsNullOrEmpty(ParentPath) && String.Compare(ParentPath, ".") != 0 && !FileExists(ParentPath)) { CreateDirectory(ParentPath); } this._nfsInterface.CreateDirectory(DirectoryFullName, Mode); }
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)); } } }
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)); } }
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; }