Chromium Code Reviews| 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 module mojo.files; | |
| 6 | |
| 7 // Error codes used by the file manager. | |
| 8 // TODO(vtl): Add more (to, e.g., cover all of errno). | |
| 9 enum Error { | |
| 10 OK = 0, | |
| 11 UNKNOWN, | |
| 12 INVALID_ARGUMENT, | |
| 13 PERMISSION_DENIED, | |
| 14 OUT_OF_RANGE, | |
| 15 UNIMPLEMENTED, | |
| 16 CLOSED, | |
| 17 UNAVAILABLE, | |
| 18 INTERNAL, | |
| 19 }; | |
| 20 | |
| 21 // Used to explain the meaning of an offset within a file. | |
| 22 enum Whence { | |
| 23 // Offset is from current position in the file. | |
| 24 FROM_CURRENT = 0, | |
| 25 // Offset is relative to the beginning of the file. | |
| 26 FROM_START, | |
| 27 // Offset is relative to the end of the file. | |
| 28 FROM_END, | |
| 29 }; | |
| 30 | |
| 31 // Describes (idealized) wall-clock time, since Unix epoch (i.e., since | |
| 32 // "1970-01-01 00:00 UTC", ignoring leap seconds and that UTC as we know it | |
| 33 // started in 1972). | |
| 34 // TODO(vtl): Should probably be moved out of mojo.files (maybe to mojo.time?). | |
| 35 struct Timespec { | |
| 36 int64 seconds; | |
| 37 int32 nanoseconds; // Always in the interval [0, 10^9). | |
| 38 }; | |
| 39 | |
| 40 // Used for |Touch()| calls. If |now| is set, |timespec| must be null (the time | |
| 41 // "now" will be used). Otherwise, |timespec| must not be null. | |
| 42 // 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
| |
| 43 struct TimespecOrNow { | |
| 44 bool now; | |
| 45 Timespec? timespec; | |
| 46 }; | |
| 47 | |
| 48 // Describes various information about a file or directory (for |Stat()|). Note | |
| 49 // that access/modification times may be set arbitrarily (by those with | |
| 50 // appropriate capabilities) and may not reflect reality. | |
| 51 struct FileInformation { | |
| 52 // Size of the file, in bytes. | |
| 53 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.)
| |
| 54 // Last access time, if available/supported. | |
| 55 Timespec? atime; | |
| 56 // Last modification time, if available/supported. | |
| 57 Timespec? mtime; | |
| 58 }; | |
| 59 | |
| 60 // File and directory open flags (at least one of |kOpenFlagRead| and | |
| 61 // |kOpenFlagWrite| is required): | |
| 62 // Opens the file/directory for reading. | |
| 63 const uint32 kOpenFlagRead = 0x1; | |
| 64 // Opens the file/directory for writing. | |
| 65 const uint32 kOpenFlagWrite = 0x2; | |
| 66 // Only meaningful together with |kOpenFlagWrite|: creates the file if | |
| 67 // necessary. | |
| 68 const uint32 kOpenFlagCreate = 0x4; | |
| 69 // Only meaningful together with |kOpenFlagCreate|: requires file/directory to | |
| 70 // be created, failing if it already exists. | |
| 71 const uint32 kOpenFlagExclusive = 0x8; | |
| 72 // Only meaningful for files, together with |kOpenFlagWrite|: writes will always | |
| 73 // append to the file. | |
| 74 const uint32 kOpenFlagAppend = 0x10; | |
| 75 // Only meaningful for files, together with |kOpenFlagWrite|: truncates the | |
| 76 // file. | |
| 77 const uint32 kOpenFlagTruncate = 0x20; | |
| 78 | |
| 79 // File types. | |
| 80 enum FileType { | |
| 81 UNKNOWN = 0, | |
| 82 REGULAR_FILE, | |
| 83 DIRECTORY, | |
| 84 }; | |
| 85 | |
| 86 // Describes a directory entry (i.e., a single member of a directory). | |
| 87 struct DirectoryEntry { | |
| 88 FileType type; | |
| 89 string name; | |
| 90 }; | |
| 91 | |
| 92 // Deletion flags: | |
| 93 // Only delete if the path refers to a file/non-directory (by default, will | |
| 94 // delete files and directories). | |
| 95 const uint32 kDeleteFlagFileOnly = 0x1; | |
| 96 // Only delete if the path refers to a directory. | |
| 97 const uint32 kDeleteFlagDirectoryOnly = 0x2; | |
| 98 // Recursively delete (neither of the two flags above may be specified). | |
| 99 const uint32 kDeleteFlagRecursive = 0x4; | |
| OLD | NEW |