Path: blob/master/src/java.base/macosx/classes/sun/nio/fs/BsdFileSystem.java
41137 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;3233/**34* Bsd implementation of FileSystem35*/3637class BsdFileSystem extends UnixFileSystem {3839BsdFileSystem(UnixFileSystemProvider provider, String dir) {40super(provider, dir);41}4243@Override44public WatchService newWatchService()45throws IOException46{47// use polling implementation until we implement a BSD/kqueue one48return new PollingWatchService();49}5051// lazy initialization of the list of supported attribute views52private static class SupportedFileFileAttributeViewsHolder {53static final Set<String> supportedFileAttributeViews =54supportedFileAttributeViews();55private static Set<String> supportedFileAttributeViews() {56Set<String> result = new HashSet<String>();57result.addAll(standardFileAttributeViews());58// additional BSD-specific views59result.add("user");60return Collections.unmodifiableSet(result);61}62}6364@Override65public Set<String> supportedFileAttributeViews() {66return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews;67}6869@Override70void copyNonPosixAttributes(int ofd, int nfd) {71UnixUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd);72}7374/**75* Returns object to iterate over mount entries76*/77@Override78Iterable<UnixMountEntry> getMountEntries() {79ArrayList<UnixMountEntry> entries = new ArrayList<UnixMountEntry>();80try {81long iter = BsdNativeDispatcher.getfsstat();82try {83for (;;) {84UnixMountEntry entry = new UnixMountEntry();85int res = BsdNativeDispatcher.fsstatEntry(iter, entry);86if (res < 0)87break;88entries.add(entry);89}90} finally {91BsdNativeDispatcher.endfsstat(iter);92}9394} catch (UnixException x) {95// nothing we can do96}97return entries;98}99100101102@Override103FileStore getFileStore(UnixMountEntry entry) throws IOException {104return new BsdFileStore(this, entry);105}106}107108109