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