OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef BIN_FILE_H_ | 5 #ifndef BIN_FILE_H_ |
6 #define BIN_FILE_H_ | 6 #define BIN_FILE_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // These match the constants in FileStat in file_system_entity.dart. | 62 // These match the constants in FileStat in file_system_entity.dart. |
63 kType = 0, | 63 kType = 0, |
64 kCreatedTime = 1, | 64 kCreatedTime = 1, |
65 kModifiedTime = 2, | 65 kModifiedTime = 2, |
66 kAccessedTime = 3, | 66 kAccessedTime = 3, |
67 kMode = 4, | 67 kMode = 4, |
68 kSize = 5, | 68 kSize = 5, |
69 kStatSize = 6 | 69 kStatSize = 6 |
70 }; | 70 }; |
71 | 71 |
| 72 enum LockType { |
| 73 // These match the constants in FileStat in file_impl.dart. |
| 74 kLockMin = 0, |
| 75 kLockUnlock = 0, |
| 76 kLockShared = 1, |
| 77 kLockExclusive = 2, |
| 78 kLockMax = 2 |
| 79 }; |
| 80 |
72 ~File(); | 81 ~File(); |
73 | 82 |
74 intptr_t GetFD(); | 83 intptr_t GetFD(); |
75 | 84 |
76 // Read/Write attempt to transfer num_bytes to/from buffer. It returns | 85 // Read/Write attempt to transfer num_bytes to/from buffer. It returns |
77 // the number of bytes read/written. | 86 // the number of bytes read/written. |
78 int64_t Read(void* buffer, int64_t num_bytes); | 87 int64_t Read(void* buffer, int64_t num_bytes); |
79 int64_t Write(const void* buffer, int64_t num_bytes); | 88 int64_t Write(const void* buffer, int64_t num_bytes); |
80 | 89 |
81 // ReadFully and WriteFully do attempt to transfer num_bytes to/from | 90 // ReadFully and WriteFully do attempt to transfer num_bytes to/from |
(...skipping 16 matching lines...) Expand all Loading... |
98 | 107 |
99 // Set the byte position in the file. | 108 // Set the byte position in the file. |
100 bool SetPosition(int64_t position); | 109 bool SetPosition(int64_t position); |
101 | 110 |
102 // Truncate (or extend) the file to the given length in bytes. | 111 // Truncate (or extend) the file to the given length in bytes. |
103 bool Truncate(int64_t length); | 112 bool Truncate(int64_t length); |
104 | 113 |
105 // Flush contents of file. | 114 // Flush contents of file. |
106 bool Flush(); | 115 bool Flush(); |
107 | 116 |
| 117 // Lock range of a file. |
| 118 bool Lock(LockType lock, int64_t start, int64_t end); |
| 119 |
108 // Returns whether the file has been closed. | 120 // Returns whether the file has been closed. |
109 bool IsClosed(); | 121 bool IsClosed(); |
110 | 122 |
111 // Open the file with the given path. The file is always opened for | 123 // Open the file with the given path. The file is always opened for |
112 // reading. If mode contains kWrite the file is opened for both | 124 // reading. If mode contains kWrite the file is opened for both |
113 // reading and writing. If mode contains kWrite and the file does | 125 // reading and writing. If mode contains kWrite and the file does |
114 // not exist the file is created. The file is truncated to length 0 if | 126 // not exist the file is created. The file is truncated to length 0 if |
115 // mode contains kTruncate. | 127 // mode contains kTruncate. |
116 static File* Open(const char* path, FileOpenMode mode); | 128 static File* Open(const char* path, FileOpenMode mode); |
117 | 129 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 static CObject* ReadRequest(const CObjectArray& request); | 173 static CObject* ReadRequest(const CObjectArray& request); |
162 static CObject* ReadIntoRequest(const CObjectArray& request); | 174 static CObject* ReadIntoRequest(const CObjectArray& request); |
163 static CObject* WriteFromRequest(const CObjectArray& request); | 175 static CObject* WriteFromRequest(const CObjectArray& request); |
164 static CObject* CreateLinkRequest(const CObjectArray& request); | 176 static CObject* CreateLinkRequest(const CObjectArray& request); |
165 static CObject* DeleteLinkRequest(const CObjectArray& request); | 177 static CObject* DeleteLinkRequest(const CObjectArray& request); |
166 static CObject* RenameLinkRequest(const CObjectArray& request); | 178 static CObject* RenameLinkRequest(const CObjectArray& request); |
167 static CObject* LinkTargetRequest(const CObjectArray& request); | 179 static CObject* LinkTargetRequest(const CObjectArray& request); |
168 static CObject* TypeRequest(const CObjectArray& request); | 180 static CObject* TypeRequest(const CObjectArray& request); |
169 static CObject* IdenticalRequest(const CObjectArray& request); | 181 static CObject* IdenticalRequest(const CObjectArray& request); |
170 static CObject* StatRequest(const CObjectArray& request); | 182 static CObject* StatRequest(const CObjectArray& request); |
| 183 static CObject* LockRequest(const CObjectArray& request); |
171 | 184 |
172 private: | 185 private: |
173 explicit File(FileHandle* handle) : handle_(handle) { } | 186 explicit File(FileHandle* handle) : handle_(handle) { } |
174 void Close(); | 187 void Close(); |
175 | 188 |
176 static const int kClosedFd = -1; | 189 static const int kClosedFd = -1; |
177 | 190 |
178 // FileHandle is an OS specific class which stores data about the file. | 191 // FileHandle is an OS specific class which stores data about the file. |
179 FileHandle* handle_; // OS specific handle for the file. | 192 FileHandle* handle_; // OS specific handle for the file. |
180 | 193 |
181 DISALLOW_COPY_AND_ASSIGN(File); | 194 DISALLOW_COPY_AND_ASSIGN(File); |
182 }; | 195 }; |
183 | 196 |
184 } // namespace bin | 197 } // namespace bin |
185 } // namespace dart | 198 } // namespace dart |
186 | 199 |
187 #endif // BIN_FILE_H_ | 200 #endif // BIN_FILE_H_ |
OLD | NEW |