vfs: check userland buffers before reading them.
[haiku.git] / headers / build / os / storage / Node.h
blobffb187c695554f18a74f01ec0209867feaf5a29f
1 /*
2 * Copyright 2002-2008, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _NODE_H
6 #define _NODE_H
9 #include <Statable.h>
11 class BDirectory;
12 class BEntry;
13 class BString;
14 struct entry_ref;
16 //! Reference structure to a particular vnode on a particular device
17 /*! <b>node_ref</b> - A node reference.
19 @author <a href="mailto:tylerdauwalder@users.sf.net">Tyler Dauwalder</a>
20 @author Be Inc.
21 @version 0.0.0
23 struct node_ref {
24 node_ref();
25 node_ref(const node_ref &ref);
27 bool operator==(const node_ref &ref) const;
28 bool operator!=(const node_ref &ref) const;
29 node_ref& operator=(const node_ref &ref);
31 bool operator<(const node_ref &ref) const
33 return device < ref.device
34 || (device == ref.device && node < ref.node);
37 dev_t device;
38 ino_t node;
42 //! A BNode represents a chunk of data in the filesystem.
43 /*! The BNode class provides an interface for manipulating the data and attributes
44 belonging to filesystem entries. The BNode is unaware of the name that refers
45 to it in the filesystem (i.e. its entry); a BNode is solely concerned with
46 the entry's data and attributes.
49 @author <a href='mailto:tylerdauwalder@users.sf.net'>Tyler Dauwalder</a>
50 @version 0.0.0
53 class BNode : public BStatable {
54 public:
55 BNode();
56 BNode(const entry_ref *ref);
57 BNode(const BEntry *entry);
58 BNode(const char *path);
59 BNode(const BDirectory *dir, const char *path);
60 BNode(const BNode &node);
61 virtual ~BNode();
63 status_t InitCheck() const;
65 virtual status_t GetStat(struct stat *st) const;
67 status_t SetTo(const entry_ref *ref);
68 status_t SetTo(const BEntry *entry);
69 status_t SetTo(const char *path);
70 status_t SetTo(const BDirectory *dir, const char *path);
71 void Unset();
73 status_t Lock();
74 status_t Unlock();
76 status_t Sync();
78 ssize_t WriteAttr(const char *name, type_code type, off_t offset,
79 const void *buffer, size_t len);
80 ssize_t ReadAttr(const char *name, type_code type, off_t offset,
81 void *buffer, size_t len) const;
82 status_t RemoveAttr(const char *name);
83 status_t RenameAttr(const char *oldname, const char *newname);
84 status_t GetAttrInfo(const char *name, struct attr_info *info) const;
85 status_t GetNextAttrName(char *buffer);
86 status_t RewindAttrs();
87 status_t WriteAttrString(const char *name, const BString *data);
88 status_t ReadAttrString(const char *name, BString *result) const;
90 BNode& operator=(const BNode &node);
91 bool operator==(const BNode &node) const;
92 bool operator!=(const BNode &node) const;
94 int Dup(); // This should be "const" but R5's is not... Ugggh.
96 private:
97 friend class BFile;
98 friend class BDirectory;
99 friend class BSymLink;
101 virtual void _RudeNode1();
102 virtual void _RudeNode2();
103 virtual void _RudeNode3();
104 virtual void _RudeNode4();
105 virtual void _RudeNode5();
106 virtual void _RudeNode6();
108 uint32 rudeData[4];
110 private:
111 status_t set_fd(int fd);
112 virtual void close_fd();
113 void set_status(status_t newStatus);
115 status_t _SetTo(int fd, const char *path, bool traverse);
116 status_t _SetTo(const entry_ref *ref, bool traverse);
118 virtual status_t set_stat(struct stat &st, uint32 what);
120 int fFd;
121 int fAttrFd;
122 status_t fCStatus;
124 status_t InitAttrDir();
127 #endif // _NODE_H