1/* 2 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package sun.nio.fs; 27 28import java.nio.file.attribute.*; 29import java.io.IOException; 30 31import static sun.nio.fs.UnixNativeDispatcher.*; 32import static sun.nio.fs.SolarisConstants.*; 33 34/** 35 * Solaris implementation of FileStore 36 */ 37 38class SolarisFileStore 39 extends UnixFileStore 40{ 41 private final boolean xattrEnabled; 42 43 SolarisFileStore(UnixPath file) throws IOException { 44 super(file); 45 this.xattrEnabled = xattrEnabled(); 46 } 47 48 SolarisFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException { 49 super(fs, entry); 50 this.xattrEnabled = xattrEnabled(); 51 } 52 53 // returns true if extended attributes enabled 54 private boolean xattrEnabled() { 55 long res = 0L; 56 try { 57 res = pathconf(file(), _PC_XATTR_ENABLED); 58 } catch (UnixException x) { 59 // ignore 60 } 61 return (res != 0L); 62 } 63 64 @Override 65 UnixMountEntry findMountEntry() throws IOException { 66 // On Solaris iterate over the entries in the mount table to find device 67 for (UnixMountEntry entry: file().getFileSystem().getMountEntries()) { 68 if (entry.dev() == dev()) { 69 return entry; 70 } 71 } 72 throw new IOException("Device not found in mnttab"); 73 } 74 75 @Override 76 public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { 77 if (type == AclFileAttributeView.class) { 78 // lookup fstypes.properties 79 FeatureStatus status = checkIfFeaturePresent("nfsv4acl"); 80 switch (status) { 81 case PRESENT : return true; 82 case NOT_PRESENT : return false; 83 default : 84 // AclFileAttributeView available on ZFS 85 return (type().equals("zfs")); 86 } 87 } 88 if (type == UserDefinedFileAttributeView.class) { 89 // lookup fstypes.properties 90 FeatureStatus status = checkIfFeaturePresent("xattr"); 91 switch (status) { 92 case PRESENT : return true; 93 case NOT_PRESENT : return false; 94 default : 95 // UserDefinedFileAttributeView available if extended 96 // attributes supported 97 return xattrEnabled; 98 } 99 } 100 return super.supportsFileAttributeView(type); 101 } 102 103 @Override 104 public boolean supportsFileAttributeView(String name) { 105 if (name.equals("acl")) 106 return supportsFileAttributeView(AclFileAttributeView.class); 107 if (name.equals("user")) 108 return supportsFileAttributeView(UserDefinedFileAttributeView.class); 109 return super.supportsFileAttributeView(name); 110 } 111} 112