summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/libraries/nacl_mounts/mount_node.h
blob: be284275ec62ab1b8b827b45435bfbb538cdba3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef LIBRARIES_NACL_MOUNTS_MOUNT_NODE_H_
#define LIBRARIES_NACL_MOUNTS_MOUNT_NODE_H_

#include <sys/stat.h>

#include <string>
#include "ref_object.h"

struct dirent;
struct stat;
class Mount;
class MountNode;

class MountNode : public RefObject {
 protected:
  virtual ~MountNode();

 protected:
  MountNode(Mount* mount, int ino, int dev);
  virtual bool Init(int mode, short uid, short gid);
  virtual int Close();

public:
  // Normal OS operations on a node (file), can be called by the kernel
  // directly so it must lock and unlock appropriately.  These functions
  // must not be called by the mount.
  virtual int FSync();
  virtual int GetDents(size_t offs, struct dirent* pdir, size_t count);
  virtual int GetStat(struct stat* stat);
  virtual int Ioctl(int request, char* arg);
  virtual int Read(size_t offs, void* buf, size_t count);
  virtual int Truncate(size_t size);
  virtual int Write(size_t offs, const void* buf, size_t count);

  virtual int GetLinks() const;
  virtual int GetMode() const;
  virtual int GetType() const;
  virtual size_t GetSize() const;
  virtual bool IsaDir() const;
  virtual bool IsaFile() const;
  virtual bool IsaTTY() const;

protected:
  // Directory operations on the node are done by the Mount. The mount's lock
  // must be held while these calls are made.

  // Adds or removes a directory entry updating the link numbers and refcount
  virtual int AddChild(const std::string& name, MountNode *node);
  virtual int RemoveChild(const std::string& name);

  // Find a child and return it without updating the refcount
  virtual MountNode* FindChild(const std::string& name);
  virtual int ChildCount();

  // Update the link count
  virtual void Link();
  virtual void Unlink();

protected:
  struct stat stat_;
  Mount* mount_;

  friend class MountHFS;
  friend class MountMem;
  friend class MountNodeDir;
};

#endif  // LIBRARIES_NACL_MOUNTS_MOUNT_NODE_H_