OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // TODO(vtl): notes to self: | |
6 // - file offsets, file positions, and file sizes are int64 (though positions | |
7 // and sizes must always be non-negative) | |
8 // - buffer size parameters (for read/write) are uint32 | |
9 | |
10 module mojo.files; | |
11 | |
12 import "services/files/types.mojom"; | |
13 | |
14 // TODO(vtl): Write comments. | |
15 interface File { | |
16 // Flushes/closes this file; no operations may be performed on this file after | |
17 // this. Note that any error code is strictly informational -- the close may | |
18 // not be retried. | |
19 Close() => (Error err); | |
20 | |
21 // Reads (at most) |num_bytes_to_read| from the location specified by | |
22 // |offset|/|whence|. On success, |bytes_read| is set to the data read. | |
23 // TODO(vtl): Define/clarify behavior when less than |num_bytes_to_read| bytes | |
24 // are read. | |
25 // TODO(vtl): Clarify when (for what values of |offset|/|whence|) this | |
26 // modifies the file position. Or maybe there should be a flag? | |
27 Read(uint32 num_bytes_to_read, int64 offset, Whence whence) | |
28 => (Error error, array<uint8>? bytes_read); | |
29 | |
30 // Writes |bytes_to_write| to the location specified by |offset|/|whence|. | |
31 // TODO(vtl): Clarify behavior when |num_bytes_written| is less than the size | |
32 // of |bytes_to_write|. | |
33 Write(array<uint8> bytes_to_write, int64 offset, Whence whence) | |
34 => (Error error, uint32 num_bytes_written); | |
35 | |
36 // TODO(vtl): We definitely want 64 bits for |num_bytes_to_read|; but do we | |
37 // want it to be signed (this is consistent with |size| values, but | |
38 // inconsistent with 32-bit |num_bytes_to_read| values)? Do we want to have | |
39 // separate "read to end" versus "tail" (i.e., keep on reading as more data is | |
40 // appended) modes, and how would those be signalled? | |
41 ReadToStream(handle<data_pipe_producer> source, | |
42 int64 offset, | |
43 Whence whence, | |
44 int64 num_bytes_to_read) => (Error error); | |
45 WriteFromStream(handle<data_pipe_consumer> sink, int64 offset, Whence whence) | |
46 => (Error error); | |
47 | |
48 // Gets the current file position. On success, |position| is the current | |
49 // offset (in bytes) from the beginning of the file). | |
50 Tell() => (Error error, int64 position); | |
51 | |
52 // Sets the current file position to that specified by |offset|/|whence|. On | |
53 // success, |position| is the offset (in bytes) from the beginning of the | |
54 // file. | |
55 Seek(int64 offset, Whence whence) => (Error error, int64 position); | |
56 | |
57 // Gets information about this file. On success, |file_information| is | |
58 // non-null and will contain this information. | |
59 Stat() => (Error error, FileInformation? file_information); | |
60 | |
61 // Truncates this file to the size specified by |size| (in bytes). | |
62 Truncate(int64 size) => (Error error); | |
63 | |
64 // Updates this file's atime and/or mtime to the time specified by |atime| (or | |
65 // |mtime|, respectively), which may also indicate "now". If |atime| or | |
66 // |mtime| is null, then the corresponding time is not modified. | |
67 Touch(TimespecOrNow? atime, TimespecOrNow? mtime) => (Error error); | |
68 | |
69 // Creates a new |File| instance, which shares the same "file description". | |
70 // I.e., the access mode, etc. (as specified to |Directory::OpenFile()| by the | |
71 // |open_flags| argument) as well as file position. | |
72 Dup(File& file) => (Error error); | |
73 | |
74 // TODO(vtl): What are the rules for reopening (w.r.t. changing mode/flags). | |
75 // E.g., obviously can go from "read-write" to "read", but reverse? (probably | |
76 // not), can remove "append"? (probably not?). Do we allow "truncate"? | |
77 Reopen(File& file, uint32 open_flags) => (Error error); | |
78 | |
79 // TODO(vtl): probably should have access flags (but also exec?); how do these | |
80 // relate to access mode? | |
81 AsBuffer() => (Error error, handle<shared_buffer>? buffer); | |
82 | |
83 // TODO(vtl): Add a "watch"? | |
84 // TODO(vtl): Add something analogous to fsync(2)? | |
85 }; | |
OLD | NEW |