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.PermissionStatus;
022import org.apache.hadoop.hdfs.server.namenode.INodeFile.HeaderFormat;
023import org.apache.hadoop.hdfs.server.namenode.XAttrFeature;
024/**
025 * The attributes of a file.
026 */
027@InterfaceAudience.Private
028public interface INodeFileAttributes extends INodeAttributes {
029  /** @return the file replication. */
030  public short getFileReplication();
031
032  /** @return preferred block size in bytes */
033  public long getPreferredBlockSize();
034
035  /** @return the header as a long. */
036  public long getHeaderLong();
037
038  public boolean metadataEquals(INodeFileAttributes other);
039
040  public byte getLocalStoragePolicyID();
041
042  /** A copy of the inode file attributes */
043  public static class SnapshotCopy extends INodeAttributes.SnapshotCopy
044      implements INodeFileAttributes {
045    private final long header;
046
047    public SnapshotCopy(byte[] name, PermissionStatus permissions,
048        AclFeature aclFeature, long modificationTime, long accessTime,
049        short replication, long preferredBlockSize, byte storagePolicyID,
050        XAttrFeature xAttrsFeature) {
051      super(name, permissions, aclFeature, modificationTime, accessTime, 
052          xAttrsFeature);
053      header = HeaderFormat.toLong(preferredBlockSize, replication, storagePolicyID);
054    }
055
056    public SnapshotCopy(INodeFile file) {
057      super(file);
058      this.header = file.getHeaderLong();
059    }
060
061    @Override
062    public boolean isDirectory() {
063      return false;
064    }
065
066    @Override
067    public short getFileReplication() {
068      return HeaderFormat.getReplication(header);
069    }
070
071    @Override
072    public long getPreferredBlockSize() {
073      return HeaderFormat.getPreferredBlockSize(header);
074    }
075
076    @Override
077    public byte getLocalStoragePolicyID() {
078      return HeaderFormat.getStoragePolicyID(header);
079    }
080
081    @Override
082    public long getHeaderLong() {
083      return header;
084    }
085
086    @Override
087    public boolean metadataEquals(INodeFileAttributes other) {
088      return other != null
089          && getHeaderLong()== other.getHeaderLong()
090          && getPermissionLong() == other.getPermissionLong()
091          && getAclFeature() == other.getAclFeature()
092          && getXAttrFeature() == other.getXAttrFeature();
093    }
094  }
095}