OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "nacl_io/html5fs/html5_fs_node.h" | 5 #include "nacl_io/html5fs/html5_fs_node.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <ppapi/c/pp_completion_callback.h> | 9 #include <ppapi/c/pp_completion_callback.h> |
10 #include <ppapi/c/pp_directory_entry.h> | 10 #include <ppapi/c/pp_directory_entry.h> |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 case PP_FILETYPE_REGULAR: | 161 case PP_FILETYPE_REGULAR: |
162 stat->st_mode |= S_IFREG; | 162 stat->st_mode |= S_IFREG; |
163 break; | 163 break; |
164 case PP_FILETYPE_DIRECTORY: | 164 case PP_FILETYPE_DIRECTORY: |
165 stat->st_mode |= S_IFDIR; | 165 stat->st_mode |= S_IFDIR; |
166 break; | 166 break; |
167 case PP_FILETYPE_OTHER: | 167 case PP_FILETYPE_OTHER: |
168 default: | 168 default: |
169 break; | 169 break; |
170 } | 170 } |
171 stat->st_size = static_cast<off_t>(info.size); | 171 stat->st_size = static_cast<off_t>(info.size); |
Sam Clegg
2015/08/13 19:08:33
What does info.size mean for html5 fs? Perhaps we
zhitingzhu
2015/08/13 20:56:36
I am not sure about where the info comes from. But
| |
172 // Hack the directory size | |
173 // In Linux, even a empty directory has size 4096 | |
174 if (info.type == PP_FILETYPE_DIRECTORY && info.size == 0) | |
175 stat->st_size = 4096; | |
172 stat->st_atime = info.last_access_time; | 176 stat->st_atime = info.last_access_time; |
173 stat->st_mtime = info.last_modified_time; | 177 stat->st_mtime = info.last_modified_time; |
174 stat->st_ctime = info.creation_time; | 178 stat->st_ctime = info.creation_time; |
175 | 179 |
176 return 0; | 180 return 0; |
177 } | 181 } |
178 | 182 |
179 Error Html5FsNode::Read(const HandleAttr& attr, | 183 Error Html5FsNode::Read(const HandleAttr& attr, |
180 void* buf, | 184 void* buf, |
181 size_t count, | 185 size_t count, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 } | 234 } |
231 | 235 |
232 int Html5FsNode::GetType() { | 236 int Html5FsNode::GetType() { |
233 return fileio_resource_ ? S_IFREG : S_IFDIR; | 237 return fileio_resource_ ? S_IFREG : S_IFDIR; |
234 } | 238 } |
235 | 239 |
236 Error Html5FsNode::GetSize(off_t* out_size) { | 240 Error Html5FsNode::GetSize(off_t* out_size) { |
237 *out_size = 0; | 241 *out_size = 0; |
238 | 242 |
239 if (IsaDir()) | 243 if (IsaDir()) |
240 return 0; | 244 return 0; |
Sam Clegg
2015/08/13 19:08:33
Won't this early return?
Can you use a define rat
zhitingzhu
2015/08/13 20:56:36
Done. It seems GetSize only relates to file.
| |
241 | 245 |
242 AUTO_LOCK(node_lock_); | 246 AUTO_LOCK(node_lock_); |
243 | 247 |
244 PP_FileInfo info; | 248 PP_FileInfo info; |
245 int32_t result = | 249 int32_t result = |
246 file_io_iface_->Query(fileio_resource_, &info, PP_BlockUntilComplete()); | 250 file_io_iface_->Query(fileio_resource_, &info, PP_BlockUntilComplete()); |
247 if (result != PP_OK) | 251 if (result != PP_OK) |
248 return PPERROR_TO_ERRNO(result); | 252 return PPERROR_TO_ERRNO(result); |
249 | 253 |
250 *out_size = info.size; | 254 *out_size = info.size; |
255 // In Linux, even a empty directory has size 4096 | |
256 if (info.type == PP_FILETYPE_DIRECTORY && info.size == 0) | |
257 *out_size = 4096; | |
251 return 0; | 258 return 0; |
252 } | 259 } |
253 | 260 |
254 Html5FsNode::Html5FsNode(Filesystem* filesystem, PP_Resource fileref_resource) | 261 Html5FsNode::Html5FsNode(Filesystem* filesystem, PP_Resource fileref_resource) |
255 : Node(filesystem), | 262 : Node(filesystem), |
256 fileref_resource_(fileref_resource), | 263 fileref_resource_(fileref_resource), |
257 fileio_resource_(0) { | 264 fileio_resource_(0) { |
258 } | 265 } |
259 | 266 |
260 Error Html5FsNode::Init(int open_flags) { | 267 Error Html5FsNode::Init(int open_flags) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 fileref_resource_ = 0; | 323 fileref_resource_ = 0; |
317 Node::Destroy(); | 324 Node::Destroy(); |
318 } | 325 } |
319 | 326 |
320 Error Html5FsNode::Fchmod(mode_t mode) { | 327 Error Html5FsNode::Fchmod(mode_t mode) { |
321 // html5fs does not support any kinds of permissions or mode bits. | 328 // html5fs does not support any kinds of permissions or mode bits. |
322 return 0; | 329 return 0; |
323 } | 330 } |
324 | 331 |
325 } // namespace nacl_io | 332 } // namespace nacl_io |
OLD | NEW |