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