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