blob: 83ca8d3b98503e8f3d7cd7552f9c6dcf678024b7 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(vtl): notes to self:
// - file offsets, file positions, and file sizes are int64 (though positions
// and sizes must always be non-negative)
// - buffer size parameters (for read/write) are uint32
[DartPackage="mojo_services"]
module mojo.files;
import "files/public/interfaces/types.mojom";
// TODO(vtl): Write comments.
interface File {
// Flushes/closes this file; no operations may be performed on this file after
// this. Note that any error code is strictly informational -- the close may
// not be retried.
Close() => (Error err);
// Reads (at most) |num_bytes_to_read| from the location specified by
// |offset|/|whence|. On success, |bytes_read| is set to the data read.
// TODO(vtl): Define/clarify behavior when less than |num_bytes_to_read| bytes
// are read.
// TODO(vtl): Clarify when (for what values of |offset|/|whence|) this
// modifies the file position. Or maybe there should be a flag?
Read(uint32 num_bytes_to_read, int64 offset, Whence whence)
=> (Error error, array<uint8>? bytes_read);
// Writes |bytes_to_write| to the location specified by |offset|/|whence|.
// TODO(vtl): Clarify behavior when |num_bytes_written| is less than the size
// of |bytes_to_write|.
Write(array<uint8> bytes_to_write, int64 offset, Whence whence)
=> (Error error, uint32 num_bytes_written);
// TODO(vtl): We definitely want 64 bits for |num_bytes_to_read|; but do we
// want it to be signed (this is consistent with |size| values, but
// inconsistent with 32-bit |num_bytes_to_read| values)? Do we want to have
// separate "read to end" versus "tail" (i.e., keep on reading as more data is
// appended) modes, and how would those be signalled?
ReadToStream(handle<data_pipe_producer> source,
int64 offset,
Whence whence,
int64 num_bytes_to_read) => (Error error);
WriteFromStream(handle<data_pipe_consumer> sink, int64 offset, Whence whence)
=> (Error error);
// Gets the current file position. On success, |position| is the current
// offset (in bytes) from the beginning of the file).
Tell() => (Error error, int64 position);
// Sets the current file position to that specified by |offset|/|whence|. On
// success, |position| is the offset (in bytes) from the beginning of the
// file.
Seek(int64 offset, Whence whence) => (Error error, int64 position);
// Gets information about this file. On success, |file_information| is
// non-null and will contain this information.
Stat() => (Error error, FileInformation? file_information);
// Truncates this file to the size specified by |size| (in bytes).
Truncate(int64 size) => (Error error);
// Updates this file's atime and/or mtime to the time specified by |atime| (or
// |mtime|, respectively), which may also indicate "now". If |atime| or
// |mtime| is null, then the corresponding time is not modified.
Touch(TimespecOrNow? atime, TimespecOrNow? mtime) => (Error error);
// Creates a new |File| instance, which shares the same "file description".
// I.e., the access mode, etc. (as specified to |Directory::OpenFile()| by the
// |open_flags| argument) as well as file position.
Dup(File& file) => (Error error);
// TODO(vtl): What are the rules for reopening (w.r.t. changing mode/flags).
// E.g., obviously can go from "read-write" to "read", but reverse? (probably
// not), can remove "append"? (probably not?). Do we allow "truncate"?
Reopen(File& file, uint32 open_flags) => (Error error);
// TODO(vtl): probably should have access flags (but also exec?); how do these
// relate to access mode?
AsBuffer() => (Error error, handle<shared_buffer>? buffer);
// Special-file-specific control function, for device "files". |in| and |out|
// are dependent on |request|.
// TODO(vtl): Make a master list of request values somewhere.
Ioctl(uint32 request, array<uint32>? in_values)
=> (Error error, array<uint32>? out_values);
// TODO(vtl): Add a "watch"?
// TODO(vtl): Add something analogous to fsync(2)?
};