Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / filesystem.cc
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
3 // found in the LICENSE file.
4
5 #include "nacl_io/filesystem.h"
6
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <stdarg.h>
10
11 #include <string>
12
13 #include "nacl_io/dir_node.h"
14 #include "nacl_io/log.h"
15 #include "nacl_io/node.h"
16 #include "nacl_io/osstat.h"
17 #include "nacl_io/path.h"
18 #include "sdk_util/auto_lock.h"
19 #include "sdk_util/ref_object.h"
20
21 #if defined(WIN32)
22 #include <windows.h>
23 #endif
24
25 namespace nacl_io {
26
27 Filesystem::Filesystem() : dev_(0) {
28 }
29
30 Filesystem::~Filesystem() {
31 }
32
33 Error Filesystem::Init(const FsInitArgs& args) {
34   dev_ = args.dev;
35   ppapi_ = args.ppapi;
36   return 0;
37 }
38
39 void Filesystem::Destroy() {
40 }
41
42 Error Filesystem::Open(const Path& path,
43                        int open_flags,
44                        ScopedNode* out_node) {
45   return OpenWithMode(path, open_flags, 0666, out_node);
46 }
47
48 Error Filesystem::OpenResource(const Path& path, ScopedNode* out_node) {
49   out_node->reset(NULL);
50   LOG_TRACE("Can't open resource: %s", path.Join().c_str());
51   return EINVAL;
52 }
53
54 void Filesystem::OnNodeCreated(Node* node) {
55   node->stat_.st_ino = inode_pool_.Acquire();
56   node->stat_.st_dev = dev_;
57 }
58
59 void Filesystem::OnNodeDestroyed(Node* node) {
60   if (node->stat_.st_ino)
61     inode_pool_.Release(node->stat_.st_ino);
62 }
63
64 Error Filesystem::Filesystem_VIoctl(int request, va_list args) {
65   LOG_ERROR("Unsupported ioctl: %#x", request);
66   return EINVAL;
67 }
68
69 Error Filesystem::Filesystem_Ioctl(int request, ...) {
70   va_list args;
71   va_start(args, request);
72   Error error = Filesystem_VIoctl(request, args);
73   va_end(args);
74   return error;
75 }
76
77 }  // namespace nacl_io