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 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); }
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); }