001: package ch.ethz.ssh2.sftp;
002:
003: /**
004: *
005: * SFTP Open Flags.
006: *
007: * The following table is provided to assist in mapping POSIX semantics
008: * to equivalent SFTP file open parameters:
009: * <p>
010: * TODO: This comment should be moved to the open method.
011: * <p>
012: * <ul>
013: * <li>O_RDONLY
014: * <ul><li>desired-access = READ_DATA | READ_ATTRIBUTES</li></ul>
015: * </li>
016: * </ul>
017: * <ul>
018: * <li>O_WRONLY
019: * <ul><li>desired-access = WRITE_DATA | WRITE_ATTRIBUTES</li></ul>
020: * </li>
021: * </ul>
022: * <ul>
023: * <li>O_RDWR
024: * <ul><li>desired-access = READ_DATA | READ_ATTRIBUTES | WRITE_DATA | WRITE_ATTRIBUTES</li></ul>
025: * </li>
026: * </ul>
027: * <ul>
028: * <li>O_APPEND
029: * <ul>
030: * <li>desired-access = WRITE_DATA | WRITE_ATTRIBUTES | APPEND_DATA</li>
031: * <li>flags = SSH_FXF_ACCESS_APPEND_DATA and or SSH_FXF_ACCESS_APPEND_DATA_ATOMIC</li>
032: * </ul>
033: * </li>
034: * </ul>
035: * <ul>
036: * <li>O_CREAT
037: * <ul>
038: * <li>flags = SSH_FXF_OPEN_OR_CREATE</li>
039: * </ul>
040: * </li>
041: * </ul>
042: * <ul>
043: * <li>O_TRUNC
044: * <ul>
045: * <li>flags = SSH_FXF_TRUNCATE_EXISTING</li>
046: * </ul>
047: * </li>
048: * </ul>
049: * <ul>
050: * <li>O_TRUNC|O_CREATE
051: * <ul>
052: * <li>flags = SSH_FXF_CREATE_TRUNCATE</li>
053: * </ul>
054: * </li>
055: * </ul>
056: *
057: * @author Christian Plattner, plattner@inf.ethz.ch
058: * @version $Id: OpenFlags.java,v 1.2 2006/08/02 12:05:00 cplattne Exp $
059: */
060: public class OpenFlags {
061: /**
062: * Disposition is a 3 bit field that controls how the file is opened.
063: * The server MUST support these bits (possible enumaration values:
064: * SSH_FXF_CREATE_NEW, SSH_FXF_CREATE_TRUNCATE, SSH_FXF_OPEN_EXISTING,
065: * SSH_FXF_OPEN_OR_CREATE or SSH_FXF_TRUNCATE_EXISTING).
066: */
067: public static final int SSH_FXF_ACCESS_DISPOSITION = 0x00000007;
068:
069: /**
070: * A new file is created; if the file already exists, the server
071: * MUST return status SSH_FX_FILE_ALREADY_EXISTS.
072: */
073: public static final int SSH_FXF_CREATE_NEW = 0x00000000;
074:
075: /**
076: * A new file is created; if the file already exists, it is opened
077: * and truncated.
078: */
079: public static final int SSH_FXF_CREATE_TRUNCATE = 0x00000001;
080:
081: /**
082: * An existing file is opened. If the file does not exist, the
083: * server MUST return SSH_FX_NO_SUCH_FILE. If a directory in the
084: * path does not exist, the server SHOULD return
085: * SSH_FX_NO_SUCH_PATH. It is also acceptable if the server
086: * returns SSH_FX_NO_SUCH_FILE in this case.
087: */
088: public static final int SSH_FXF_OPEN_EXISTING = 0x00000002;
089:
090: /**
091: * If the file exists, it is opened. If the file does not exist,
092: * it is created.
093: */
094: public static final int SSH_FXF_OPEN_OR_CREATE = 0x00000003;
095:
096: /**
097: * An existing file is opened and truncated. If the file does not
098: * exist, the server MUST return the same error codes as defined
099: * for SSH_FXF_OPEN_EXISTING.
100: */
101: public static final int SSH_FXF_TRUNCATE_EXISTING = 0x00000004;
102:
103: /**
104: * Data is always written at the end of the file. The offset field
105: * of the SSH_FXP_WRITE requests are ignored.
106: * <p>
107: * Data is not required to be appended atomically. This means that
108: * if multiple writers attempt to append data simultaneously, data
109: * from the first may be lost. However, data MAY be appended
110: * atomically.
111: */
112: public static final int SSH_FXF_ACCESS_APPEND_DATA = 0x00000008;
113:
114: /**
115: * Data is always written at the end of the file. The offset field
116: * of the SSH_FXP_WRITE requests are ignored.
117: * <p>
118: * Data MUST be written atomically so that there is no chance that
119: * multiple appenders can collide and result in data being lost.
120: * <p>
121: * If both append flags are specified, the server SHOULD use atomic
122: * append if it is available, but SHOULD use non-atomic appends
123: * otherwise. The server SHOULD NOT fail the request in this case.
124: */
125: public static final int SSH_FXF_ACCESS_APPEND_DATA_ATOMIC = 0x00000010;
126:
127: /**
128: * Indicates that the server should treat the file as text and
129: * convert it to the canonical newline convention in use.
130: * (See Determining Server Newline Convention in section 5.3 in the
131: * SFTP standard draft).
132: * <p>
133: * When a file is opened with this flag, the offset field in the read
134: * and write functions is ignored.
135: * <p>
136: * Servers MUST process multiple, parallel reads and writes correctly
137: * in this mode. Naturally, it is permissible for them to do this by
138: * serializing the requests.
139: * <p>
140: * Clients SHOULD use the SSH_FXF_ACCESS_APPEND_DATA flag to append
141: * data to a text file rather then using write with a calculated offset.
142: */
143: public static final int SSH_FXF_ACCESS_TEXT_MODE = 0x00000020;
144:
145: /**
146: * The server MUST guarantee that no other handle has been opened
147: * with ACE4_READ_DATA access, and that no other handle will be
148: * opened with ACE4_READ_DATA access until the client closes the
149: * handle. (This MUST apply both to other clients and to other
150: * processes on the server.)
151: * <p>
152: * If there is a conflicting lock the server MUST return
153: * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
154: * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
155: * <p>
156: * Other handles MAY be opened for ACE4_WRITE_DATA or any other
157: * combination of accesses, as long as ACE4_READ_DATA is not included
158: * in the mask.
159: */
160: public static final int SSH_FXF_ACCESS_BLOCK_READ = 0x00000040;
161:
162: /**
163: * The server MUST guarantee that no other handle has been opened
164: * with ACE4_WRITE_DATA or ACE4_APPEND_DATA access, and that no other
165: * handle will be opened with ACE4_WRITE_DATA or ACE4_APPEND_DATA
166: * access until the client closes the handle. (This MUST apply both
167: * to other clients and to other processes on the server.)
168: * <p>
169: * If there is a conflicting lock the server MUST return
170: * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
171: * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
172: * <p>
173: * Other handles MAY be opened for ACE4_READ_DATA or any other
174: * combination of accesses, as long as neither ACE4_WRITE_DATA nor
175: * ACE4_APPEND_DATA are included in the mask.
176: */
177: public static final int SSH_FXF_ACCESS_BLOCK_WRITE = 0x00000080;
178:
179: /**
180: * The server MUST guarantee that no other handle has been opened
181: * with ACE4_DELETE access, opened with the
182: * SSH_FXF_ACCESS_DELETE_ON_CLOSE flag set, and that no other handle
183: * will be opened with ACE4_DELETE access or with the
184: * SSH_FXF_ACCESS_DELETE_ON_CLOSE flag set, and that the file itself
185: * is not deleted in any other way until the client closes the handle.
186: * <p>
187: * If there is a conflicting lock the server MUST return
188: * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
189: * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
190: */
191: public static final int SSH_FXF_ACCESS_BLOCK_DELETE = 0x00000100;
192:
193: /**
194: * If this bit is set, the above BLOCK modes are advisory. In advisory
195: * mode, only other accesses that specify a BLOCK mode need be
196: * considered when determining whether the BLOCK can be granted,
197: * and the server need not prevent I/O operations that violate the
198: * block mode.
199: * <p>
200: * The server MAY perform mandatory locking even if the BLOCK_ADVISORY
201: * bit is set.
202: */
203: public static final int SSH_FXF_ACCESS_BLOCK_ADVISORY = 0x00000200;
204:
205: /**
206: * If the final component of the path is a symlink, then the open
207: * MUST fail, and the error SSH_FX_LINK_LOOP MUST be returned.
208: */
209: public static final int SSH_FXF_ACCESS_NOFOLLOW = 0x00000400;
210:
211: /**
212: * The file should be deleted when the last handle to it is closed.
213: * (The last handle may not be an sftp-handle.) This MAY be emulated
214: * by a server if the OS doesn't support it by deleting the file when
215: * this handle is closed.
216: * <p>
217: * It is implementation specific whether the directory entry is
218: * removed immediately or when the handle is closed.
219: */
220: public static final int SSH_FXF_ACCESS_DELETE_ON_CLOSE = 0x00000800;
221: }
|