OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO(vtl): notes to self: | 5 // TODO(vtl): notes to self: |
6 // - file offsets, file positions, and file sizes are int64 (though positions | 6 // - file offsets, file positions, and file sizes are int64 (though positions |
7 // and sizes must always be non-negative) | 7 // and sizes must always be non-negative) |
8 // - buffer size parameters (for read/write) are uint32 | 8 // - buffer size parameters (for read/write) are uint32 |
9 | 9 |
10 [DartPackage="mojo_services"] | 10 [DartPackage="mojo_services"] |
11 module mojo.files; | 11 module mojo.files; |
12 | 12 |
13 import "files/interfaces/types.mojom"; | 13 import "files/interfaces/types.mojom"; |
14 | 14 |
15 // TODO(vtl): Write comments. | 15 // TODO(vtl): Write comments. |
16 interface File { | 16 interface File { |
17 // Flushes/closes this file; no operations may be performed on this file after | 17 // Flushes/closes this file; no operations may be performed on this file after |
18 // this. Note that any error code is strictly informational -- the close may | 18 // this. Note that any error code is strictly informational -- the close may |
19 // not be retried. | 19 // not be retried. |
20 Close() => (Error err); | 20 Close() => (Error err); |
21 | 21 |
22 // Reads (at most) |num_bytes_to_read| from the location specified by | 22 // Reads (at most) |num_bytes_to_read| from the location specified by |
23 // |offset|/|whence|. On success, |bytes_read| is set to the data read. | 23 // |offset|/|whence|. On success, |bytes_read| is set to the data read. |
24 // TODO(vtl): Define/clarify behavior when less than |num_bytes_to_read| bytes | 24 // TODO(vtl): Define/clarify behavior when less than |num_bytes_to_read| bytes |
25 // are read. | 25 // are read. |
26 // TODO(vtl): Clarify when (for what values of |offset|/|whence|) this | 26 // TODO(vtl): Clarify when (for what values of |offset|/|whence|) this |
27 // modifies the file position. Or maybe there should be a flag? | 27 // modifies the file position. Or maybe there should be a flag? |
28 Read(uint32 num_bytes_to_read, int64 offset, Whence whence) | 28 Read(uint32 num_bytes_to_read, int64 offset, Whence whence) => (Error error, a
rray<uint8>? bytes_read); |
29 => (Error error, array<uint8>? bytes_read); | |
30 | 29 |
31 // Writes |bytes_to_write| to the location specified by |offset|/|whence|. | 30 // Writes |bytes_to_write| to the location specified by |offset|/|whence|. |
32 // TODO(vtl): Clarify behavior when |num_bytes_written| is less than the size | 31 // TODO(vtl): Clarify behavior when |num_bytes_written| is less than the size |
33 // of |bytes_to_write|. | 32 // of |bytes_to_write|. |
34 Write(array<uint8> bytes_to_write, int64 offset, Whence whence) | 33 Write(array<uint8> bytes_to_write, int64 offset, Whence whence) => (Error erro
r, uint32 num_bytes_written); |
35 => (Error error, uint32 num_bytes_written); | |
36 | 34 |
37 // TODO(vtl): We definitely want 64 bits for |num_bytes_to_read|; but do we | 35 // TODO(vtl): We definitely want 64 bits for |num_bytes_to_read|; but do we |
38 // want it to be signed (this is consistent with |size| values, but | 36 // want it to be signed (this is consistent with |size| values, but |
39 // inconsistent with 32-bit |num_bytes_to_read| values)? Do we want to have | 37 // inconsistent with 32-bit |num_bytes_to_read| values)? Do we want to have |
40 // separate "read to end" versus "tail" (i.e., keep on reading as more data is | 38 // separate "read to end" versus "tail" (i.e., keep on reading as more data is |
41 // appended) modes, and how would those be signaled? | 39 // appended) modes, and how would those be signaled? |
42 ReadToStream(handle<data_pipe_producer> source, | 40 ReadToStream(handle<data_pipe_producer> source, int64 offset, Whence whence, i
nt64 num_bytes_to_read) => (Error error); |
43 int64 offset, | 41 WriteFromStream(handle<data_pipe_consumer> sink, int64 offset, Whence whence)
=> (Error error); |
44 Whence whence, | |
45 int64 num_bytes_to_read) => (Error error); | |
46 WriteFromStream(handle<data_pipe_consumer> sink, int64 offset, Whence whence) | |
47 => (Error error); | |
48 | 42 |
49 // Gets the current file position. On success, |position| is the current | 43 // Gets the current file position. On success, |position| is the current |
50 // offset (in bytes) from the beginning of the file). | 44 // offset (in bytes) from the beginning of the file). |
51 Tell() => (Error error, int64 position); | 45 Tell() => (Error error, int64 position); |
52 | 46 |
53 // Sets the current file position to that specified by |offset|/|whence|. On | 47 // Sets the current file position to that specified by |offset|/|whence|. On |
54 // success, |position| is the offset (in bytes) from the beginning of the | 48 // success, |position| is the offset (in bytes) from the beginning of the |
55 // file. | 49 // file. |
56 Seek(int64 offset, Whence whence) => (Error error, int64 position); | 50 Seek(int64 offset, Whence whence) => (Error error, int64 position); |
57 | 51 |
(...skipping 19 matching lines...) Expand all Loading... |
77 // not), can remove "append"? (probably not?). Do we allow "truncate"? | 71 // not), can remove "append"? (probably not?). Do we allow "truncate"? |
78 Reopen(File& file, uint32 open_flags) => (Error error); | 72 Reopen(File& file, uint32 open_flags) => (Error error); |
79 | 73 |
80 // TODO(vtl): probably should have access flags (but also exec?); how do these | 74 // TODO(vtl): probably should have access flags (but also exec?); how do these |
81 // relate to access mode? | 75 // relate to access mode? |
82 AsBuffer() => (Error error, handle<shared_buffer>? buffer); | 76 AsBuffer() => (Error error, handle<shared_buffer>? buffer); |
83 | 77 |
84 // Special-file-specific control function, for device "files". |in| and |out| | 78 // Special-file-specific control function, for device "files". |in| and |out| |
85 // are dependent on |request|. See ioctl.mojom for the master list of request | 79 // are dependent on |request|. See ioctl.mojom for the master list of request |
86 // values. | 80 // values. |
87 Ioctl(uint32 request, array<uint32>? in_values) | 81 Ioctl(uint32 request, array<uint32>? in_values) => (Error error, array<uint32>
? out_values); |
88 => (Error error, array<uint32>? out_values); | |
89 | 82 |
90 // TODO(vtl): Add a "watch"? | 83 // TODO(vtl): Add a "watch"? |
91 // TODO(vtl): Add something analogous to fsync(2)? | 84 // TODO(vtl): Add something analogous to fsync(2)? |
92 }; | 85 }; |
OLD | NEW |