1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 package com.sshtools.daemon.platform;
27
28 import com.sshtools.daemon.configuration;
29
30 import com.sshtools.j2ssh.configuration;
31 import com.sshtools.j2ssh.io;
32 import com.sshtools.j2ssh.sftp;
33
34 import org.apache.commons.logging;
35
36 import java.io;
37
38
39 /**
40 *
41 *
42 * @author $author$
43 * @version $Revision: 1.13 $
44 */
45 public abstract class NativeFileSystemProvider {
46 private static Log log = LogFactory.getLog(NativeAuthenticationProvider.class);
47 private static NativeFileSystemProvider instance;
48
49 /** */
50 public static final int OPEN_READ = SftpSubsystemClient.OPEN_READ;
51
52 /** */
53 public static final int OPEN_WRITE = SftpSubsystemClient.OPEN_WRITE;
54
55 /** */
56 public static final int OPEN_APPEND = SftpSubsystemClient.OPEN_APPEND;
57
58 /** */
59 public static final int OPEN_CREATE = SftpSubsystemClient.OPEN_CREATE;
60
61 /** */
62 public static final int OPEN_TRUNCATE = SftpSubsystemClient.OPEN_TRUNCATE;
63
64 /** */
65 public static final int OPEN_EXCLUSIVE = SftpSubsystemClient.OPEN_EXCLUSIVE;
66
67 static {
68 try {
69 if (ConfigurationLoader.isConfigurationAvailable(
70 PlatformConfiguration.class)) {
71 Class cls = ConfigurationLoader.getExtensionClass(((PlatformConfiguration) ConfigurationLoader.getConfiguration(
72 PlatformConfiguration.class)).getNativeFileSystemProvider());
73 instance = (NativeFileSystemProvider) cls.newInstance();
74 }
75 } catch (Exception e) {
76 log.error("Failed to load native file system provider", e);
77 instance = null;
78 }
79 }
80
81 /**
82 *
83 *
84 * @param path
85 *
86 * @return
87 *
88 * @throws PermissionDeniedException
89 * @throws FileNotFoundException
90 * @throws IOException
91 */
92 public abstract boolean fileExists(String path) throws IOException;
93
94 /**
95 *
96 *
97 * @param path
98 *
99 * @return
100 *
101 * @throws PermissionDeniedException
102 * @throws FileNotFoundException
103 * @throws IOException
104 */
105 public abstract String getCanonicalPath(String path)
106 throws IOException, FileNotFoundException;
107
108 /**
109 *
110 *
111 * @param path
112 *
113 * @return
114 *
115 * @throws FileNotFoundException
116 */
117 public abstract String getRealPath(String path)
118 throws FileNotFoundException;
119
120 /**
121 *
122 *
123 * @param path
124 *
125 * @return
126 *
127 * @throws PermissionDeniedException
128 * @throws FileNotFoundException
129 * @throws IOException
130 */
131 public abstract boolean makeDirectory(String path)
132 throws PermissionDeniedException, FileNotFoundException, IOException;
133
134 /**
135 *
136 *
137 * @param path
138 *
139 * @return
140 *
141 * @throws IOException
142 * @throws FileNotFoundException
143 */
144 public abstract FileAttributes getFileAttributes(String path)
145 throws IOException, FileNotFoundException;
146
147 /**
148 *
149 *
150 * @param handle
151 *
152 * @return
153 *
154 * @throws IOException
155 * @throws InvalidHandleException
156 */
157 public abstract FileAttributes getFileAttributes(byte[] handle)
158 throws IOException, InvalidHandleException;
159
160 /**
161 *
162 *
163 * @param path
164 *
165 * @return
166 *
167 * @throws PermissionDeniedException
168 * @throws FileNotFoundException
169 * @throws IOException
170 */
171 public abstract byte[] openDirectory(String path)
172 throws PermissionDeniedException, FileNotFoundException, IOException;
173
174 /**
175 *
176 *
177 * @param handle
178 *
179 * @return
180 *
181 * @throws InvalidHandleException
182 * @throws EOFException
183 */
184 public abstract SftpFile[] readDirectory(byte[] handle)
185 throws InvalidHandleException, EOFException, IOException;
186
187 /**
188 *
189 *
190 * @param path
191 * @param flags
192 * @param attrs
193 *
194 * @return
195 *
196 * @throws PermissionDeniedException
197 * @throws FileNotFoundException
198 * @throws IOException
199 */
200 public abstract byte[] openFile(String path, UnsignedInteger32 flags,
201 FileAttributes attrs)
202 throws PermissionDeniedException, FileNotFoundException, IOException;
203
204 /**
205 *
206 *
207 * @param handle
208 * @param offset
209 * @param len
210 *
211 * @return
212 *
213 * @throws InvalidHandleException
214 * @throws EOFException
215 * @throws IOException
216 */
217 public abstract byte[] readFile(byte[] handle, UnsignedInteger64 offset,
218 UnsignedInteger32 len)
219 throws InvalidHandleException, EOFException, IOException;
220
221 /**
222 *
223 *
224 * @param handle
225 * @param offset
226 * @param data
227 * @param off
228 * @param len
229 *
230 * @throws InvalidHandleException
231 * @throws IOException
232 */
233 public abstract void writeFile(byte[] handle, UnsignedInteger64 offset,
234 byte[] data, int off, int len)
235 throws InvalidHandleException, IOException;
236
237 /**
238 *
239 *
240 * @param handle
241 *
242 * @throws InvalidHandleException
243 * @throws IOException
244 */
245 public abstract void closeFile(byte[] handle)
246 throws InvalidHandleException, IOException;
247
248 /**
249 *
250 *
251 * @param path
252 *
253 * @throws PermissionDeniedException
254 * @throws IOException
255 * @throws FileNotFoundException
256 */
257 public abstract void removeFile(String path)
258 throws PermissionDeniedException, IOException, FileNotFoundException;
259
260 /**
261 *
262 *
263 * @param oldpath
264 * @param newpath
265 *
266 * @throws PermissionDeniedException
267 * @throws FileNotFoundException
268 * @throws IOException
269 */
270 public abstract void renameFile(String oldpath, String newpath)
271 throws PermissionDeniedException, FileNotFoundException, IOException;
272
273 /**
274 *
275 *
276 * @param path
277 *
278 * @throws PermissionDeniedException
279 * @throws FileNotFoundException
280 * @throws IOException
281 */
282 public abstract void removeDirectory(String path)
283 throws PermissionDeniedException, FileNotFoundException, IOException;
284
285 /**
286 *
287 *
288 * @param path
289 * @param attrs
290 *
291 * @throws PermissionDeniedException
292 * @throws IOException
293 * @throws FileNotFoundException
294 */
295 public abstract void setFileAttributes(String path, FileAttributes attrs)
296 throws PermissionDeniedException, IOException, FileNotFoundException;
297
298 /**
299 *
300 *
301 * @param handle
302 * @param attrs
303 *
304 * @throws PermissionDeniedException
305 * @throws IOException
306 * @throws InvalidHandleException
307 */
308 public abstract void setFileAttributes(byte[] handle, FileAttributes attrs)
309 throws PermissionDeniedException, IOException, InvalidHandleException;
310
311 /**
312 *
313 *
314 * @param path
315 *
316 * @return
317 *
318 * @throws UnsupportedFileOperationException
319 * @throws FileNotFoundException
320 * @throws IOException
321 * @throws PermissionDeniedException
322 */
323 public abstract SftpFile readSymbolicLink(String path)
324 throws UnsupportedFileOperationException, FileNotFoundException,
325 IOException, PermissionDeniedException;
326
327 /**
328 *
329 *
330 * @param link
331 * @param target
332 *
333 * @throws UnsupportedFileOperationException
334 * @throws FileNotFoundException
335 * @throws IOException
336 * @throws PermissionDeniedException
337 */
338 public abstract void createSymbolicLink(String link, String target)
339 throws UnsupportedFileOperationException, FileNotFoundException,
340 IOException, PermissionDeniedException;
341
342 public abstract String getDefaultPath(String username)
343 throws FileNotFoundException;
344
345 /**
346 *
347 *
348 * @param username
349 * @param path
350 * @param permissions
351 *
352 * @throws PermissionDeniedException
353 * @throws FileNotFoundException
354 * @throws IOException
355 */
356 public abstract void verifyPermissions(String username, String path,
357 String permissions)
358 throws PermissionDeniedException, FileNotFoundException, IOException;
359
360 /**
361 *
362 *
363 * @return
364 */
365 public static NativeFileSystemProvider getInstance() {
366 return instance;
367 }
368 }