Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/SolarisFileSystem.java
32288 views
/*1* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.fs;2627import java.nio.file.*;28import java.io.IOException;29import java.util.*;30import java.security.AccessController;31import sun.security.action.GetPropertyAction;32import static sun.nio.fs.SolarisNativeDispatcher.*;3334/**35* Solaris implementation of FileSystem36*/3738class SolarisFileSystem extends UnixFileSystem {39private final boolean hasSolaris11Features;4041SolarisFileSystem(UnixFileSystemProvider provider, String dir) {42super(provider, dir);4344// check os.version45String osversion = AccessController46.doPrivileged(new GetPropertyAction("os.version"));47String[] vers = Util.split(osversion, '.');48assert vers.length >= 2;49int majorVersion = Integer.parseInt(vers[0]);50int minorVersion = Integer.parseInt(vers[1]);51this.hasSolaris11Features =52(majorVersion > 5 || (majorVersion == 5 && minorVersion >= 11));53}5455@Override56boolean isSolaris() {57return true;58}5960@Override61public WatchService newWatchService()62throws IOException63{64// FEN available since Solaris 1165if (hasSolaris11Features) {66return new SolarisWatchService(this);67} else {68return new PollingWatchService();69}70}717273// lazy initialization of the list of supported attribute views74private static class SupportedFileFileAttributeViewsHolder {75static final Set<String> supportedFileAttributeViews =76supportedFileAttributeViews();77private static Set<String> supportedFileAttributeViews() {78Set<String> result = new HashSet<>();79result.addAll(standardFileAttributeViews());80// additional Solaris-specific views81result.add("acl");82result.add("user");83return Collections.unmodifiableSet(result);84}85}8687@Override88public Set<String> supportedFileAttributeViews() {89return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews;90}9192@Override93void copyNonPosixAttributes(int ofd, int nfd) {94SolarisUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd);95// TDB: copy ACL from source to target96}9798/**99* Returns object to iterate over entries in /etc/mnttab100*/101@Override102Iterable<UnixMountEntry> getMountEntries() {103ArrayList<UnixMountEntry> entries = new ArrayList<>();104try {105UnixPath mnttab = new UnixPath(this, "/etc/mnttab");106long fp = fopen(mnttab, "r");107try {108for (;;) {109UnixMountEntry entry = new UnixMountEntry();110int res = getextmntent(fp, entry);111if (res < 0)112break;113entries.add(entry);114}115} finally {116fclose(fp);117}118} catch (UnixException x) {119// nothing we can do120}121return entries;122}123124@Override125FileStore getFileStore(UnixMountEntry entry) throws IOException {126return new SolarisFileStore(this, entry);127}128}129130131