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.PermissionStatus; 022 import org.apache.hadoop.hdfs.server.namenode.INodeFile.HeaderFormat; 023 024 /** 025 * The attributes of a file. 026 */ 027 @InterfaceAudience.Private 028 public 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 /** A copy of the inode file attributes */ 039 public static class SnapshotCopy extends INodeAttributes.SnapshotCopy 040 implements INodeFileAttributes { 041 private final long header; 042 043 public SnapshotCopy(byte[] name, PermissionStatus permissions, 044 AclFeature aclFeature, long modificationTime, long accessTime, 045 short replication, long preferredBlockSize) { 046 super(name, permissions, aclFeature, modificationTime, accessTime); 047 048 final long h = HeaderFormat.combineReplication(0L, replication); 049 header = HeaderFormat.combinePreferredBlockSize(h, preferredBlockSize); 050 } 051 052 public SnapshotCopy(INodeFile file) { 053 super(file); 054 this.header = file.getHeaderLong(); 055 } 056 057 @Override 058 public short getFileReplication() { 059 return HeaderFormat.getReplication(header); 060 } 061 062 @Override 063 public long getPreferredBlockSize() { 064 return HeaderFormat.getPreferredBlockSize(header); 065 } 066 067 @Override 068 public long getHeaderLong() { 069 return header; 070 } 071 } 072 }