Chromium Code Reviews| Index: services/files/types.mojom |
| diff --git a/services/files/types.mojom b/services/files/types.mojom |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba8aa1050e2ad4d1a8dfa02c206d3382accb9aae |
| --- /dev/null |
| +++ b/services/files/types.mojom |
| @@ -0,0 +1,99 @@ |
| +// 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. |
| + |
| +module mojo.files; |
| + |
| +// Error codes used by the file manager. |
| +// TODO(vtl): Add more (to, e.g., cover all of errno). |
| +enum Error { |
| + OK = 0, |
| + UNKNOWN, |
| + INVALID_ARGUMENT, |
| + PERMISSION_DENIED, |
| + OUT_OF_RANGE, |
| + UNIMPLEMENTED, |
| + CLOSED, |
| + UNAVAILABLE, |
| + INTERNAL, |
| +}; |
| + |
| +// Used to explain the meaning of an offset within a file. |
| +enum Whence { |
| + // Offset is from current position in the file. |
| + FROM_CURRENT = 0, |
| + // Offset is relative to the beginning of the file. |
| + FROM_START, |
| + // Offset is relative to the end of the file. |
| + FROM_END, |
| +}; |
| + |
| +// Describes (idealized) wall-clock time, since Unix epoch (i.e., since |
| +// "1970-01-01 00:00 UTC", ignoring leap seconds and that UTC as we know it |
| +// started in 1972). |
| +// TODO(vtl): Should probably be moved out of mojo.files (maybe to mojo.time?). |
| +struct Timespec { |
| + int64 seconds; |
| + int32 nanoseconds; // Always in the interval [0, 10^9). |
| +}; |
| + |
| +// Used for |Touch()| calls. If |now| is set, |timespec| must be null (the time |
| +// "now" will be used). Otherwise, |timespec| must not be null. |
| +// TODO(vtl): Use a union instead, when that becomes possible. |
|
qsr
2015/03/02 12:46:40
I am missing something obvious, but why do you nee
viettrungluu
2015/03/02 18:10:59
Really, this should be turned into a union, once t
qsr
2015/03/03 11:56:44
What would the union looks like? The same as this?
viettrungluu
2015/03/03 18:50:35
Yeah, I'm not super-happy about it. Really, what I
|
| +struct TimespecOrNow { |
| + bool now; |
| + Timespec? timespec; |
| +}; |
| + |
| +// Describes various information about a file or directory (for |Stat()|). Note |
| +// that access/modification times may be set arbitrarily (by those with |
| +// appropriate capabilities) and may not reflect reality. |
| +struct FileInformation { |
| + // Size of the file, in bytes. |
| + int64 size; |
|
qsr
2015/03/02 12:46:40
What does size mean for a directory?
viettrungluu
2015/03/02 18:10:59
That's a good question (to be pondered). stat(2) d
viettrungluu
2015/03/03 18:50:35
(I defined it to be zero for directories.)
|
| + // Last access time, if available/supported. |
| + Timespec? atime; |
| + // Last modification time, if available/supported. |
| + Timespec? mtime; |
| +}; |
| + |
| +// File and directory open flags (at least one of |kOpenFlagRead| and |
| +// |kOpenFlagWrite| is required): |
| +// Opens the file/directory for reading. |
| +const uint32 kOpenFlagRead = 0x1; |
| +// Opens the file/directory for writing. |
| +const uint32 kOpenFlagWrite = 0x2; |
| +// Only meaningful together with |kOpenFlagWrite|: creates the file if |
| +// necessary. |
| +const uint32 kOpenFlagCreate = 0x4; |
| +// Only meaningful together with |kOpenFlagCreate|: requires file/directory to |
| +// be created, failing if it already exists. |
| +const uint32 kOpenFlagExclusive = 0x8; |
| +// Only meaningful for files, together with |kOpenFlagWrite|: writes will always |
| +// append to the file. |
| +const uint32 kOpenFlagAppend = 0x10; |
| +// Only meaningful for files, together with |kOpenFlagWrite|: truncates the |
| +// file. |
| +const uint32 kOpenFlagTruncate = 0x20; |
| + |
| +// File types. |
| +enum FileType { |
| + UNKNOWN = 0, |
| + REGULAR_FILE, |
| + DIRECTORY, |
| +}; |
| + |
| +// Describes a directory entry (i.e., a single member of a directory). |
| +struct DirectoryEntry { |
| + FileType type; |
| + string name; |
| +}; |
| + |
| +// Deletion flags: |
| +// Only delete if the path refers to a file/non-directory (by default, will |
| +// delete files and directories). |
| +const uint32 kDeleteFlagFileOnly = 0x1; |
| +// Only delete if the path refers to a directory. |
| +const uint32 kDeleteFlagDirectoryOnly = 0x2; |
| +// Recursively delete (neither of the two flags above may be specified). |
| +const uint32 kDeleteFlagRecursive = 0x4; |