src/solaris/classes/sun/nio/fs/LinuxDosFileAttributeView.java

Print this page




  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.attribute.*;
  29 import java.util.Map;

  30 import java.io.IOException;
  31 import sun.misc.Unsafe;
  32 
  33 import static sun.nio.fs.UnixNativeDispatcher.*;
  34 import static sun.nio.fs.UnixConstants.*;
  35 
  36 /**
  37  * Linux implementation of DosFileAttributeView for use on file systems such
  38  * as ext3 that have extended attributes enabled and SAMBA configured to store
  39  * DOS attributes.
  40  */
  41 
  42 class LinuxDosFileAttributeView
  43     extends UnixFileAttributeViews.Basic implements DosFileAttributeView
  44 {
  45     private static final Unsafe unsafe = Unsafe.getUnsafe();
  46 
  47     private static final String READONLY_NAME = "readonly";
  48     private static final String ARCHIVE_NAME = "archive";
  49     private static final String SYSTEM_NAME = "system";
  50     private static final String HIDDEN_NAME = "hidden";
  51 
  52     private static final String DOS_XATTR_NAME = "user.DOSATTRIB";
  53     private static final byte[] DOS_XATTR_NAME_AS_BYTES = DOS_XATTR_NAME.getBytes();
  54 
  55     private static final int DOS_XATTR_READONLY = 0x01;
  56     private static final int DOS_XATTR_HIDDEN   = 0x02;
  57     private static final int DOS_XATTR_SYSTEM   = 0x04;
  58     private static final int DOS_XATTR_ARCHIVE  = 0x20;
  59 




  60     LinuxDosFileAttributeView(UnixPath file, boolean followLinks) {
  61         super(file, followLinks);
  62     }
  63 
  64     @Override
  65     public String name() {
  66         return "dos";
  67     }
  68 
  69     @Override
  70     public void setAttribute(String attribute, Object value)
  71         throws IOException
  72     {
  73         if (attribute.equals(READONLY_NAME)) {
  74             setReadOnly((Boolean)value);
  75             return;
  76         }
  77         if (attribute.equals(ARCHIVE_NAME)) {
  78             setArchive((Boolean)value);
  79             return;
  80         }
  81         if (attribute.equals(SYSTEM_NAME)) {
  82             setSystem((Boolean)value);
  83             return;
  84         }
  85         if (attribute.equals(HIDDEN_NAME)) {
  86             setHidden((Boolean)value);
  87             return;
  88         }
  89         super.setAttribute(attribute, value);
  90     }
  91 
  92     @Override
  93     public Map<String,Object> readAttributes(String[] attributes)
  94         throws IOException
  95     {
  96         AttributesBuilder builder = AttributesBuilder.create(attributes);

  97         DosFileAttributes attrs = readAttributes();
  98         addBasicAttributesToBuilder(attrs, builder);
  99         if (builder.match(READONLY_NAME))
 100             builder.add(READONLY_NAME, attrs.isReadOnly());
 101         if (builder.match(ARCHIVE_NAME))
 102             builder.add(ARCHIVE_NAME, attrs.isArchive());
 103         if (builder.match(SYSTEM_NAME))
 104             builder.add(SYSTEM_NAME, attrs.isSystem());
 105         if (builder.match(HIDDEN_NAME))
 106             builder.add(HIDDEN_NAME, attrs.isHidden());
 107         return builder.unmodifiableMap();
 108     }
 109 
 110     @Override
 111     public DosFileAttributes readAttributes() throws IOException {
 112         file.checkRead();
 113 
 114         int fd = file.openForAttributeAccess(followLinks);
 115         try {
 116              final UnixFileAttributes attrs = UnixFileAttributes.get(fd);
 117              final int dosAttribute = getDosAttribute(fd);
 118 




  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.attribute.*;
  29 import java.util.Map;
  30 import java.util.Set;
  31 import java.io.IOException;
  32 import sun.misc.Unsafe;
  33 
  34 import static sun.nio.fs.UnixNativeDispatcher.*;
  35 import static sun.nio.fs.UnixConstants.*;
  36 
  37 /**
  38  * Linux implementation of DosFileAttributeView for use on file systems such
  39  * as ext3 that have extended attributes enabled and SAMBA configured to store
  40  * DOS attributes.
  41  */
  42 
  43 class LinuxDosFileAttributeView
  44     extends UnixFileAttributeViews.Basic implements DosFileAttributeView
  45 {
  46     private static final Unsafe unsafe = Unsafe.getUnsafe();
  47 
  48     private static final String READONLY_NAME = "readonly";
  49     private static final String ARCHIVE_NAME = "archive";
  50     private static final String SYSTEM_NAME = "system";
  51     private static final String HIDDEN_NAME = "hidden";
  52 
  53     private static final String DOS_XATTR_NAME = "user.DOSATTRIB";
  54     private static final byte[] DOS_XATTR_NAME_AS_BYTES = DOS_XATTR_NAME.getBytes();
  55 
  56     private static final int DOS_XATTR_READONLY = 0x01;
  57     private static final int DOS_XATTR_HIDDEN   = 0x02;
  58     private static final int DOS_XATTR_SYSTEM   = 0x04;
  59     private static final int DOS_XATTR_ARCHIVE  = 0x20;
  60     
  61     // the names of the DOS attributes (includes basic)
  62     private static final Set<String> dosAttributeNames = 
  63         Util.newSet(basicAttributeNames, READONLY_NAME, ARCHIVE_NAME, SYSTEM_NAME, HIDDEN_NAME);
  64 
  65     LinuxDosFileAttributeView(UnixPath file, boolean followLinks) {
  66         super(file, followLinks);
  67     }
  68 
  69     @Override
  70     public String name() {
  71         return "dos";
  72     }
  73 
  74     @Override
  75     public void setAttribute(String attribute, Object value)
  76         throws IOException
  77     {
  78         if (attribute.equals(READONLY_NAME)) {
  79             setReadOnly((Boolean)value);
  80             return;
  81         }
  82         if (attribute.equals(ARCHIVE_NAME)) {
  83             setArchive((Boolean)value);
  84             return;
  85         }
  86         if (attribute.equals(SYSTEM_NAME)) {
  87             setSystem((Boolean)value);
  88             return;
  89         }
  90         if (attribute.equals(HIDDEN_NAME)) {
  91             setHidden((Boolean)value);
  92             return;
  93         }
  94         super.setAttribute(attribute, value);
  95     }
  96 
  97     @Override
  98     public Map<String,Object> readAttributes(String[] attributes)
  99         throws IOException
 100     {
 101         AttributesBuilder builder = 
 102             AttributesBuilder.create(dosAttributeNames, attributes);
 103         DosFileAttributes attrs = readAttributes();
 104         addRequestedBasicAttributes(attrs, builder);
 105         if (builder.match(READONLY_NAME))
 106             builder.add(READONLY_NAME, attrs.isReadOnly());
 107         if (builder.match(ARCHIVE_NAME))
 108             builder.add(ARCHIVE_NAME, attrs.isArchive());
 109         if (builder.match(SYSTEM_NAME))
 110             builder.add(SYSTEM_NAME, attrs.isSystem());
 111         if (builder.match(HIDDEN_NAME))
 112             builder.add(HIDDEN_NAME, attrs.isHidden());
 113         return builder.unmodifiableMap();
 114     }
 115 
 116     @Override
 117     public DosFileAttributes readAttributes() throws IOException {
 118         file.checkRead();
 119 
 120         int fd = file.openForAttributeAccess(followLinks);
 121         try {
 122              final UnixFileAttributes attrs = UnixFileAttributes.get(fd);
 123              final int dosAttribute = getDosAttribute(fd);
 124