/// <summary>Returns true if the file is closed</summary> /// <exception cref="System.IO.IOException"/> internal static bool IsFileClosed(FSDirectory fsd, string src) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, true); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } return(!INodeFile.ValueOf(iip.GetLastINode(), src).IsUnderConstruction()); }
/// <exception cref="System.IO.IOException"/> internal static DirectoryListing GetListingInt(FSDirectory fsd, string srcArg, byte [] startAfter, bool needLocation) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(srcArg); string startAfterString = new string(startAfter, Charsets.Utf8); string src = fsd.ResolvePath(pc, srcArg, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, true); // Get file name when startAfter is an INodePath if (FSDirectory.IsReservedName(startAfterString)) { byte[][] startAfterComponents = FSDirectory.GetPathComponentsForReservedPath(startAfterString ); try { string tmp = FSDirectory.ResolvePath(src, startAfterComponents, fsd); byte[][] regularPath = INode.GetPathComponents(tmp); startAfter = regularPath[regularPath.Length - 1]; } catch (IOException) { // Possibly the inode is deleted throw new DirectoryListingStartAfterNotFoundException("Can't find startAfter " + startAfterString); } } bool isSuperUser = true; if (fsd.IsPermissionEnabled()) { if (iip.GetLastINode() != null && iip.GetLastINode().IsDirectory()) { fsd.CheckPathAccess(pc, iip, FsAction.ReadExecute); } else { fsd.CheckTraverse(pc, iip); } isSuperUser = pc.IsSuperUser(); } return(GetListing(fsd, iip, src, startAfter, needLocation, isSuperUser)); }
/// <exception cref="System.IO.IOException"/> internal static long GetPreferredBlockSize(FSDirectory fsd, string src) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); fsd.ReadLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, false); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } return(INodeFile.ValueOf(iip.GetLastINode(), src).GetPreferredBlockSize()); } finally { fsd.ReadUnlock(); } }
/// <exception cref="System.IO.IOException"/> internal static AclStatus GetAclStatus(FSDirectory fsd, string src) { CheckAclsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); string srcs = FSDirectory.NormalizePath(src); fsd.ReadLock(); try { // There is no real inode for the path ending in ".snapshot", so return a // non-null, unpopulated AclStatus. This is similar to getFileInfo. if (srcs.EndsWith(HdfsConstants.SeparatorDotSnapshotDir) && fsd.GetINode4DotSnapshot (srcs) != null) { return(new AclStatus.Builder().Owner(string.Empty).Group(string.Empty).Build()); } INodesInPath iip = fsd.GetINodesInPath(srcs, true); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } INode inode = FSDirectory.ResolveLastINode(iip); int snapshotId = iip.GetPathSnapshotId(); IList <AclEntry> acl = AclStorage.ReadINodeAcl(fsd.GetAttributes(src, inode.GetLocalNameBytes (), inode, snapshotId)); FsPermission fsPermission = inode.GetFsPermission(snapshotId); return(new AclStatus.Builder().Owner(inode.GetUserName()).Group(inode.GetGroupName ()).StickyBit(fsPermission.GetStickyBit()).SetPermission(fsPermission).AddEntries (acl).Build()); } finally { fsd.ReadUnlock(); } }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus Mkdirs(FSNamesystem fsn, string src, PermissionStatus permissions, bool createParent) { FSDirectory fsd = fsn.GetFSDirectory(); if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* NameSystem.mkdirs: " + src); } if (!DFSUtil.IsValidName(src)) { throw new InvalidPathException(src); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath4Write(src); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } INode lastINode = iip.GetLastINode(); if (lastINode != null && lastINode.IsFile()) { throw new FileAlreadyExistsException("Path is not a directory: " + src); } INodesInPath existing = lastINode != null ? iip : iip.GetExistingINodes(); if (lastINode == null) { if (fsd.IsPermissionEnabled()) { fsd.CheckAncestorAccess(pc, iip, FsAction.Write); } if (!createParent) { fsd.VerifyParentDir(iip, src); } // validate that we have enough inodes. This is, at best, a // heuristic because the mkdirs() operation might need to // create multiple inodes. fsn.CheckFsObjectLimit(); IList <string> nonExisting = iip.GetPath(existing.Length(), iip.Length() - existing .Length()); int length = nonExisting.Count; if (length > 1) { IList <string> ancestors = nonExisting.SubList(0, length - 1); // Ensure that the user can traversal the path by adding implicit // u+wx permission to all ancestor directories existing = CreateChildrenDirectories(fsd, existing, ancestors, AddImplicitUwx(permissions , permissions)); if (existing == null) { throw new IOException("Failed to create directory: " + src); } } if ((existing = CreateChildrenDirectories(fsd, existing, nonExisting.SubList(length - 1, length), permissions)) == null) { throw new IOException("Failed to create directory: " + src); } } return(fsd.GetAuditFileInfo(existing)); } finally { fsd.WriteUnlock(); } }