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