| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/jsfs/js_fs.h" | 5 #include "nacl_io/jsfs/js_fs.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 404 } |
| 405 | 405 |
| 406 pthread_cond_wait(&response_cond_, lock_.mutex()); | 406 pthread_cond_wait(&response_cond_, lock_.mutex()); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 | 409 |
| 410 Error JsFs::OpenWithMode(const Path& path, int open_flags, mode_t t, | 410 Error JsFs::OpenWithMode(const Path& path, int open_flags, mode_t t, |
| 411 ScopedNode* out_node) { | 411 ScopedNode* out_node) { |
| 412 out_node->reset(NULL); | 412 out_node->reset(NULL); |
| 413 ScopedVar response(ppapi_); | 413 ScopedVar response(ppapi_); |
| 414 if (!SendRequestAndWait(&response, "%s%s%d", | 414 std::string path_str = path.Join(); |
| 415 "cmd", "open", | 415 if (!SendRequestAndWait(&response, "%s%s%d", "cmd", "open", "path", |
| 416 "path", path.Join().c_str(), | 416 path_str.c_str(), "oflag", open_flags)) { |
| 417 "oflag", open_flags)) { | |
| 418 LOG_ERROR("Failed to send request."); | 417 LOG_ERROR("Failed to send request."); |
| 419 return EINVAL; | 418 return EINVAL; |
| 420 } | 419 } |
| 421 | 420 |
| 422 int32_t error; | 421 int32_t error; |
| 423 int32_t fd; | 422 int32_t fd; |
| 424 int result = ScanVar(response.pp_var(), "%d%d", "error", &error, "fd", &fd); | 423 int result = ScanVar(response.pp_var(), "%d%d", "error", &error, "fd", &fd); |
| 425 if (result >= 1 && error) | 424 if (result >= 1 && error) |
| 426 return error; | 425 return error; |
| 427 | 426 |
| 428 if (result != 2) { | 427 if (result != 2) { |
| 429 LOG_ERROR("Expected \"error\" and \"fd\" fields in response."); | 428 LOG_ERROR("Expected \"error\" and \"fd\" fields in response."); |
| 430 return EINVAL; | 429 return EINVAL; |
| 431 } | 430 } |
| 432 | 431 |
| 433 out_node->reset(new JsFsNode(this, fd)); | 432 out_node->reset(new JsFsNode(this, fd)); |
| 434 return 0; | 433 return 0; |
| 435 } | 434 } |
| 436 | 435 |
| 437 Error JsFs::Unlink(const Path& path) { | 436 Error JsFs::Unlink(const Path& path) { |
| 438 ScopedVar response(ppapi_); | 437 ScopedVar response(ppapi_); |
| 439 if (!SendRequestAndWait( | 438 std::string path_str = path.Join(); |
| 440 &response, "%s%s", "cmd", "unlink", "path", path.Join().c_str())) { | 439 if (!SendRequestAndWait(&response, "%s%s", "cmd", "unlink", "path", |
| 440 path_str.c_str())) { |
| 441 LOG_ERROR("Failed to send request."); | 441 LOG_ERROR("Failed to send request."); |
| 442 return EINVAL; | 442 return EINVAL; |
| 443 } | 443 } |
| 444 | 444 |
| 445 return ErrorFromResponse(response); | 445 return ErrorFromResponse(response); |
| 446 } | 446 } |
| 447 | 447 |
| 448 Error JsFs::Mkdir(const Path& path, int perm) { | 448 Error JsFs::Mkdir(const Path& path, int perm) { |
| 449 ScopedVar response(ppapi_); | 449 ScopedVar response(ppapi_); |
| 450 if (!SendRequestAndWait(&response, "%s%s%d", | 450 std::string path_str = path.Join(); |
| 451 "cmd", "mkdir", | 451 if (!SendRequestAndWait(&response, "%s%s%d", "cmd", "mkdir", "path", |
| 452 "path", path.Join().c_str(), | 452 path_str.c_str(), "mode", perm)) { |
| 453 "mode", perm)) { | |
| 454 LOG_ERROR("Failed to send request."); | 453 LOG_ERROR("Failed to send request."); |
| 455 return EINVAL; | 454 return EINVAL; |
| 456 } | 455 } |
| 457 | 456 |
| 458 return ErrorFromResponse(response); | 457 return ErrorFromResponse(response); |
| 459 } | 458 } |
| 460 | 459 |
| 461 Error JsFs::Rmdir(const Path& path) { | 460 Error JsFs::Rmdir(const Path& path) { |
| 462 ScopedVar response(ppapi_); | 461 ScopedVar response(ppapi_); |
| 463 if (!SendRequestAndWait( | 462 std::string path_str = path.Join(); |
| 464 &response, "%s%s", "cmd", "rmdir", "path", path.Join().c_str())) { | 463 if (!SendRequestAndWait(&response, "%s%s", "cmd", "rmdir", "path", |
| 464 path_str.c_str())) { |
| 465 LOG_ERROR("Failed to send request."); | 465 LOG_ERROR("Failed to send request."); |
| 466 return EINVAL; | 466 return EINVAL; |
| 467 } | 467 } |
| 468 | 468 |
| 469 return ErrorFromResponse(response); | 469 return ErrorFromResponse(response); |
| 470 } | 470 } |
| 471 | 471 |
| 472 Error JsFs::Remove(const Path& path) { | 472 Error JsFs::Remove(const Path& path) { |
| 473 ScopedVar response(ppapi_); | 473 ScopedVar response(ppapi_); |
| 474 if (!SendRequestAndWait( | 474 std::string path_str = path.Join(); |
| 475 &response, "%s%s", "cmd", "remove", "path", path.Join().c_str())) { | 475 if (!SendRequestAndWait(&response, "%s%s", "cmd", "remove", "path", |
| 476 path_str.c_str())) { |
| 476 LOG_ERROR("Failed to send request."); | 477 LOG_ERROR("Failed to send request."); |
| 477 return EINVAL; | 478 return EINVAL; |
| 478 } | 479 } |
| 479 | 480 |
| 480 return ErrorFromResponse(response); | 481 return ErrorFromResponse(response); |
| 481 } | 482 } |
| 482 | 483 |
| 483 Error JsFs::Rename(const Path& path, const Path& newpath) { | 484 Error JsFs::Rename(const Path& path, const Path& newpath) { |
| 484 ScopedVar response(ppapi_); | 485 ScopedVar response(ppapi_); |
| 485 if (!SendRequestAndWait(&response, "%s%s%s", | 486 std::string path_str = path.Join(); |
| 486 "cmd", "rename", | 487 std::string newpath_str = newpath.Join(); |
| 487 "old", path.Join().c_str(), | 488 if (!SendRequestAndWait(&response, "%s%s%s", "cmd", "rename", "old", |
| 488 "new", newpath.Join().c_str())) { | 489 path_str.c_str(), "new", newpath_str.c_str())) { |
| 489 LOG_ERROR("Failed to send request."); | 490 LOG_ERROR("Failed to send request."); |
| 490 return EINVAL; | 491 return EINVAL; |
| 491 } | 492 } |
| 492 | 493 |
| 493 return ErrorFromResponse(response); | 494 return ErrorFromResponse(response); |
| 494 } | 495 } |
| 495 | 496 |
| 496 Error JsFs::Filesystem_VIoctl(int request, va_list args) { | 497 Error JsFs::Filesystem_VIoctl(int request, va_list args) { |
| 497 if (request != NACL_IOC_HANDLEMESSAGE) { | 498 if (request != NACL_IOC_HANDLEMESSAGE) { |
| 498 LOG_ERROR("Unknown ioctl: %#x", request); | 499 LOG_ERROR("Unknown ioctl: %#x", request); |
| 499 return EINVAL; | 500 return EINVAL; |
| 500 } | 501 } |
| 501 | 502 |
| 502 PP_Var response = *va_arg(args, PP_Var*); | 503 PP_Var response = *va_arg(args, PP_Var*); |
| 503 | 504 |
| 504 AUTO_LOCK(lock_); | 505 AUTO_LOCK(lock_); |
| 505 | 506 |
| 506 RequestId response_id; | 507 RequestId response_id; |
| 507 if (ScanVar(response, "%d", "id", &response_id) != 1) { | 508 if (ScanVar(response, "%d", "id", &response_id) != 1) { |
| 508 LOG_TRACE("ioctl with no \"id\", ignoring.\n"); | 509 LOG_TRACE("ioctl with no \"id\", ignoring.\n"); |
| 509 return EINVAL; | 510 return EINVAL; |
| 510 } | 511 } |
| 511 | 512 |
| 512 responses_.insert(ResponseMap_t::value_type(response_id, response)); | 513 responses_.insert(ResponseMap_t::value_type(response_id, response)); |
| 513 pthread_cond_broadcast(&response_cond_); | 514 pthread_cond_broadcast(&response_cond_); |
| 514 return 0; | 515 return 0; |
| 515 } | 516 } |
| 516 | 517 |
| 517 } // namespace nacl_io | 518 } // namespace nacl_io |
| OLD | NEW |