private static PermissionStatus AddImplicitUwx(PermissionStatus parentPerm, PermissionStatus perm) { FsPermission p = parentPerm.GetPermission(); FsPermission ancestorPerm = new FsPermission(p.GetUserAction().Or(FsAction.WriteExecute ), p.GetGroupAction(), p.GetOtherAction()); return(new PermissionStatus(perm.GetUserName(), perm.GetGroupName(), ancestorPerm )); }
/// <summary>Return the JSON formatted ACL status of the specified file.</summary> /// <param name="path">a path specifies a file</param> /// <returns>JSON formatted AclStatus</returns> /// <exception cref="System.IO.IOException">if failed to serialize fileStatus to JSON. /// </exception> internal virtual string GetAclStatus(string path) { PermissionStatus p = GetPermissionStatus(path); IList <AclEntry> aclEntryList = GetAclEntryList(path); FsPermission permission = p.GetPermission(); AclStatus.Builder builder = new AclStatus.Builder(); builder.Owner(p.GetUserName()).Group(p.GetGroupName()).AddEntries(aclEntryList).SetPermission (permission).StickyBit(permission.GetStickyBit()); AclStatus aclStatus = builder.Build(); return(JsonUtil.ToJsonString(aclStatus)); }
/// <summary> /// Encode the /// <see cref="Org.Apache.Hadoop.FS.Permission.PermissionStatus"/> /// to a long. /// </summary> internal static long ToLong(PermissionStatus ps) { long permission = 0L; int user = SerialNumberManager.Instance.GetUserSerialNumber(ps.GetUserName()); permission = INodeWithAdditionalFields.PermissionStatusFormat.User.Bits.Combine(user , permission); int group = SerialNumberManager.Instance.GetGroupSerialNumber(ps.GetGroupName()); permission = INodeWithAdditionalFields.PermissionStatusFormat.Group.Bits.Combine( group, permission); int mode = ps.GetPermission().ToShort(); permission = INodeWithAdditionalFields.PermissionStatusFormat.Mode.Bits.Combine(mode , permission); return(permission); }
private IDictionary <string, object> GetFileStatus(FsImageProto.INodeSection.INode inode, bool printSuffix) { IDictionary <string, object> map = Maps.NewHashMap(); switch (inode.GetType()) { case FsImageProto.INodeSection.INode.Type.File: { FsImageProto.INodeSection.INodeFile f = inode.GetFile(); PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(f.GetPermission() , stringTable); map["accessTime"] = f.GetAccessTime(); map["blockSize"] = f.GetPreferredBlockSize(); map["group"] = p.GetGroupName(); map["length"] = GetFileSize(f); map["modificationTime"] = f.GetModificationTime(); map["owner"] = p.GetUserName(); map["pathSuffix"] = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty; map["permission"] = ToString(p.GetPermission()); map["replication"] = f.GetReplication(); map["type"] = inode.GetType(); map["fileId"] = inode.GetId(); map["childrenNum"] = 0; return(map); } case FsImageProto.INodeSection.INode.Type.Directory: { FsImageProto.INodeSection.INodeDirectory d = inode.GetDirectory(); PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission() , stringTable); map["accessTime"] = 0; map["blockSize"] = 0; map["group"] = p.GetGroupName(); map["length"] = 0; map["modificationTime"] = d.GetModificationTime(); map["owner"] = p.GetUserName(); map["pathSuffix"] = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty; map["permission"] = ToString(p.GetPermission()); map["replication"] = 0; map["type"] = inode.GetType(); map["fileId"] = inode.GetId(); map["childrenNum"] = dirmap.Contains(inode.GetId()) ? dirmap[inode.GetId()].Length : 0; return(map); } case FsImageProto.INodeSection.INode.Type.Symlink: { FsImageProto.INodeSection.INodeSymlink d = inode.GetSymlink(); PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission() , stringTable); map["accessTime"] = d.GetAccessTime(); map["blockSize"] = 0; map["group"] = p.GetGroupName(); map["length"] = 0; map["modificationTime"] = d.GetModificationTime(); map["owner"] = p.GetUserName(); map["pathSuffix"] = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty; map["permission"] = ToString(p.GetPermission()); map["replication"] = 0; map["type"] = inode.GetType(); map["symlink"] = d.GetTarget().ToStringUtf8(); map["fileId"] = inode.GetId(); map["childrenNum"] = 0; return(map); } default: { return(null); } } }
protected internal override string GetEntry(string parent, FsImageProto.INodeSection.INode inode) { StringBuilder buffer = new StringBuilder(); string inodeName = inode.GetName().ToStringUtf8(); Path path = new Path(parent.IsEmpty() ? "/" : parent, inodeName.IsEmpty() ? "/" : inodeName); buffer.Append(path.ToString()); PermissionStatus p = null; switch (inode.GetType()) { case FsImageProto.INodeSection.INode.Type.File: { FsImageProto.INodeSection.INodeFile file = inode.GetFile(); p = GetPermission(file.GetPermission()); Append(buffer, file.GetReplication()); Append(buffer, FormatDate(file.GetModificationTime())); Append(buffer, FormatDate(file.GetAccessTime())); Append(buffer, file.GetPreferredBlockSize()); Append(buffer, file.GetBlocksCount()); Append(buffer, FSImageLoader.GetFileSize(file)); Append(buffer, 0); // NS_QUOTA Append(buffer, 0); // DS_QUOTA break; } case FsImageProto.INodeSection.INode.Type.Directory: { FsImageProto.INodeSection.INodeDirectory dir = inode.GetDirectory(); p = GetPermission(dir.GetPermission()); Append(buffer, 0); // Replication Append(buffer, FormatDate(dir.GetModificationTime())); Append(buffer, FormatDate(0)); // Access time. Append(buffer, 0); // Block size. Append(buffer, 0); // Num blocks. Append(buffer, 0); // Num bytes. Append(buffer, dir.GetNsQuota()); Append(buffer, dir.GetDsQuota()); break; } case FsImageProto.INodeSection.INode.Type.Symlink: { FsImageProto.INodeSection.INodeSymlink s = inode.GetSymlink(); p = GetPermission(s.GetPermission()); Append(buffer, 0); // Replication Append(buffer, FormatDate(s.GetModificationTime())); Append(buffer, FormatDate(s.GetAccessTime())); Append(buffer, 0); // Block size. Append(buffer, 0); // Num blocks. Append(buffer, 0); // Num bytes. Append(buffer, 0); // NS_QUOTA Append(buffer, 0); // DS_QUOTA break; } default: { break; } } System.Diagnostics.Debug.Assert(p != null); Append(buffer, p.GetPermission().ToString()); Append(buffer, p.GetUserName()); Append(buffer, p.GetGroupName()); return(buffer.ToString()); }