1 /* 2 * Copyright (c) 2008, 2009, 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 26 package sun.nio.fs; 27 28 import java.nio.file.*; 29 import java.nio.file.attribute.*; 30 import java.io.IOException; 31 import java.util.*; 32 import java.security.AccessController; 33 import sun.security.action.GetPropertyAction; 34 import static sun.nio.fs.UnixNativeDispatcher.*; 35 36 /** 37 * Solaris implementation of FileSystem 38 */ 39 40 class SolarisFileSystem extends UnixFileSystem { 41 private final boolean hasSolaris11Features; 42 43 SolarisFileSystem(UnixFileSystemProvider provider, String dir) { 44 super(provider, dir); 45 46 // check os.version 47 String osversion = AccessController 48 .doPrivileged(new GetPropertyAction("os.version")); 49 String[] vers = Util.split(osversion, '.'); 50 assert vers.length >= 2; 51 int majorVersion = Integer.parseInt(vers[0]); 52 int minorVersion = Integer.parseInt(vers[1]); 53 this.hasSolaris11Features = 54 (majorVersion > 5 || (majorVersion == 5 && minorVersion >= 11)); 55 } 56 57 @Override 58 boolean isSolaris() { 59 return true; 60 } 61 62 @Override 63 public WatchService newWatchService() 64 throws IOException 65 { 66 // FEN available since Solaris 11 67 if (hasSolaris11Features) { 68 return new SolarisWatchService(this); 69 } else { 70 return new PollingWatchService(); 71 } 72 } 73 74 @Override 75 @SuppressWarnings("unchecked") 76 public <V extends FileAttributeView> V newFileAttributeView(Class<V> view, 77 UnixPath file, LinkOption... options) 78 { 79 if (view == AclFileAttributeView.class) 80 return (V) new SolarisAclFileAttributeView(file, followLinks(options)); 81 if (view == UserDefinedFileAttributeView.class) { 82 return(V) new SolarisUserDefinedFileAttributeView(file, followLinks(options)); 83 } 84 return super.newFileAttributeView(view, file, options); 85 } 86 87 @Override 88 protected DynamicFileAttributeView newFileAttributeView(String name, 89 UnixPath file, 90 LinkOption... options) 91 { 92 if (name.equals("acl")) 93 return new SolarisAclFileAttributeView(file, followLinks(options)); 94 if (name.equals("user")) 95 return new SolarisUserDefinedFileAttributeView(file, followLinks(options)); 96 return super.newFileAttributeView(name, file, options); 97 } 98 99 // lazy initialization of the list of supported attribute views 100 private static class SupportedFileFileAttributeViewsHolder { 101 static final Set<String> supportedFileAttributeViews = 102 supportedFileAttributeViews(); 103 private static Set<String> supportedFileAttributeViews() { 104 Set<String> result = new HashSet<String>(); 105 result.addAll(UnixFileSystem.standardFileAttributeViews()); 106 // additional Solaris-specific views 107 result.add("acl"); 108 result.add("user"); 109 return Collections.unmodifiableSet(result); 110 } 111 } 112 113 @Override 114 public Set<String> supportedFileAttributeViews() { 115 return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews; 116 } 117 118 @Override 119 void copyNonPosixAttributes(int ofd, int nfd) { 120 SolarisUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd); 121 // TDB: copy ACL from source to target 122 } 123 124 /** 125 * Returns object to iterate over entries in /etc/mnttab 126 */ 127 @Override 128 Iterable<UnixMountEntry> getMountEntries() { 129 ArrayList<UnixMountEntry> entries = new ArrayList<UnixMountEntry>(); 130 try { 131 UnixPath mnttab = new UnixPath(this, "/etc/mnttab"); 132 long fp = fopen(mnttab, "r"); 133 try { 134 for (;;) { 135 UnixMountEntry entry = new UnixMountEntry(); 136 int res = getextmntent(fp, entry); 137 if (res < 0) 138 break; 139 entries.add(entry); 140 } 141 } finally { 142 fclose(fp); 143 } 144 } catch (UnixException x) { 145 // nothing we can do 146 } 147 return entries; 148 } 149 150 @Override 151 FileStore getFileStore(UnixPath path) throws IOException { 152 return new SolarisFileStore(path); 153 } 154 155 @Override 156 FileStore getFileStore(UnixMountEntry entry) throws IOException { 157 return new SolarisFileStore(this, entry); 158 } 159 }