| 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 [DartPackage="mojo_services"] | |
| 11 module mojo.files; | |
| 12 | |
| 13 import "files/public/interfaces/types.mojom"; | |
| 14 | |
| 15 // TODO(vtl): Write comments. | |
| 16 interface File { | |
| 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 | |
| 19 // not be retried. | |
| 20 Close() => (Error err); | |
| 21 | |
| 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. | |
| 24 // TODO(vtl): Define/clarify behavior when less than |num_bytes_to_read| bytes | |
| 25 // are read. | |
| 26 // TODO(vtl): Clarify when (for what values of |offset|/|whence|) this | |
| 27 // modifies the file position. Or maybe there should be a flag? | |
| 28 Read(uint32 num_bytes_to_read, int64 offset, Whence whence) | |
| 29 => (Error error, array<uint8>? bytes_read); | |
| 30 | |
| 31 // 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 | |
| 33 // of |bytes_to_write|. | |
| 34 Write(array<uint8> bytes_to_write, int64 offset, Whence whence) | |
| 35 => (Error error, uint32 num_bytes_written); | |
| 36 | |
| 37 // 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 | |
| 39 // 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 | |
| 41 // appended) modes, and how would those be signalled? | |
| 42 ReadToStream(handle<data_pipe_producer> source, | |
| 43 int64 offset, | |
| 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 | |
| 49 // Gets the current file position. On success, |position| is the current | |
| 50 // offset (in bytes) from the beginning of the file). | |
| 51 Tell() => (Error error, int64 position); | |
| 52 | |
| 53 // 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 | |
| 55 // file. | |
| 56 Seek(int64 offset, Whence whence) => (Error error, int64 position); | |
| 57 | |
| 58 // Gets information about this file. On success, |file_information| is | |
| 59 // non-null and will contain this information. | |
| 60 Stat() => (Error error, FileInformation? file_information); | |
| 61 | |
| 62 // Truncates this file to the size specified by |size| (in bytes). | |
| 63 Truncate(int64 size) => (Error error); | |
| 64 | |
| 65 // Updates this file's atime and/or mtime to the time specified by |atime| (or | |
| 66 // |mtime|, respectively), which may also indicate "now". If |atime| or | |
| 67 // |mtime| is null, then the corresponding time is not modified. | |
| 68 Touch(TimespecOrNow? atime, TimespecOrNow? mtime) => (Error error); | |
| 69 | |
| 70 // Creates a new |File| instance, which shares the same "file description". | |
| 71 // I.e., the access mode, etc. (as specified to |Directory::OpenFile()| by the | |
| 72 // |open_flags| argument) as well as file position. | |
| 73 Dup(File& file) => (Error error); | |
| 74 | |
| 75 // TODO(vtl): What are the rules for reopening (w.r.t. changing mode/flags). | |
| 76 // E.g., obviously can go from "read-write" to "read", but reverse? (probably | |
| 77 // not), can remove "append"? (probably not?). Do we allow "truncate"? | |
| 78 Reopen(File& file, uint32 open_flags) => (Error error); | |
| 79 | |
| 80 // TODO(vtl): probably should have access flags (but also exec?); how do these | |
| 81 // relate to access mode? | |
| 82 AsBuffer() => (Error error, handle<shared_buffer>? buffer); | |
| 83 | |
| 84 // 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 | |
| 86 // values. | |
| 87 Ioctl(uint32 request, array<uint32>? in_values) | |
| 88 => (Error error, array<uint32>? out_values); | |
| 89 | |
| 90 // TODO(vtl): Add a "watch"? | |
| 91 // TODO(vtl): Add something analogous to fsync(2)? | |
| 92 }; | |
| OLD | NEW |