src/java.base/linux/classes/sun/nio/fs/LinuxFileStore.java
author bpb
Mon, 16 Jul 2018 10:58:28 -0700
changeset 51125 b6b9a2515525
parent 49586 09905cd87bb2
permissions -rw-r--r--
8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx) Summary: Assume extended attributes are only explicitly enable on ext3 Reviewed-by: mbaesken, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     1
/*
48460
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
     2
 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     4
 *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3721
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3721
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    10
 *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    15
 * accompanied this code).
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    16
 *
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3721
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3721
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3721
diff changeset
    23
 * questions.
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    24
 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    25
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    26
package sun.nio.fs;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    27
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    28
import java.io.IOException;
51125
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    29
import java.nio.file.attribute.DosFileAttributeView;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    30
import java.nio.file.attribute.FileAttributeView;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    31
import java.nio.file.attribute.PosixFileAttributeView;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    32
import java.nio.file.attribute.UserDefinedFileAttributeView;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    33
import java.util.Arrays;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    34
import java.util.List;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
    35
import java.util.regex.Pattern;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    36
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    37
/**
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    38
 * Linux implementation of FileStore
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    39
 */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    40
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    41
class LinuxFileStore
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    42
    extends UnixFileStore
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    43
{
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    44
    // used when checking if extended attributes are enabled or not
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    45
    private volatile boolean xattrChecked;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    46
    private volatile boolean xattrEnabled;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    47
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    48
    LinuxFileStore(UnixPath file) throws IOException {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    49
        super(file);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    50
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    51
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    52
    LinuxFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    53
        super(fs, entry);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    54
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    55
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    56
    /**
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    57
     * Finds, and returns, the mount entry for the file system where the file
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    58
     * resides.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    59
     */
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    60
    @Override
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    61
    UnixMountEntry findMountEntry() throws IOException {
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
    62
        LinuxFileSystem fs = (LinuxFileSystem)file().getFileSystem();
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    63
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    64
        // step 1: get realpath
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    65
        UnixPath path = null;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    66
        try {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    67
            byte[] rp = UnixNativeDispatcher.realpath(file());
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    68
            path = new UnixPath(fs, rp);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    69
        } catch (UnixException x) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    70
            x.rethrowAsIOException(file());
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    71
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    72
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    73
        // step 2: find mount point
48460
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    74
        List<UnixMountEntry> procMountsEntries =
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    75
            fs.getMountEntries("/proc/mounts");
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    76
        UnixPath parent = path.getParent();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    77
        while (parent != null) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    78
            UnixFileAttributes attrs = null;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    79
            try {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    80
                attrs = UnixFileAttributes.get(parent, true);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    81
            } catch (UnixException x) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    82
                x.rethrowAsIOException(parent);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    83
            }
48460
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    84
            if (attrs.dev() != dev()) {
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    85
                // step 3: lookup mounted file systems (use /proc/mounts to
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    86
                // ensure we find the file system even when not in /etc/mtab)
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    87
                byte[] dir = path.asByteArray();
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    88
                for (UnixMountEntry entry : procMountsEntries) {
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    89
                    if (Arrays.equals(dir, entry.dir()))
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    90
                        return entry;
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    91
                }
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    92
            }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    93
            path = parent;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    94
            parent = parent.getParent();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    95
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    96
48460
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    97
        // step 3: lookup mounted file systems (use /proc/mounts to
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
    98
        // ensure we find the file system even when not in /etc/mtab)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
    99
        byte[] dir = path.asByteArray();
48460
bdbbf56c302e 8165852: (fs) Mount point not found for a file which is present in overlayfs
bpb
parents: 47216
diff changeset
   100
        for (UnixMountEntry entry : procMountsEntries) {
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   101
            if (Arrays.equals(dir, entry.dir()))
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   102
                return entry;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   103
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   104
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   105
        throw new IOException("Mount point not found");
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   106
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   107
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   108
    // returns true if extended attributes enabled on file system where given
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   109
    // file resides, returns false if disabled or unable to determine.
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   110
    private boolean isExtendedAttributesEnabled(UnixPath path) {
34537
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   111
        int fd = -1;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   112
        try {
34537
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   113
            fd = path.openForAttributeAccess(false);
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   114
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   115
            // fgetxattr returns size if called with size==0
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   116
            byte[] name = Util.toBytes("user.java");
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   117
            LinuxNativeDispatcher.fgetxattr(fd, name, 0L, 0);
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   118
            return true;
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   119
        } catch (UnixException e) {
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   120
            // attribute does not exist
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   121
            if (e.errno() == UnixConstants.ENODATA)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   122
                return true;
34537
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   123
        } finally {
ca5ca0e04c96 8139133: Changing the modification time on a unix domain socket file fails
bpb
parents: 25859
diff changeset
   124
            UnixNativeDispatcher.close(fd);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   125
        }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   126
        return false;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   127
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   128
51125
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   129
    // get kernel version as a three element array {major, minor, micro}
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   130
    private static int[] getKernelVersion() {
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   131
        Pattern pattern = Pattern.compile("\\D+");
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   132
        String[] matches = pattern.split(System.getProperty("os.version"));
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   133
        int[] majorMinorMicro = new int[3];
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   134
        int length = Math.min(matches.length, majorMinorMicro.length);
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   135
        for (int i = 0; i < length; i++) {
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   136
            majorMinorMicro[i] = Integer.valueOf(matches[i]);
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   137
        }
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   138
        return majorMinorMicro;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   139
    }
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   140
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   141
    @Override
3721
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   142
    public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
3065
452aaa2899fc 6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents: 2057
diff changeset
   143
        // support DosFileAttributeView and UserDefinedAttributeView if extended
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   144
        // attributes enabled
3721
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   145
        if (type == DosFileAttributeView.class ||
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   146
            type == UserDefinedFileAttributeView.class)
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   147
        {
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   148
            // lookup fstypes.properties
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   149
            FeatureStatus status = checkIfFeaturePresent("user_xattr");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   150
            if (status == FeatureStatus.PRESENT)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   151
                return true;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   152
            if (status == FeatureStatus.NOT_PRESENT)
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   153
                return false;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   154
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   155
            // if file system is mounted with user_xattr option then assume
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   156
            // extended attributes are enabled
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   157
            if ((entry().hasOption("user_xattr")))
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   158
                return true;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   159
51125
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   160
            // check for explicit disabling of extended attributes
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   161
            if (entry().hasOption("nouser_xattr")) {
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   162
                return false;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   163
            }
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   164
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   165
            // user_{no}xattr options not present but we special-case ext3 as
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   166
            // we know that extended attributes are not enabled by default.
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   167
            if (entry().fstype().equals("ext3")) {
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   168
                return false;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   169
            }
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   170
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   171
            // user_xattr option not present but we special-case ext4 as we
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   172
            // know that extended attributes are enabled by default for
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   173
            // kernel version >= 2.6.39
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   174
            if (entry().fstype().equals("ext4")) {
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   175
                if (!xattrChecked) {
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   176
                    // check kernel version
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   177
                    int[] kernelVersion = getKernelVersion();
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   178
                    xattrEnabled = kernelVersion[0] > 2 ||
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   179
                        (kernelVersion[0] == 2 && kernelVersion[1] > 6) ||
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   180
                        (kernelVersion[0] == 2 && kernelVersion[1] == 6 &&
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   181
                            kernelVersion[2] >= 39);
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   182
                    xattrChecked = true;
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   183
                }
b6b9a2515525 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
bpb
parents: 49586
diff changeset
   184
                return xattrEnabled;
49586
09905cd87bb2 8009632: (fs) FileStore.supportsFileAttributeView does not detect user_xattr enabled on ext4
bpb
parents: 48460
diff changeset
   185
            }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   186
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   187
            // not ext3/4 so probe mount point
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   188
            if (!xattrChecked) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   189
                UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   190
                xattrEnabled = isExtendedAttributesEnabled(dir);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   191
                xattrChecked = true;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   192
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   193
            return xattrEnabled;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   194
        }
14011
3d24d5dcf602 6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents: 7668
diff changeset
   195
        // POSIX attributes not supported on FAT
3d24d5dcf602 6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents: 7668
diff changeset
   196
        if (type == PosixFileAttributeView.class && entry().fstype().equals("vfat"))
3d24d5dcf602 6950237: Test java/nio/file/Path/CopyAndMove.java does not work correctly when test dir in on VFAT
dxu
parents: 7668
diff changeset
   197
            return false;
3721
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   198
        return super.supportsFileAttributeView(type);
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   199
    }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   200
3721
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   201
    @Override
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   202
    public boolean supportsFileAttributeView(String name) {
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   203
        if (name.equals("dos"))
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   204
            return supportsFileAttributeView(DosFileAttributeView.class);
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   205
        if (name.equals("user"))
1adb60cc9f39 6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents: 3065
diff changeset
   206
            return supportsFileAttributeView(UserDefinedFileAttributeView.class);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   207
        return super.supportsFileAttributeView(name);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   208
    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff changeset
   209
}