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 */
018package org.apache.hadoop.hdfs.server.namenode;
019
020import org.apache.hadoop.classification.InterfaceAudience;
021import org.apache.hadoop.fs.permission.FsPermission;
022import org.apache.hadoop.fs.permission.PermissionStatus;
023import org.apache.hadoop.hdfs.server.namenode.INodeWithAdditionalFields.PermissionStatusFormat;
024import org.apache.hadoop.hdfs.server.namenode.XAttrFeature;
025
026/**
027 * The attributes of an inode.
028 */
029@InterfaceAudience.Private
030public interface INodeAttributes {
031  /**
032   * @return null if the local name is null;
033   *         otherwise, return the local name byte array.
034   */
035  public byte[] getLocalNameBytes();
036
037  /** @return the user name. */
038  public String getUserName();
039
040  /** @return the group name. */
041  public String getGroupName();
042  
043  /** @return the permission. */
044  public FsPermission getFsPermission();
045
046  /** @return the permission as a short. */
047  public short getFsPermissionShort();
048  
049  /** @return the permission information as a long. */
050  public long getPermissionLong();
051
052  /** @return the ACL feature. */
053  public AclFeature getAclFeature();
054  
055  /** @return the XAttrs feature. */
056  public XAttrFeature getXAttrFeature();
057
058  /** @return the modification time. */
059  public long getModificationTime();
060
061  /** @return the access time. */
062  public long getAccessTime();
063
064  /** A read-only copy of the inode attributes. */
065  public static abstract class SnapshotCopy implements INodeAttributes {
066    private final byte[] name;
067    private final long permission;
068    private final AclFeature aclFeature;
069    private final long modificationTime;
070    private final long accessTime;
071    private XAttrFeature xAttrFeature;
072
073    SnapshotCopy(byte[] name, PermissionStatus permissions,
074        AclFeature aclFeature, long modificationTime, long accessTime, 
075        XAttrFeature xAttrFeature) {
076      this.name = name;
077      this.permission = PermissionStatusFormat.toLong(permissions);
078      this.aclFeature = aclFeature;
079      this.modificationTime = modificationTime;
080      this.accessTime = accessTime;
081      this.xAttrFeature = xAttrFeature;
082    }
083
084    SnapshotCopy(INode inode) {
085      this.name = inode.getLocalNameBytes();
086      this.permission = inode.getPermissionLong();
087      this.aclFeature = inode.getAclFeature();
088      this.modificationTime = inode.getModificationTime();
089      this.accessTime = inode.getAccessTime();
090      this.xAttrFeature = inode.getXAttrFeature();
091    }
092
093    @Override
094    public final byte[] getLocalNameBytes() {
095      return name;
096    }
097
098    @Override
099    public final String getUserName() {
100      return PermissionStatusFormat.getUser(permission);
101    }
102
103    @Override
104    public final String getGroupName() {
105      return PermissionStatusFormat.getGroup(permission);
106    }
107
108    @Override
109    public final FsPermission getFsPermission() {
110      return new FsPermission(getFsPermissionShort());
111    }
112
113    @Override
114    public final short getFsPermissionShort() {
115      return PermissionStatusFormat.getMode(permission);
116    }
117    
118    @Override
119    public long getPermissionLong() {
120      return permission;
121    }
122
123    @Override
124    public AclFeature getAclFeature() {
125      return aclFeature;
126    }
127
128    @Override
129    public final long getModificationTime() {
130      return modificationTime;
131    }
132
133    @Override
134    public final long getAccessTime() {
135      return accessTime;
136    }
137    
138    @Override
139    public final XAttrFeature getXAttrFeature() {
140      return xAttrFeature;
141    }
142  }
143}