Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/LinuxFileSystem.java
32288 views
/*1* Copyright (c) 2008, 2019, 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 static sun.nio.fs.LinuxNativeDispatcher.*;3132/**33* Linux implementation of FileSystem34*/3536class LinuxFileSystem extends UnixFileSystem {37LinuxFileSystem(UnixFileSystemProvider provider, String dir) {38super(provider, dir);39}4041@Override42public WatchService newWatchService()43throws IOException44{45// assume 2.6.13 or newer46return new LinuxWatchService(this);47}484950// lazy initialization of the list of supported attribute views51private static class SupportedFileFileAttributeViewsHolder {52static final Set<String> supportedFileAttributeViews =53supportedFileAttributeViews();54private static Set<String> supportedFileAttributeViews() {55Set<String> result = new HashSet<>();56result.addAll(standardFileAttributeViews());57// additional Linux-specific views58result.add("dos");59result.add("user");60return Collections.unmodifiableSet(result);61}62}6364@Override65public Set<String> supportedFileAttributeViews() {66return SupportedFileFileAttributeViewsHolder.supportedFileAttributeViews;67}6869@Override70void copyNonPosixAttributes(int ofd, int nfd) {71LinuxUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd);72}7374/**75* Returns object to iterate over the mount entries in the given fstab file.76*/77List<UnixMountEntry> getMountEntries(String fstab) {78ArrayList<UnixMountEntry> entries = new ArrayList<>();79try {80long fp = setmntent(Util.toBytes(fstab), Util.toBytes("r"));81int maxLineSize = 1024;82try {83for (;;) {84int lineSize = getlinelen(fp);85if (lineSize == -1)86break;87if (lineSize > maxLineSize)88maxLineSize = lineSize;89}90} catch (UnixException x) {91// nothing we need to do92} finally {93rewind(fp);94}9596try {97for (;;) {98UnixMountEntry entry = new UnixMountEntry();99// count in NUL character at the end100int res = getmntent(fp, entry, maxLineSize + 1);101if (res < 0)102break;103entries.add(entry);104}105} finally {106endmntent(fp);107}108109} catch (UnixException x) {110// nothing we can do111}112return entries;113}114115/**116* Returns object to iterate over the mount entries in /etc/mtab117*/118@Override119List<UnixMountEntry> getMountEntries() {120return getMountEntries("/etc/mtab");121}122123124125@Override126FileStore getFileStore(UnixMountEntry entry) throws IOException {127return new LinuxFileStore(this, entry);128}129}130131132