comparison src/com/trilead/ssh2/sftp/OpenFlags.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1
2 package com.trilead.ssh2.sftp;
3
4 /**
5 *
6 * SFTP Open Flags.
7 *
8 * The following table is provided to assist in mapping POSIX semantics
9 * to equivalent SFTP file open parameters:
10 * <p>
11 * TODO: This comment should be moved to the open method.
12 * <p>
13 * <ul>
14 * <li>O_RDONLY
15 * <ul><li>desired-access = READ_DATA | READ_ATTRIBUTES</li></ul>
16 * </li>
17 * </ul>
18 * <ul>
19 * <li>O_WRONLY
20 * <ul><li>desired-access = WRITE_DATA | WRITE_ATTRIBUTES</li></ul>
21 * </li>
22 * </ul>
23 * <ul>
24 * <li>O_RDWR
25 * <ul><li>desired-access = READ_DATA | READ_ATTRIBUTES | WRITE_DATA | WRITE_ATTRIBUTES</li></ul>
26 * </li>
27 * </ul>
28 * <ul>
29 * <li>O_APPEND
30 * <ul>
31 * <li>desired-access = WRITE_DATA | WRITE_ATTRIBUTES | APPEND_DATA</li>
32 * <li>flags = SSH_FXF_ACCESS_APPEND_DATA and or SSH_FXF_ACCESS_APPEND_DATA_ATOMIC</li>
33 * </ul>
34 * </li>
35 * </ul>
36 * <ul>
37 * <li>O_CREAT
38 * <ul>
39 * <li>flags = SSH_FXF_OPEN_OR_CREATE</li>
40 * </ul>
41 * </li>
42 * </ul>
43 * <ul>
44 * <li>O_TRUNC
45 * <ul>
46 * <li>flags = SSH_FXF_TRUNCATE_EXISTING</li>
47 * </ul>
48 * </li>
49 * </ul>
50 * <ul>
51 * <li>O_TRUNC|O_CREATE
52 * <ul>
53 * <li>flags = SSH_FXF_CREATE_TRUNCATE</li>
54 * </ul>
55 * </li>
56 * </ul>
57 *
58 * @author Christian Plattner, plattner@trilead.com
59 * @version $Id: OpenFlags.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
60 */
61 public class OpenFlags {
62 /**
63 * Disposition is a 3 bit field that controls how the file is opened.
64 * The server MUST support these bits (possible enumaration values:
65 * SSH_FXF_CREATE_NEW, SSH_FXF_CREATE_TRUNCATE, SSH_FXF_OPEN_EXISTING,
66 * SSH_FXF_OPEN_OR_CREATE or SSH_FXF_TRUNCATE_EXISTING).
67 */
68 public static final int SSH_FXF_ACCESS_DISPOSITION = 0x00000007;
69
70 /**
71 * A new file is created; if the file already exists, the server
72 * MUST return status SSH_FX_FILE_ALREADY_EXISTS.
73 */
74 public static final int SSH_FXF_CREATE_NEW = 0x00000000;
75
76 /**
77 * A new file is created; if the file already exists, it is opened
78 * and truncated.
79 */
80 public static final int SSH_FXF_CREATE_TRUNCATE = 0x00000001;
81
82 /**
83 * An existing file is opened. If the file does not exist, the
84 * server MUST return SSH_FX_NO_SUCH_FILE. If a directory in the
85 * path does not exist, the server SHOULD return
86 * SSH_FX_NO_SUCH_PATH. It is also acceptable if the server
87 * returns SSH_FX_NO_SUCH_FILE in this case.
88 */
89 public static final int SSH_FXF_OPEN_EXISTING = 0x00000002;
90
91 /**
92 * If the file exists, it is opened. If the file does not exist,
93 * it is created.
94 */
95 public static final int SSH_FXF_OPEN_OR_CREATE = 0x00000003;
96
97 /**
98 * An existing file is opened and truncated. If the file does not
99 * exist, the server MUST return the same error codes as defined
100 * for SSH_FXF_OPEN_EXISTING.
101 */
102 public static final int SSH_FXF_TRUNCATE_EXISTING = 0x00000004;
103
104 /**
105 * Data is always written at the end of the file. The offset field
106 * of the SSH_FXP_WRITE requests are ignored.
107 * <p>
108 * Data is not required to be appended atomically. This means that
109 * if multiple writers attempt to append data simultaneously, data
110 * from the first may be lost. However, data MAY be appended
111 * atomically.
112 */
113 public static final int SSH_FXF_ACCESS_APPEND_DATA = 0x00000008;
114
115 /**
116 * Data is always written at the end of the file. The offset field
117 * of the SSH_FXP_WRITE requests are ignored.
118 * <p>
119 * Data MUST be written atomically so that there is no chance that
120 * multiple appenders can collide and result in data being lost.
121 * <p>
122 * If both append flags are specified, the server SHOULD use atomic
123 * append if it is available, but SHOULD use non-atomic appends
124 * otherwise. The server SHOULD NOT fail the request in this case.
125 */
126 public static final int SSH_FXF_ACCESS_APPEND_DATA_ATOMIC = 0x00000010;
127
128 /**
129 * Indicates that the server should treat the file as text and
130 * convert it to the canonical newline convention in use.
131 * (See Determining Server Newline Convention in section 5.3 in the
132 * SFTP standard draft).
133 * <p>
134 * When a file is opened with this flag, the offset field in the read
135 * and write functions is ignored.
136 * <p>
137 * Servers MUST process multiple, parallel reads and writes correctly
138 * in this mode. Naturally, it is permissible for them to do this by
139 * serializing the requests.
140 * <p>
141 * Clients SHOULD use the SSH_FXF_ACCESS_APPEND_DATA flag to append
142 * data to a text file rather then using write with a calculated offset.
143 */
144 public static final int SSH_FXF_ACCESS_TEXT_MODE = 0x00000020;
145
146 /**
147 * The server MUST guarantee that no other handle has been opened
148 * with ACE4_READ_DATA access, and that no other handle will be
149 * opened with ACE4_READ_DATA access until the client closes the
150 * handle. (This MUST apply both to other clients and to other
151 * processes on the server.)
152 * <p>
153 * If there is a conflicting lock the server MUST return
154 * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
155 * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
156 * <p>
157 * Other handles MAY be opened for ACE4_WRITE_DATA or any other
158 * combination of accesses, as long as ACE4_READ_DATA is not included
159 * in the mask.
160 */
161 public static final int SSH_FXF_ACCESS_BLOCK_READ = 0x00000040;
162
163 /**
164 * The server MUST guarantee that no other handle has been opened
165 * with ACE4_WRITE_DATA or ACE4_APPEND_DATA access, and that no other
166 * handle will be opened with ACE4_WRITE_DATA or ACE4_APPEND_DATA
167 * access until the client closes the handle. (This MUST apply both
168 * to other clients and to other processes on the server.)
169 * <p>
170 * If there is a conflicting lock the server MUST return
171 * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
172 * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
173 * <p>
174 * Other handles MAY be opened for ACE4_READ_DATA or any other
175 * combination of accesses, as long as neither ACE4_WRITE_DATA nor
176 * ACE4_APPEND_DATA are included in the mask.
177 */
178 public static final int SSH_FXF_ACCESS_BLOCK_WRITE = 0x00000080;
179
180 /**
181 * The server MUST guarantee that no other handle has been opened
182 * with ACE4_DELETE access, opened with the
183 * SSH_FXF_ACCESS_DELETE_ON_CLOSE flag set, and that no other handle
184 * will be opened with ACE4_DELETE access or with the
185 * SSH_FXF_ACCESS_DELETE_ON_CLOSE flag set, and that the file itself
186 * is not deleted in any other way until the client closes the handle.
187 * <p>
188 * If there is a conflicting lock the server MUST return
189 * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
190 * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
191 */
192 public static final int SSH_FXF_ACCESS_BLOCK_DELETE = 0x00000100;
193
194 /**
195 * If this bit is set, the above BLOCK modes are advisory. In advisory
196 * mode, only other accesses that specify a BLOCK mode need be
197 * considered when determining whether the BLOCK can be granted,
198 * and the server need not prevent I/O operations that violate the
199 * block mode.
200 * <p>
201 * The server MAY perform mandatory locking even if the BLOCK_ADVISORY
202 * bit is set.
203 */
204 public static final int SSH_FXF_ACCESS_BLOCK_ADVISORY = 0x00000200;
205
206 /**
207 * If the final component of the path is a symlink, then the open
208 * MUST fail, and the error SSH_FX_LINK_LOOP MUST be returned.
209 */
210 public static final int SSH_FXF_ACCESS_NOFOLLOW = 0x00000400;
211
212 /**
213 * The file should be deleted when the last handle to it is closed.
214 * (The last handle may not be an sftp-handle.) This MAY be emulated
215 * by a server if the OS doesn't support it by deleting the file when
216 * this handle is closed.
217 * <p>
218 * It is implementation specific whether the directory entry is
219 * removed immediately or when the handle is closed.
220 */
221 public static final int SSH_FXF_ACCESS_DELETE_ON_CLOSE = 0x00000800;
222 }