public NFSAttributes GetItemAttributes(String ItemFullName, bool ThrowExceptionIfNotFound = true) { if (_ProtocolV2 == null) { throw new NFSConnectionException("NFS Client not connected!"); } if (_MountProtocolV2 == null) { throw new NFSMountConnectionException("NFS Device not connected!"); } NFSAttributes attributes = null; if (String.IsNullOrEmpty(ItemFullName)) ItemFullName = "."; NFSHandle currentItem = _RootDirectoryHandleObject; String[] PathTree = ItemFullName.Split(@"\".ToCharArray()); for (int pC = 0; pC < PathTree.Length; pC++) { ItemOperationArguments dpDrArgs = new ItemOperationArguments(); dpDrArgs.Directory = currentItem; dpDrArgs.Name = new Name(PathTree[pC]); ItemOperationStatus pDirOpRes = _ProtocolV2.NFSPROC_LOOKUP(dpDrArgs); if (pDirOpRes != null && pDirOpRes.Status == NFSStats.NFS_OK) { currentItem = pDirOpRes.OK.HandleObject; if (PathTree.Length - 1 == pC) { attributes = new NFSAttributes( pDirOpRes.OK.Attributes.CreateTime.Seconds, pDirOpRes.OK.Attributes.LastAccessedTime.Seconds, pDirOpRes.OK.Attributes.ModifiedTime.Seconds, pDirOpRes.OK.Attributes.Type, pDirOpRes.OK.Attributes.Mode, pDirOpRes.OK.Attributes.Size, pDirOpRes.OK.HandleObject.Value); } } else { if (pDirOpRes == null || pDirOpRes.Status == NFSStats.NFSERR_NOENT) { attributes = null; break; } if(ThrowExceptionIfNotFound) ExceptionHelpers.ThrowException(pDirOpRes.Status); } } return attributes; }
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; }