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/fusefs/fuse_fs.h" | 5 #include "nacl_io/fusefs/fuse_fs.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 LOG_ERROR("fuse_ops_->read is NULL."); | 334 LOG_ERROR("fuse_ops_->read is NULL."); |
335 return ENOSYS; | 335 return ENOSYS; |
336 } | 336 } |
337 | 337 |
338 char* cbuf = static_cast<char*>(buf); | 338 char* cbuf = static_cast<char*>(buf); |
339 | 339 |
340 int result = fuse_ops_->read(path_.c_str(), cbuf, count, attr.offs, &info_); | 340 int result = fuse_ops_->read(path_.c_str(), cbuf, count, attr.offs, &info_); |
341 if (result < 0) | 341 if (result < 0) |
342 return -result; | 342 return -result; |
343 | 343 |
344 // Fuse docs say that a read() call will always completely fill the buffer | |
345 // (padding with zeroes) unless the direct_io filesystem flag is set. | |
346 // TODO(binji): support the direct_io flag | 344 // TODO(binji): support the direct_io flag |
347 if (static_cast<size_t>(result) < count) | 345 if (static_cast<size_t>(result) < count) |
348 memset(&cbuf[result], 0, count - result); | 346 memset(&cbuf[result], 0, count - result); |
349 | 347 |
350 *out_bytes = count; | 348 *out_bytes = result; |
351 return 0; | 349 return 0; |
352 } | 350 } |
353 | 351 |
354 Error FileFuseFsNode::Write(const HandleAttr& attr, | 352 Error FileFuseFsNode::Write(const HandleAttr& attr, |
355 const void* buf, | 353 const void* buf, |
356 size_t count, | 354 size_t count, |
357 int* out_bytes) { | 355 int* out_bytes) { |
358 if (!fuse_ops_->write) { | 356 if (!fuse_ops_->write) { |
359 LOG_ERROR("fuse_ops_->write is NULL."); | 357 LOG_ERROR("fuse_ops_->write is NULL."); |
360 return ENOSYS; | 358 return ENOSYS; |
361 } | 359 } |
362 | 360 |
363 int result = fuse_ops_->write( | 361 int result = fuse_ops_->write( |
364 path_.c_str(), static_cast<const char*>(buf), count, attr.offs, &info_); | 362 path_.c_str(), static_cast<const char*>(buf), count, attr.offs, &info_); |
365 if (result < 0) | 363 if (result < 0) |
366 return -result; | 364 return -result; |
367 | 365 |
368 // Fuse docs say that a write() call will always write the entire buffer | |
369 // unless the direct_io filesystem flag is set. | |
370 // TODO(binji): What should we do if the user breaks this contract? Warn? | |
371 // TODO(binji): support the direct_io flag | 366 // TODO(binji): support the direct_io flag |
372 *out_bytes = result; | 367 *out_bytes = result; |
373 return 0; | 368 return 0; |
374 } | 369 } |
375 | 370 |
376 DirFuseFsNode::DirFuseFsNode(Filesystem* filesystem, | 371 DirFuseFsNode::DirFuseFsNode(Filesystem* filesystem, |
377 struct fuse_operations* fuse_ops, | 372 struct fuse_operations* fuse_ops, |
378 struct fuse_file_info& info, | 373 struct fuse_file_info& info, |
379 const std::string& path) | 374 const std::string& path) |
380 : FuseFsNode(filesystem, fuse_ops, info, path) { | 375 : FuseFsNode(filesystem, fuse_ops, info, path) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } else { | 472 } else { |
478 fill_info->getdents->AddDirent(ino, name, strlen(name)); | 473 fill_info->getdents->AddDirent(ino, name, strlen(name)); |
479 fill_info->num_bytes -= sizeof(dirent); | 474 fill_info->num_bytes -= sizeof(dirent); |
480 // According to the docs, we can never return 1 (buffer full) when the | 475 // According to the docs, we can never return 1 (buffer full) when the |
481 // offset is zero (the user is probably ignoring the result anyway). | 476 // offset is zero (the user is probably ignoring the result anyway). |
482 return 0; | 477 return 0; |
483 } | 478 } |
484 } | 479 } |
485 | 480 |
486 } // namespace nacl_io | 481 } // namespace nacl_io |
OLD | NEW |