001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.hadoop.hdfs.server.namenode; 019 020 import org.apache.hadoop.classification.InterfaceAudience; 021 import org.apache.hadoop.fs.permission.FsPermission; 022 import org.apache.hadoop.fs.permission.PermissionStatus; 023 import org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields.PermissionStatusFormat; 024 025 /** 026 * The attributes of an inode. 027 */ 028 @InterfaceAudience.Private 029 public interface INodeAttributes { 030 /** 031 * @return null if the local name is null; 032 * otherwise, return the local name byte array. 033 */ 034 public byte[] getLocalNameBytes(); 035 036 /** @return the user name. */ 037 public String getUserName(); 038 039 /** @return the group name. */ 040 public String getGroupName(); 041 042 /** @return the permission. */ 043 public FsPermission getFsPermission(); 044 045 /** @return the permission as a short. */ 046 public short getFsPermissionShort(); 047 048 /** @return the permission information as a long. */ 049 public long getPermissionLong(); 050 051 /** @return the modification time. */ 052 public long getModificationTime(); 053 054 /** @return the access time. */ 055 public long getAccessTime(); 056 057 /** A read-only copy of the inode attributes. */ 058 public static abstract class SnapshotCopy implements INodeAttributes { 059 private final byte[] name; 060 private final long permission; 061 private final long modificationTime; 062 private final long accessTime; 063 064 SnapshotCopy(byte[] name, PermissionStatus permissions, 065 long modificationTime, long accessTime) { 066 this.name = name; 067 this.permission = PermissionStatusFormat.toLong(permissions); 068 this.modificationTime = modificationTime; 069 this.accessTime = accessTime; 070 } 071 072 SnapshotCopy(INode inode) { 073 this.name = inode.getLocalNameBytes(); 074 this.permission = inode.getPermissionLong(); 075 this.modificationTime = inode.getModificationTime(); 076 this.accessTime = inode.getAccessTime(); 077 } 078 079 @Override 080 public final byte[] getLocalNameBytes() { 081 return name; 082 } 083 084 @Override 085 public final String getUserName() { 086 final int n = (int)PermissionStatusFormat.USER.retrieve(permission); 087 return SerialNumberManager.INSTANCE.getUser(n); 088 } 089 090 @Override 091 public final String getGroupName() { 092 final int n = (int)PermissionStatusFormat.GROUP.retrieve(permission); 093 return SerialNumberManager.INSTANCE.getGroup(n); 094 } 095 096 @Override 097 public final FsPermission getFsPermission() { 098 return new FsPermission(getFsPermissionShort()); 099 } 100 101 @Override 102 public final short getFsPermissionShort() { 103 return (short)PermissionStatusFormat.MODE.retrieve(permission); 104 } 105 106 @Override 107 public long getPermissionLong() { 108 return permission; 109 } 110 111 @Override 112 public final long getModificationTime() { 113 return modificationTime; 114 } 115 116 @Override 117 public final long getAccessTime() { 118 return accessTime; 119 } 120 } 121 }