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

Print this page
rev 9260 : imported patch io-events-path


 132                     null, "Unable to get size of extended attribute '" + name +
 133                     "': " + x.getMessage());
 134             }
 135         } finally {
 136             close(fd);
 137         }
 138     }
 139 
 140     @Override
 141     public int read(String name, ByteBuffer dst) throws IOException {
 142         if (System.getSecurityManager() != null)
 143             checkAccess(file.getPathForPermissionCheck(), true, false);
 144 
 145         int fd = file.openForAttributeAccess(followLinks);
 146         try {
 147             try {
 148                 // open attribute file
 149                 int afd = openat(fd, nameAsBytes(file,name), (O_RDONLY|O_XATTR), 0);
 150 
 151                 // wrap with channel
 152                 FileChannel fc = UnixChannelFactory.newFileChannel(afd, true, false);
 153 
 154                 // read to EOF (nothing we can do if I/O error occurs)
 155                 try {
 156                     if (fc.size() > dst.remaining())
 157                         throw new IOException("Extended attribute file too large");
 158                     int total = 0;
 159                     while (dst.hasRemaining()) {
 160                         int n = fc.read(dst);
 161                         if (n < 0)
 162                             break;
 163                         total += n;
 164                     }
 165                     return total;
 166                 } finally {
 167                     fc.close();
 168                 }
 169             } catch (UnixException x) {
 170                 throw new FileSystemException(file.getPathForExceptionMessage(),
 171                     null, "Unable to read extended attribute '" + name +
 172                     "': " + x.getMessage());
 173             }
 174         } finally {
 175             close(fd);
 176         }
 177     }
 178 
 179     @Override
 180     public int write(String name, ByteBuffer src) throws IOException {
 181         if (System.getSecurityManager() != null)
 182             checkAccess(file.getPathForPermissionCheck(), false, true);
 183 
 184         int fd = file.openForAttributeAccess(followLinks);
 185         try {
 186             try {
 187                 // open/create attribute file
 188                 int afd = openat(fd, nameAsBytes(file,name),
 189                                  (O_CREAT|O_WRONLY|O_TRUNC|O_XATTR),
 190                                  UnixFileModeAttribute.ALL_PERMISSIONS);
 191 
 192                 // wrap with channel
 193                 FileChannel fc = UnixChannelFactory.newFileChannel(afd, false, true);
 194 
 195                 // write value (nothing we can do if I/O error occurs)
 196                 try {
 197                     int rem = src.remaining();
 198                     while (src.hasRemaining()) {
 199                         fc.write(src);
 200                     }
 201                     return rem;
 202                 } finally {
 203                     fc.close();
 204                 }
 205             } catch (UnixException x) {
 206                 throw new FileSystemException(file.getPathForExceptionMessage(),
 207                     null, "Unable to write extended attribute '" + name +
 208                     "': " + x.getMessage());
 209             }
 210         } finally {
 211             close(fd);
 212         }
 213     }




 132                     null, "Unable to get size of extended attribute '" + name +
 133                     "': " + x.getMessage());
 134             }
 135         } finally {
 136             close(fd);
 137         }
 138     }
 139 
 140     @Override
 141     public int read(String name, ByteBuffer dst) throws IOException {
 142         if (System.getSecurityManager() != null)
 143             checkAccess(file.getPathForPermissionCheck(), true, false);
 144 
 145         int fd = file.openForAttributeAccess(followLinks);
 146         try {
 147             try {
 148                 // open attribute file
 149                 int afd = openat(fd, nameAsBytes(file,name), (O_RDONLY|O_XATTR), 0);
 150 
 151                 // wrap with channel
 152                 FileChannel fc = UnixChannelFactory.newFileChannel(afd, file.toString(), true, false);
 153 
 154                 // read to EOF (nothing we can do if I/O error occurs)
 155                 try {
 156                     if (fc.size() > dst.remaining())
 157                         throw new IOException("Extended attribute file too large");
 158                     int total = 0;
 159                     while (dst.hasRemaining()) {
 160                         int n = fc.read(dst);
 161                         if (n < 0)
 162                             break;
 163                         total += n;
 164                     }
 165                     return total;
 166                 } finally {
 167                     fc.close();
 168                 }
 169             } catch (UnixException x) {
 170                 throw new FileSystemException(file.getPathForExceptionMessage(),
 171                     null, "Unable to read extended attribute '" + name +
 172                     "': " + x.getMessage());
 173             }
 174         } finally {
 175             close(fd);
 176         }
 177     }
 178 
 179     @Override
 180     public int write(String name, ByteBuffer src) throws IOException {
 181         if (System.getSecurityManager() != null)
 182             checkAccess(file.getPathForPermissionCheck(), false, true);
 183 
 184         int fd = file.openForAttributeAccess(followLinks);
 185         try {
 186             try {
 187                 // open/create attribute file
 188                 int afd = openat(fd, nameAsBytes(file,name),
 189                                  (O_CREAT|O_WRONLY|O_TRUNC|O_XATTR),
 190                                  UnixFileModeAttribute.ALL_PERMISSIONS);
 191 
 192                 // wrap with channel
 193                 FileChannel fc = UnixChannelFactory.newFileChannel(afd, file.toString(), false, true);
 194 
 195                 // write value (nothing we can do if I/O error occurs)
 196                 try {
 197                     int rem = src.remaining();
 198                     while (src.hasRemaining()) {
 199                         fc.write(src);
 200                     }
 201                     return rem;
 202                 } finally {
 203                     fc.close();
 204                 }
 205             } catch (UnixException x) {
 206                 throw new FileSystemException(file.getPathForExceptionMessage(),
 207                     null, "Unable to write extended attribute '" + name +
 208                     "': " + x.getMessage());
 209             }
 210         } finally {
 211             close(fd);
 212         }
 213     }